comparison test/testvidinfo.c @ 479:c0a1744bc2cf

Added a -benchmark flag for testing the speeds of various video modes
author Sam Lantinga <slouken@libsdl.org>
date Sat, 31 Aug 2002 19:48:11 +0000
parents c6abdda2f666
children 92596bfe8446
comparison
equal deleted inserted replaced
478:f8482d7c9595 479:c0a1744bc2cf
1 1
2 /* Simple program -- figure out what kind of video display we have */ 2 /* Simple program -- figure out what kind of video display we have */
3 3
4 #include <stdlib.h>
4 #include <stdio.h> 5 #include <stdio.h>
5 #include <stdlib.h> 6 #include <stdlib.h>
6 7
7 #include "SDL.h" 8 #include "SDL.h"
9
10 #define FLAG_MASK (SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF)
11
12 void PrintFlags(Uint32 flags)
13 {
14 printf("0x%8.8x", (flags & FLAG_MASK));
15 if ( flags & SDL_HWSURFACE ) {
16 printf(" SDL_HWSURFACE");
17 } else {
18 printf(" SDL_SWSURFACE");
19 }
20 if ( flags & SDL_FULLSCREEN ) {
21 printf(" | SDL_FULLSCREEN");
22 }
23 if ( flags & SDL_DOUBLEBUF ) {
24 printf(" | SDL_DOUBLEBUF");
25 }
26 }
27
28 int RunBlitTests(SDL_Surface *screen, SDL_Surface *bmp, int blitcount)
29 {
30 int i, j;
31 int maxx;
32 int maxy;
33 SDL_Rect *rects;
34
35 rects = (SDL_Rect *)malloc(blitcount * sizeof(*rects));
36 if ( ! rects ) {
37 return 0;
38 }
39 maxx = (int)screen->w - bmp->w;
40 maxy = (int)screen->h - bmp->h;
41 for ( i = 0; i < 100; ++i ) {
42 for ( j = 0; j < blitcount; ++j ) {
43 if ( maxx ) {
44 rects[j].x = rand() % maxx;
45 } else {
46 rects[j].x = 0;
47 }
48 if ( maxy ) {
49 rects[j].y = rand() % maxy;
50 } else {
51 rects[j].y = 0;
52 }
53 rects[j].w = bmp->w;
54 rects[j].h = bmp->h;
55 SDL_BlitSurface(bmp, NULL, screen, &rects[j]);
56 }
57 if ( screen->flags & SDL_DOUBLEBUF ) {
58 SDL_Flip(screen);
59 } else {
60 SDL_UpdateRects(screen, blitcount, rects);
61 }
62 }
63 free(rects);
64
65 return i;
66 }
67
68 void RunModeTests(SDL_Surface *screen)
69 {
70 Uint32 then, now;
71 Uint32 frames;
72 int i;
73 Uint8 r, g, b;
74 Uint32 pixel;
75 SDL_Surface *bmp, *tmp;
76
77 /* First test fills and screen update speed */
78 printf("Running color fill and fullscreen update test\n");
79 then = SDL_GetTicks();
80 frames = 0;
81 for ( i = 0; i < 256; ++i ) {
82 r = i;
83 g = 0;
84 b = 0;
85 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b));
86 SDL_Flip(screen);
87 ++frames;
88 }
89 for ( i = 0; i < 256; ++i ) {
90 r = 0;
91 g = i;
92 b = 0;
93 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b));
94 SDL_Flip(screen);
95 ++frames;
96 }
97 for ( i = 0; i < 256; ++i ) {
98 r = 0;
99 g = 0;
100 b = i;
101 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b));
102 SDL_Flip(screen);
103 ++frames;
104 }
105 now = SDL_GetTicks();
106 printf("%d fills and flips, %f FPS\n", frames, (float)(now - then) / frames);
107
108 bmp = SDL_LoadBMP("sample.bmp");
109 if ( ! bmp ) {
110 printf("Couldn't load sample.bmp: %s\n", SDL_GetError());
111 return;
112 }
113 printf("Running freshly loaded blit test: %dx%d at %d bpp, flags: ",
114 bmp->w, bmp->h, bmp->format->BitsPerPixel);
115 PrintFlags(bmp->flags);
116 printf("\n");
117 then = SDL_GetTicks();
118 frames = RunBlitTests(screen, bmp, 10);
119 now = SDL_GetTicks();
120 if ( frames ) {
121 printf("%d blits, %d updates, %f FPS\n", 10*frames, frames, (float)(now - then) / frames);
122 }
123
124 tmp = bmp;
125 bmp = SDL_DisplayFormat(bmp);
126 SDL_FreeSurface(tmp);
127 if ( ! bmp ) {
128 printf("Couldn't convert sample.bmp: %s\n", SDL_GetError());
129 return;
130 }
131 printf("Running display format blit test: %dx%d at %d bpp, flags: ",
132 bmp->w, bmp->h, bmp->format->BitsPerPixel);
133 PrintFlags(bmp->flags);
134 printf("\n");
135 then = SDL_GetTicks();
136 frames = RunBlitTests(screen, bmp, 10);
137 now = SDL_GetTicks();
138 if ( frames ) {
139 printf("%d blits, %d updates, %f FPS\n", 10*frames, frames, (float)(now - then) / frames);
140 }
141 SDL_FreeSurface(bmp);
142 }
143
144 void RunVideoTests()
145 {
146 static const struct {
147 int w, h, bpp;
148 } mode_list[] = {
149 { 640, 480, 8 }, { 640, 480, 16 }, { 640, 480, 32 },
150 { 800, 600, 8 }, { 800, 600, 16 }, { 800, 600, 32 },
151 { 1024, 768, 8 }, { 1024, 768, 16 }, { 1024, 768, 32 }
152 };
153 static const Uint32 flags[] = {
154 (SDL_SWSURFACE),
155 (SDL_SWSURFACE | SDL_FULLSCREEN),
156 (SDL_HWSURFACE | SDL_FULLSCREEN),
157 (SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF)
158 };
159 int i, j;
160 SDL_Surface *screen;
161
162 /* Test out several different video mode combinations */
163 for ( i = 0; i < SDL_TABLESIZE(mode_list); ++i ) {
164 for ( j = 0; j < SDL_TABLESIZE(flags); ++j ) {
165 printf("===================================\n");
166 printf("Setting video mode: %dx%d at %d bpp, flags: ",
167 mode_list[i].w,
168 mode_list[i].h,
169 mode_list[i].bpp);
170 PrintFlags(flags[j]);
171 printf("\n");
172 screen = SDL_SetVideoMode(mode_list[i].w,
173 mode_list[i].h,
174 mode_list[i].bpp,
175 flags[j]);
176 if ( ! screen ) {
177 printf("Setting video mode failed: %s\n", SDL_GetError());
178 continue;
179 }
180 if ( (screen->flags & FLAG_MASK) != flags[j] ) {
181 printf("Flags didn't match: ");
182 PrintFlags(screen->flags);
183 printf("\n");
184 continue;
185 }
186 RunModeTests(screen);
187 }
188 }
189 }
8 190
9 int main(int argc, char *argv[]) 191 int main(int argc, char *argv[])
10 { 192 {
11 const SDL_VideoInfo *info; 193 const SDL_VideoInfo *info;
12 int i; 194 int i;
71 } 253 }
72 if ( info->blit_fill ) { 254 if ( info->blit_fill ) {
73 printf( 255 printf(
74 "Color fills on hardware surfaces are accelerated\n"); 256 "Color fills on hardware surfaces are accelerated\n");
75 } 257 }
258
259 if ( argv[1] && (strcmp(argv[1], "-benchmark") == 0) ) {
260 RunVideoTests();
261 }
262
76 SDL_Quit(); 263 SDL_Quit();
77 return(0); 264 return(0);
78 } 265 }