2 /* Simple program -- figure out what kind of video display we have */
11 #define NUM_UPDATES 500
13 #define FLAG_MASK (SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF)
15 void PrintFlags(Uint32 flags)
17 printf("0x%8.8x", (flags & FLAG_MASK));
18 if ( flags & SDL_HWSURFACE ) {
19 printf(" SDL_HWSURFACE");
21 printf(" SDL_SWSURFACE");
23 if ( flags & SDL_FULLSCREEN ) {
24 printf(" | SDL_FULLSCREEN");
26 if ( flags & SDL_DOUBLEBUF ) {
27 printf(" | SDL_DOUBLEBUF");
31 int RunBlitTests(SDL_Surface *screen, SDL_Surface *bmp, int blitcount)
38 maxx = (int)screen->w - bmp->w + 1;
39 maxy = (int)screen->h - bmp->h + 1;
40 for ( i = 0; i < NUM_UPDATES; ++i ) {
41 for ( j = 0; j < blitcount; ++j ) {
43 dst.x = rand() % maxx;
48 dst.y = rand() % maxy;
54 SDL_BlitSurface(bmp, NULL, screen, &dst);
62 int RunModeTests(SDL_Surface *screen)
70 SDL_Surface *bmp, *tmp;
73 while ( SDL_PollEvent(&event) ) {
74 if ( event.type == SDL_KEYDOWN )
78 /* First test fills and screen update speed */
79 printf("Running color fill and fullscreen update test\n");
80 then = SDL_GetTicks();
82 for ( i = 0; i < 256; ++i ) {
86 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b));
90 for ( i = 0; i < 256; ++i ) {
94 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b));
98 for ( i = 0; i < 256; ++i ) {
102 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b));
106 now = SDL_GetTicks();
107 seconds = (float)(now - then) / 1000.0f;
108 if ( seconds > 0.0f ) {
109 printf("%d fills and flips in %2.2f seconds, %2.2f FPS\n", frames, seconds, (float)frames / seconds);
111 printf("%d fills and flips in zero seconds!n", frames);
114 while ( SDL_PollEvent(&event) ) {
115 if ( event.type == SDL_KEYDOWN )
119 bmp = SDL_LoadBMP("sample.bmp");
121 printf("Couldn't load sample.bmp: %s\n", SDL_GetError());
124 printf("Running freshly loaded blit test: %dx%d at %d bpp, flags: ",
125 bmp->w, bmp->h, bmp->format->BitsPerPixel);
126 PrintFlags(bmp->flags);
128 then = SDL_GetTicks();
129 frames = RunBlitTests(screen, bmp, NUM_BLITS);
130 now = SDL_GetTicks();
131 seconds = (float)(now - then) / 1000.0f;
132 if ( seconds > 0.0f ) {
133 printf("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds);
135 printf("%d blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames);
139 bmp = SDL_DisplayFormat(bmp);
140 SDL_FreeSurface(tmp);
142 printf("Couldn't convert sample.bmp: %s\n", SDL_GetError());
145 printf("Running display format blit test: %dx%d at %d bpp, flags: ",
146 bmp->w, bmp->h, bmp->format->BitsPerPixel);
147 PrintFlags(bmp->flags);
149 then = SDL_GetTicks();
150 frames = RunBlitTests(screen, bmp, NUM_BLITS);
151 now = SDL_GetTicks();
152 seconds = (float)(now - then) / 1000.0f;
153 if ( seconds > 0.0f ) {
154 printf("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds);
156 printf("%d blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames);
158 SDL_FreeSurface(bmp);
160 while ( SDL_PollEvent(&event) ) {
161 if ( event.type == SDL_KEYDOWN )
169 static const struct {
172 { 640, 480, 8 }, { 640, 480, 16 }, { 640, 480, 32 },
173 { 800, 600, 8 }, { 800, 600, 16 }, { 800, 600, 32 },
174 { 1024, 768, 8 }, { 1024, 768, 16 }, { 1024, 768, 32 }
176 static const Uint32 flags[] = {
178 (SDL_SWSURFACE | SDL_FULLSCREEN),
179 (SDL_HWSURFACE | SDL_FULLSCREEN),
180 (SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF)
185 /* Test out several different video mode combinations */
186 SDL_WM_SetCaption("SDL Video Benchmark", "vidtest");
188 for ( i = 0; i < SDL_TABLESIZE(mode_list); ++i ) {
189 for ( j = 0; j < SDL_TABLESIZE(flags); ++j ) {
190 printf("===================================\n");
191 printf("Setting video mode: %dx%d at %d bpp, flags: ",
195 PrintFlags(flags[j]);
197 screen = SDL_SetVideoMode(mode_list[i].w,
202 printf("Setting video mode failed: %s\n", SDL_GetError());
205 if ( (screen->flags & FLAG_MASK) != flags[j] ) {
206 printf("Flags didn't match: ");
207 PrintFlags(screen->flags);
211 if ( ! RunModeTests(screen) ) {
218 int main(int argc, char *argv[])
220 const SDL_VideoInfo *info;
225 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
227 "Couldn't initialize SDL: %s\n", SDL_GetError());
230 if ( SDL_VideoDriverName(driver, sizeof(driver)) ) {
231 printf("Video driver: %s\n", driver);
233 info = SDL_GetVideoInfo();
235 "Current display: %d bits-per-pixel\n",info->vfmt->BitsPerPixel);
236 if ( info->vfmt->palette == NULL ) {
237 printf(" Red Mask = 0x%.8x\n", info->vfmt->Rmask);
238 printf(" Green Mask = 0x%.8x\n", info->vfmt->Gmask);
239 printf(" Blue Mask = 0x%.8x\n", info->vfmt->Bmask);
241 /* Print available fullscreen video modes */
242 modes = SDL_ListModes(NULL, SDL_FULLSCREEN);
243 if ( modes == (SDL_Rect **)0 ) {
244 printf("No available fullscreen video modes\n");
246 if ( modes == (SDL_Rect **)-1 ) {
247 printf("No special fullscreen video modes\n");
249 printf("Fullscreen video modes:\n");
250 for ( i=0; modes[i]; ++i ) {
251 printf("\t%dx%dx%d\n", modes[i]->w, modes[i]->h, info->vfmt->BitsPerPixel);
254 if ( info->wm_available ) {
255 printf("A window manager is available\n");
257 if ( info->hw_available ) {
258 printf("Hardware surfaces are available (%dK video memory)\n",
261 if ( info->blit_hw ) {
263 "Copy blits between hardware surfaces are accelerated\n");
265 if ( info->blit_hw_CC ) {
267 "Colorkey blits between hardware surfaces are accelerated\n");
269 if ( info->blit_hw_A ) {
271 "Alpha blits between hardware surfaces are accelerated\n");
273 if ( info->blit_sw ) {
275 "Copy blits from software surfaces to hardware surfaces are accelerated\n");
277 if ( info->blit_sw_CC ) {
279 "Colorkey blits from software surfaces to hardware surfaces are accelerated\n");
281 if ( info->blit_sw_A ) {
283 "Alpha blits from software surfaces to hardware surfaces are accelerated\n");
285 if ( info->blit_fill ) {
287 "Color fills on hardware surfaces are accelerated\n");
290 if ( argv[1] && (strcmp(argv[1], "-benchmark") == 0) ) {