Mercurial > sdl-ios-xcode
comparison test/testvidinfo.c @ 1895:c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 10 Jul 2006 21:04:37 +0000 |
parents | 8d9bb0cf2c2a |
children | 01e29c3e9a29 |
comparison
equal
deleted
inserted
replaced
1894:c69cee13dd76 | 1895:c121d94672cb |
---|---|
13 | 13 |
14 #define FLAG_MASK (SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF | \ | 14 #define FLAG_MASK (SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF | \ |
15 SDL_SRCCOLORKEY | SDL_SRCALPHA | SDL_RLEACCEL | \ | 15 SDL_SRCCOLORKEY | SDL_SRCALPHA | SDL_RLEACCEL | \ |
16 SDL_RLEACCELOK) | 16 SDL_RLEACCELOK) |
17 | 17 |
18 void PrintFlags(Uint32 flags) | 18 #if 0 |
19 void | |
20 PrintFlags(Uint32 flags) | |
19 { | 21 { |
20 printf("0x%8.8x", (flags & FLAG_MASK)); | 22 printf("0x%8.8x", (flags & FLAG_MASK)); |
21 if ( flags & SDL_HWSURFACE ) { | 23 if (flags & SDL_HWSURFACE) { |
22 printf(" SDL_HWSURFACE"); | 24 printf(" SDL_HWSURFACE"); |
23 } else { | 25 } else { |
24 printf(" SDL_SWSURFACE"); | 26 printf(" SDL_SWSURFACE"); |
25 } | 27 } |
26 if ( flags & SDL_FULLSCREEN ) { | 28 if (flags & SDL_FULLSCREEN) { |
27 printf(" | SDL_FULLSCREEN"); | 29 printf(" | SDL_FULLSCREEN"); |
28 } | 30 } |
29 if ( flags & SDL_DOUBLEBUF ) { | 31 if (flags & SDL_DOUBLEBUF) { |
30 printf(" | SDL_DOUBLEBUF"); | 32 printf(" | SDL_DOUBLEBUF"); |
31 } | 33 } |
32 if ( flags & SDL_SRCCOLORKEY ) { | 34 if (flags & SDL_SRCCOLORKEY) { |
33 printf(" | SDL_SRCCOLORKEY"); | 35 printf(" | SDL_SRCCOLORKEY"); |
34 } | 36 } |
35 if ( flags & SDL_SRCALPHA ) { | 37 if (flags & SDL_SRCALPHA) { |
36 printf(" | SDL_SRCALPHA"); | 38 printf(" | SDL_SRCALPHA"); |
37 } | 39 } |
38 if ( flags & SDL_RLEACCEL ) { | 40 if (flags & SDL_RLEACCEL) { |
39 printf(" | SDL_RLEACCEL"); | 41 printf(" | SDL_RLEACCEL"); |
40 } | 42 } |
41 if ( flags & SDL_RLEACCELOK ) { | 43 if (flags & SDL_RLEACCELOK) { |
42 printf(" | SDL_RLEACCELOK"); | 44 printf(" | SDL_RLEACCELOK"); |
43 } | 45 } |
44 } | 46 } |
45 | 47 |
46 int RunBlitTests(SDL_Surface *screen, SDL_Surface *bmp, int blitcount) | 48 int |
49 RunBlitTests(SDL_Surface * screen, SDL_Surface * bmp, int blitcount) | |
47 { | 50 { |
48 int i, j; | 51 int i, j; |
49 int maxx; | 52 int maxx; |
50 int maxy; | 53 int maxy; |
51 SDL_Rect dst; | 54 SDL_Rect dst; |
52 | 55 |
53 maxx = (int)screen->w - bmp->w + 1; | 56 maxx = (int) screen->w - bmp->w + 1; |
54 maxy = (int)screen->h - bmp->h + 1; | 57 maxy = (int) screen->h - bmp->h + 1; |
55 for ( i = 0; i < NUM_UPDATES; ++i ) { | 58 for (i = 0; i < NUM_UPDATES; ++i) { |
56 for ( j = 0; j < blitcount; ++j ) { | 59 for (j = 0; j < blitcount; ++j) { |
57 if ( maxx ) { | 60 if (maxx) { |
58 dst.x = rand() % maxx; | 61 dst.x = rand() % maxx; |
59 } else { | 62 } else { |
60 dst.x = 0; | 63 dst.x = 0; |
61 } | 64 } |
62 if ( maxy ) { | 65 if (maxy) { |
63 dst.y = rand() % maxy; | 66 dst.y = rand() % maxy; |
64 } else { | 67 } else { |
65 dst.y = 0; | 68 dst.y = 0; |
66 } | 69 } |
67 dst.w = bmp->w; | 70 dst.w = bmp->w; |
68 dst.h = bmp->h; | 71 dst.h = bmp->h; |
69 SDL_BlitSurface(bmp, NULL, screen, &dst); | 72 SDL_BlitSurface(bmp, NULL, screen, &dst); |
70 } | 73 } |
71 SDL_Flip(screen); | 74 SDL_Flip(screen); |
72 } | 75 } |
73 | 76 |
74 return i; | 77 return i; |
75 } | 78 } |
76 | 79 |
77 int RunModeTests(SDL_Surface *screen) | 80 int |
81 RunModeTests(SDL_Surface * screen) | |
78 { | 82 { |
79 Uint32 then, now; | 83 Uint32 then, now; |
80 Uint32 frames; | 84 Uint32 frames; |
81 float seconds; | 85 float seconds; |
82 int i; | 86 int i; |
83 Uint8 r, g, b; | 87 Uint8 r, g, b; |
84 SDL_Surface *bmp, *bmpcc, *tmp; | 88 SDL_Surface *bmp, *bmpcc, *tmp; |
85 SDL_Event event; | 89 SDL_Event event; |
86 | 90 |
87 while ( SDL_PollEvent(&event) ) { | 91 while (SDL_PollEvent(&event)) { |
88 if ( event.type == SDL_KEYDOWN ) | 92 if (event.type == SDL_KEYDOWN) |
89 return 0; | 93 return 0; |
90 } | 94 } |
91 | 95 |
92 /* First test fills and screen update speed */ | 96 /* First test fills and screen update speed */ |
93 printf("Running color fill and fullscreen update test\n"); | 97 printf("Running color fill and fullscreen update test\n"); |
94 then = SDL_GetTicks(); | 98 then = SDL_GetTicks(); |
95 frames = 0; | 99 frames = 0; |
96 for ( i = 0; i < 256; ++i ) { | 100 for (i = 0; i < 256; ++i) { |
97 r = i; | 101 r = i; |
98 g = 0; | 102 g = 0; |
99 b = 0; | 103 b = 0; |
100 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b)); | 104 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b)); |
101 SDL_Flip(screen); | 105 SDL_Flip(screen); |
102 ++frames; | 106 ++frames; |
103 } | 107 } |
104 for ( i = 0; i < 256; ++i ) { | 108 for (i = 0; i < 256; ++i) { |
105 r = 0; | 109 r = 0; |
106 g = i; | 110 g = i; |
107 b = 0; | 111 b = 0; |
108 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b)); | 112 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b)); |
109 SDL_Flip(screen); | 113 SDL_Flip(screen); |
110 ++frames; | 114 ++frames; |
111 } | 115 } |
112 for ( i = 0; i < 256; ++i ) { | 116 for (i = 0; i < 256; ++i) { |
113 r = 0; | 117 r = 0; |
114 g = 0; | 118 g = 0; |
115 b = i; | 119 b = i; |
116 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b)); | 120 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b)); |
117 SDL_Flip(screen); | 121 SDL_Flip(screen); |
118 ++frames; | 122 ++frames; |
119 } | 123 } |
120 now = SDL_GetTicks(); | 124 now = SDL_GetTicks(); |
121 seconds = (float)(now - then) / 1000.0f; | 125 seconds = (float) (now - then) / 1000.0f; |
122 if ( seconds > 0.0f ) { | 126 if (seconds > 0.0f) { |
123 printf("%d fills and flips in %2.2f seconds, %2.2f FPS\n", frames, seconds, (float)frames / seconds); | 127 printf("%d fills and flips in %2.2f seconds, %2.2f FPS\n", frames, |
124 } else { | 128 seconds, (float) frames / seconds); |
125 printf("%d fills and flips in zero seconds!n", frames); | 129 } else { |
126 } | 130 printf("%d fills and flips in zero seconds!n", frames); |
127 | 131 } |
128 /* clear the screen after fill test */ | 132 |
129 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); | 133 /* clear the screen after fill test */ |
130 SDL_Flip(screen); | 134 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); |
131 | 135 SDL_Flip(screen); |
132 while ( SDL_PollEvent(&event) ) { | 136 |
133 if ( event.type == SDL_KEYDOWN ) | 137 while (SDL_PollEvent(&event)) { |
134 return 0; | 138 if (event.type == SDL_KEYDOWN) |
135 } | 139 return 0; |
136 | 140 } |
137 /* run the generic blit test */ | 141 |
138 bmp = SDL_LoadBMP("sample.bmp"); | 142 /* run the generic blit test */ |
139 if ( ! bmp ) { | 143 bmp = SDL_LoadBMP("sample.bmp"); |
140 printf("Couldn't load sample.bmp: %s\n", SDL_GetError()); | 144 if (!bmp) { |
141 return 0; | 145 printf("Couldn't load sample.bmp: %s\n", SDL_GetError()); |
142 } | 146 return 0; |
143 printf("Running freshly loaded blit test: %dx%d at %d bpp, flags: ", | 147 } |
144 bmp->w, bmp->h, bmp->format->BitsPerPixel); | 148 printf("Running freshly loaded blit test: %dx%d at %d bpp, flags: ", |
145 PrintFlags(bmp->flags); | 149 bmp->w, bmp->h, bmp->format->BitsPerPixel); |
146 printf("\n"); | 150 PrintFlags(bmp->flags); |
147 then = SDL_GetTicks(); | 151 printf("\n"); |
148 frames = RunBlitTests(screen, bmp, NUM_BLITS); | 152 then = SDL_GetTicks(); |
149 now = SDL_GetTicks(); | 153 frames = RunBlitTests(screen, bmp, NUM_BLITS); |
150 seconds = (float)(now - then) / 1000.0f; | 154 now = SDL_GetTicks(); |
151 if ( seconds > 0.0f ) { | 155 seconds = (float) (now - then) / 1000.0f; |
152 printf("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds); | 156 if (seconds > 0.0f) { |
153 } else { | 157 printf("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n", |
154 printf("%d blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames); | 158 NUM_BLITS * frames, frames, seconds, (float) frames / seconds); |
155 } | 159 } else { |
156 | 160 printf("%d blits / %d updates in zero seconds!\n", |
157 /* clear the screen after blit test */ | 161 NUM_BLITS * frames, frames); |
158 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); | 162 } |
159 SDL_Flip(screen); | 163 |
160 | 164 /* clear the screen after blit test */ |
161 while ( SDL_PollEvent(&event) ) { | 165 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); |
162 if ( event.type == SDL_KEYDOWN ) | 166 SDL_Flip(screen); |
163 return 0; | 167 |
164 } | 168 while (SDL_PollEvent(&event)) { |
165 | 169 if (event.type == SDL_KEYDOWN) |
166 /* run the colorkeyed blit test */ | 170 return 0; |
167 bmpcc = SDL_LoadBMP("sample.bmp"); | 171 } |
168 if ( ! bmpcc ) { | 172 |
169 printf("Couldn't load sample.bmp: %s\n", SDL_GetError()); | 173 /* run the colorkeyed blit test */ |
170 return 0; | 174 bmpcc = SDL_LoadBMP("sample.bmp"); |
171 } | 175 if (!bmpcc) { |
172 printf("Running freshly loaded cc blit test: %dx%d at %d bpp, flags: ", | 176 printf("Couldn't load sample.bmp: %s\n", SDL_GetError()); |
173 bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel); | 177 return 0; |
174 SDL_SetColorKey(bmpcc, SDL_SRCCOLORKEY | SDL_RLEACCEL, *(Uint8 *)bmpcc->pixels); | 178 } |
175 | 179 printf("Running freshly loaded cc blit test: %dx%d at %d bpp, flags: ", |
176 PrintFlags(bmpcc->flags); | 180 bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel); |
177 printf("\n"); | 181 SDL_SetColorKey(bmpcc, SDL_SRCCOLORKEY | SDL_RLEACCEL, |
178 then = SDL_GetTicks(); | 182 *(Uint8 *) bmpcc->pixels); |
179 frames = RunBlitTests(screen, bmpcc, NUM_BLITS); | 183 |
180 now = SDL_GetTicks(); | 184 PrintFlags(bmpcc->flags); |
181 seconds = (float)(now - then) / 1000.0f; | 185 printf("\n"); |
182 if ( seconds > 0.0f ) { | 186 then = SDL_GetTicks(); |
183 printf("%d cc blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds); | 187 frames = RunBlitTests(screen, bmpcc, NUM_BLITS); |
184 } else { | 188 now = SDL_GetTicks(); |
185 printf("%d cc blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames); | 189 seconds = (float) (now - then) / 1000.0f; |
186 } | 190 if (seconds > 0.0f) { |
187 | 191 printf("%d cc blits / %d updates in %2.2f seconds, %2.2f FPS\n", |
188 /* clear the screen after cc blit test */ | 192 NUM_BLITS * frames, frames, seconds, (float) frames / seconds); |
189 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); | 193 } else { |
190 SDL_Flip(screen); | 194 printf("%d cc blits / %d updates in zero seconds!\n", |
191 | 195 NUM_BLITS * frames, frames); |
192 while ( SDL_PollEvent(&event) ) { | 196 } |
193 if ( event.type == SDL_KEYDOWN ) | 197 |
194 return 0; | 198 /* clear the screen after cc blit test */ |
195 } | 199 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); |
196 | 200 SDL_Flip(screen); |
197 /* run the generic blit test */ | 201 |
198 tmp = bmp; | 202 while (SDL_PollEvent(&event)) { |
199 bmp = SDL_DisplayFormat(bmp); | 203 if (event.type == SDL_KEYDOWN) |
200 SDL_FreeSurface(tmp); | 204 return 0; |
201 if ( ! bmp ) { | 205 } |
202 printf("Couldn't convert sample.bmp: %s\n", SDL_GetError()); | 206 |
203 return 0; | 207 /* run the generic blit test */ |
204 } | 208 tmp = bmp; |
205 printf("Running display format blit test: %dx%d at %d bpp, flags: ", | 209 bmp = SDL_DisplayFormat(bmp); |
206 bmp->w, bmp->h, bmp->format->BitsPerPixel); | 210 SDL_FreeSurface(tmp); |
207 PrintFlags(bmp->flags); | 211 if (!bmp) { |
208 printf("\n"); | 212 printf("Couldn't convert sample.bmp: %s\n", SDL_GetError()); |
209 then = SDL_GetTicks(); | 213 return 0; |
210 frames = RunBlitTests(screen, bmp, NUM_BLITS); | 214 } |
211 now = SDL_GetTicks(); | 215 printf("Running display format blit test: %dx%d at %d bpp, flags: ", |
212 seconds = (float)(now - then) / 1000.0f; | 216 bmp->w, bmp->h, bmp->format->BitsPerPixel); |
213 if ( seconds > 0.0f ) { | 217 PrintFlags(bmp->flags); |
214 printf("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds); | 218 printf("\n"); |
215 } else { | 219 then = SDL_GetTicks(); |
216 printf("%d blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames); | 220 frames = RunBlitTests(screen, bmp, NUM_BLITS); |
217 } | 221 now = SDL_GetTicks(); |
218 | 222 seconds = (float) (now - then) / 1000.0f; |
219 /* clear the screen after blit test */ | 223 if (seconds > 0.0f) { |
220 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); | 224 printf("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n", |
221 SDL_Flip(screen); | 225 NUM_BLITS * frames, frames, seconds, (float) frames / seconds); |
222 | 226 } else { |
223 while ( SDL_PollEvent(&event) ) { | 227 printf("%d blits / %d updates in zero seconds!\n", |
224 if ( event.type == SDL_KEYDOWN ) | 228 NUM_BLITS * frames, frames); |
225 return 0; | 229 } |
226 } | 230 |
227 | 231 /* clear the screen after blit test */ |
228 /* run the colorkeyed blit test */ | 232 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); |
229 tmp = bmpcc; | 233 SDL_Flip(screen); |
230 bmpcc = SDL_DisplayFormat(bmpcc); | 234 |
231 SDL_FreeSurface(tmp); | 235 while (SDL_PollEvent(&event)) { |
232 if ( ! bmpcc ) { | 236 if (event.type == SDL_KEYDOWN) |
233 printf("Couldn't convert sample.bmp: %s\n", SDL_GetError()); | 237 return 0; |
234 return 0; | 238 } |
235 } | 239 |
236 printf("Running display format cc blit test: %dx%d at %d bpp, flags: ", | 240 /* run the colorkeyed blit test */ |
237 bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel); | 241 tmp = bmpcc; |
238 PrintFlags(bmpcc->flags); | 242 bmpcc = SDL_DisplayFormat(bmpcc); |
239 printf("\n"); | 243 SDL_FreeSurface(tmp); |
240 then = SDL_GetTicks(); | 244 if (!bmpcc) { |
241 frames = RunBlitTests(screen, bmpcc, NUM_BLITS); | 245 printf("Couldn't convert sample.bmp: %s\n", SDL_GetError()); |
242 now = SDL_GetTicks(); | 246 return 0; |
243 seconds = (float)(now - then) / 1000.0f; | 247 } |
244 if ( seconds > 0.0f ) { | 248 printf("Running display format cc blit test: %dx%d at %d bpp, flags: ", |
245 printf("%d cc blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds); | 249 bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel); |
246 } else { | 250 PrintFlags(bmpcc->flags); |
247 printf("%d cc blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames); | 251 printf("\n"); |
248 } | 252 then = SDL_GetTicks(); |
249 | 253 frames = RunBlitTests(screen, bmpcc, NUM_BLITS); |
250 /* clear the screen after cc blit test */ | 254 now = SDL_GetTicks(); |
251 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); | 255 seconds = (float) (now - then) / 1000.0f; |
252 SDL_Flip(screen); | 256 if (seconds > 0.0f) { |
253 | 257 printf("%d cc blits / %d updates in %2.2f seconds, %2.2f FPS\n", |
254 while ( SDL_PollEvent(&event) ) { | 258 NUM_BLITS * frames, frames, seconds, (float) frames / seconds); |
255 if ( event.type == SDL_KEYDOWN ) | 259 } else { |
256 return 0; | 260 printf("%d cc blits / %d updates in zero seconds!\n", |
257 } | 261 NUM_BLITS * frames, frames); |
258 | 262 } |
259 /* run the alpha blit test only if screen bpp>8 */ | 263 |
260 if (bmp->format->BitsPerPixel>8) | 264 /* clear the screen after cc blit test */ |
265 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); | |
266 SDL_Flip(screen); | |
267 | |
268 while (SDL_PollEvent(&event)) { | |
269 if (event.type == SDL_KEYDOWN) | |
270 return 0; | |
271 } | |
272 | |
273 /* run the alpha blit test only if screen bpp>8 */ | |
274 if (bmp->format->BitsPerPixel > 8) { | |
275 SDL_FreeSurface(bmp); | |
276 bmp = SDL_LoadBMP("sample.bmp"); | |
277 SDL_SetAlpha(bmp, SDL_SRCALPHA, 85); /* 85 - 33% alpha */ | |
278 tmp = bmp; | |
279 bmp = SDL_DisplayFormat(bmp); | |
280 SDL_FreeSurface(tmp); | |
281 if (!bmp) { | |
282 printf("Couldn't convert sample.bmp: %s\n", SDL_GetError()); | |
283 return 0; | |
284 } | |
285 printf | |
286 ("Running display format alpha blit test: %dx%d at %d bpp, flags: ", | |
287 bmp->w, bmp->h, bmp->format->BitsPerPixel); | |
288 PrintFlags(bmp->flags); | |
289 printf("\n"); | |
290 then = SDL_GetTicks(); | |
291 frames = RunBlitTests(screen, bmp, NUM_BLITS); | |
292 now = SDL_GetTicks(); | |
293 seconds = (float) (now - then) / 1000.0f; | |
294 if (seconds > 0.0f) { | |
295 printf | |
296 ("%d alpha blits / %d updates in %2.2f seconds, %2.2f FPS\n", | |
297 NUM_BLITS * frames, frames, seconds, | |
298 (float) frames / seconds); | |
299 } else { | |
300 printf("%d alpha blits / %d updates in zero seconds!\n", | |
301 NUM_BLITS * frames, frames); | |
302 } | |
303 } | |
304 | |
305 /* clear the screen after alpha blit test */ | |
306 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); | |
307 SDL_Flip(screen); | |
308 | |
309 while (SDL_PollEvent(&event)) { | |
310 if (event.type == SDL_KEYDOWN) | |
311 return 0; | |
312 } | |
313 | |
314 /* run the cc+alpha blit test only if screen bpp>8 */ | |
315 if (bmp->format->BitsPerPixel > 8) { | |
316 SDL_FreeSurface(bmpcc); | |
317 bmpcc = SDL_LoadBMP("sample.bmp"); | |
318 SDL_SetAlpha(bmpcc, SDL_SRCALPHA, 85); /* 85 - 33% alpha */ | |
319 SDL_SetColorKey(bmpcc, SDL_SRCCOLORKEY | SDL_RLEACCEL, | |
320 *(Uint8 *) bmpcc->pixels); | |
321 tmp = bmpcc; | |
322 bmpcc = SDL_DisplayFormat(bmpcc); | |
323 SDL_FreeSurface(tmp); | |
324 if (!bmpcc) { | |
325 printf("Couldn't convert sample.bmp: %s\n", SDL_GetError()); | |
326 return 0; | |
327 } | |
328 printf | |
329 ("Running display format cc+alpha blit test: %dx%d at %d bpp, flags: ", | |
330 bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel); | |
331 PrintFlags(bmpcc->flags); | |
332 printf("\n"); | |
333 then = SDL_GetTicks(); | |
334 frames = RunBlitTests(screen, bmpcc, NUM_BLITS); | |
335 now = SDL_GetTicks(); | |
336 seconds = (float) (now - then) / 1000.0f; | |
337 if (seconds > 0.0f) { | |
338 printf | |
339 ("%d cc+alpha blits / %d updates in %2.2f seconds, %2.2f FPS\n", | |
340 NUM_BLITS * frames, frames, seconds, | |
341 (float) frames / seconds); | |
342 } else { | |
343 printf("%d cc+alpha blits / %d updates in zero seconds!\n", | |
344 NUM_BLITS * frames, frames); | |
345 } | |
346 } | |
347 | |
348 SDL_FreeSurface(bmpcc); | |
349 SDL_FreeSurface(bmp); | |
350 | |
351 while (SDL_PollEvent(&event)) { | |
352 if (event.type == SDL_KEYDOWN) | |
353 return 0; | |
354 } | |
355 return 1; | |
356 } | |
357 | |
358 void | |
359 RunVideoTests() | |
360 { | |
361 static const struct | |
362 { | |
363 int w, h, bpp; | |
364 } mode_list[] = { | |
261 { | 365 { |
262 SDL_FreeSurface(bmp); | 366 640, 480, 8}, { |
263 bmp = SDL_LoadBMP("sample.bmp"); | 367 640, 480, 16}, { |
264 SDL_SetAlpha(bmp, SDL_SRCALPHA, 85); /* 85 - 33% alpha */ | 368 640, 480, 32}, { |
265 tmp = bmp; | 369 800, 600, 8}, { |
266 bmp = SDL_DisplayFormat(bmp); | 370 800, 600, 16}, { |
267 SDL_FreeSurface(tmp); | 371 800, 600, 32}, { |
268 if ( ! bmp ) { | 372 1024, 768, 8}, { |
269 printf("Couldn't convert sample.bmp: %s\n", SDL_GetError()); | 373 1024, 768, 16}, { |
270 return 0; | 374 1024, 768, 32} |
271 } | 375 }; |
272 printf("Running display format alpha blit test: %dx%d at %d bpp, flags: ", | 376 static const Uint32 flags[] = { |
273 bmp->w, bmp->h, bmp->format->BitsPerPixel); | 377 (SDL_SWSURFACE), |
274 PrintFlags(bmp->flags); | 378 (SDL_SWSURFACE | SDL_FULLSCREEN), |
275 printf("\n"); | 379 (SDL_HWSURFACE | SDL_FULLSCREEN), |
276 then = SDL_GetTicks(); | 380 (SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF) |
277 frames = RunBlitTests(screen, bmp, NUM_BLITS); | 381 }; |
278 now = SDL_GetTicks(); | 382 int i, j; |
279 seconds = (float)(now - then) / 1000.0f; | 383 SDL_Surface *screen; |
280 if ( seconds > 0.0f ) { | 384 |
281 printf("%d alpha blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds); | 385 /* Test out several different video mode combinations */ |
282 } else { | 386 SDL_WM_SetCaption("SDL Video Benchmark", "vidtest"); |
283 printf("%d alpha blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames); | 387 SDL_ShowCursor(0); |
284 } | 388 for (i = 0; i < SDL_TABLESIZE(mode_list); ++i) { |
285 } | 389 for (j = 0; j < SDL_TABLESIZE(flags); ++j) { |
286 | 390 printf("===================================\n"); |
287 /* clear the screen after alpha blit test */ | 391 printf("Setting video mode: %dx%d at %d bpp, flags: ", |
288 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); | 392 mode_list[i].w, mode_list[i].h, mode_list[i].bpp); |
289 SDL_Flip(screen); | 393 PrintFlags(flags[j]); |
290 | 394 printf("\n"); |
291 while ( SDL_PollEvent(&event) ) { | 395 screen = SDL_SetVideoMode(mode_list[i].w, |
292 if ( event.type == SDL_KEYDOWN ) | 396 mode_list[i].h, |
293 return 0; | 397 mode_list[i].bpp, flags[j]); |
294 } | 398 if (!screen) { |
295 | 399 printf("Setting video mode failed: %s\n", SDL_GetError()); |
296 /* run the cc+alpha blit test only if screen bpp>8 */ | 400 continue; |
297 if (bmp->format->BitsPerPixel>8) | 401 } |
298 { | 402 if ((screen->flags & FLAG_MASK) != flags[j]) { |
299 SDL_FreeSurface(bmpcc); | 403 printf("Flags didn't match: "); |
300 bmpcc = SDL_LoadBMP("sample.bmp"); | 404 PrintFlags(screen->flags); |
301 SDL_SetAlpha(bmpcc, SDL_SRCALPHA, 85); /* 85 - 33% alpha */ | 405 printf("\n"); |
302 SDL_SetColorKey(bmpcc, SDL_SRCCOLORKEY | SDL_RLEACCEL, *(Uint8 *)bmpcc->pixels); | 406 continue; |
303 tmp = bmpcc; | 407 } |
304 bmpcc = SDL_DisplayFormat(bmpcc); | 408 if (!RunModeTests(screen)) { |
305 SDL_FreeSurface(tmp); | 409 return; |
306 if ( ! bmpcc ) { | 410 } |
307 printf("Couldn't convert sample.bmp: %s\n", SDL_GetError()); | 411 } |
308 return 0; | 412 } |
309 } | |
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); | |
313 printf("\n"); | |
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); | |
320 } else { | |
321 printf("%d cc+alpha blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames); | |
322 } | |
323 } | |
324 | |
325 SDL_FreeSurface(bmpcc); | |
326 SDL_FreeSurface(bmp); | |
327 | |
328 while ( SDL_PollEvent(&event) ) { | |
329 if ( event.type == SDL_KEYDOWN ) | |
330 return 0; | |
331 } | |
332 return 1; | |
333 } | 413 } |
334 | 414 #endif |
335 void RunVideoTests() | 415 |
416 int | |
417 main(int argc, char *argv[]) | |
336 { | 418 { |
337 static const struct { | 419 const SDL_VideoInfo *info; |
338 int w, h, bpp; | 420 int i, d, n; |
339 } mode_list[] = { | 421 const char *driver; |
340 { 640, 480, 8 }, { 640, 480, 16 }, { 640, 480, 32 }, | 422 const SDL_DisplayMode *mode; |
341 { 800, 600, 8 }, { 800, 600, 16 }, { 800, 600, 32 }, | 423 int bpp; |
342 { 1024, 768, 8 }, { 1024, 768, 16 }, { 1024, 768, 32 } | 424 Uint32 Rmask, Gmask, Bmask, Amask; |
343 }; | 425 int nmodes; |
344 static const Uint32 flags[] = { | 426 |
345 (SDL_SWSURFACE), | 427 /* Print available video drivers */ |
346 (SDL_SWSURFACE | SDL_FULLSCREEN), | 428 n = SDL_GetNumVideoDrivers(); |
347 (SDL_HWSURFACE | SDL_FULLSCREEN), | 429 if (n == 0) { |
348 (SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF) | 430 printf("No built-in video drivers\n"); |
349 }; | 431 } else { |
350 int i, j; | 432 printf("Built-in video drivers:"); |
351 SDL_Surface *screen; | 433 for (i = 0; i < n; ++i) { |
352 | 434 if (i > 0) { |
353 /* Test out several different video mode combinations */ | 435 printf(","); |
354 SDL_WM_SetCaption("SDL Video Benchmark", "vidtest"); | 436 } |
355 SDL_ShowCursor(0); | 437 printf(" %s", SDL_GetVideoDriver(i)); |
356 for ( i = 0; i < SDL_TABLESIZE(mode_list); ++i ) { | 438 } |
357 for ( j = 0; j < SDL_TABLESIZE(flags); ++j ) { | 439 printf("\n"); |
358 printf("===================================\n"); | 440 } |
359 printf("Setting video mode: %dx%d at %d bpp, flags: ", | 441 |
360 mode_list[i].w, | 442 if (SDL_Init(SDL_INIT_VIDEO) < 0) { |
361 mode_list[i].h, | 443 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); |
362 mode_list[i].bpp); | 444 exit(1); |
363 PrintFlags(flags[j]); | 445 } |
364 printf("\n"); | 446 driver = SDL_GetCurrentVideoDriver(); |
365 screen = SDL_SetVideoMode(mode_list[i].w, | 447 if (driver) { |
366 mode_list[i].h, | 448 printf("Video driver: %s\n", driver); |
367 mode_list[i].bpp, | 449 } |
368 flags[j]); | 450 printf("Number of displays: %d\n", SDL_GetNumVideoDisplays()); |
369 if ( ! screen ) { | 451 for (d = 0; d < SDL_GetNumVideoDisplays(); ++d) { |
370 printf("Setting video mode failed: %s\n", SDL_GetError()); | 452 printf("Display %d:\n", d); |
371 continue; | 453 SDL_SelectVideoDisplay(d); |
372 } | 454 |
373 if ( (screen->flags & FLAG_MASK) != flags[j] ) { | 455 mode = SDL_GetDesktopDisplayMode(); |
374 printf("Flags didn't match: "); | 456 SDL_PixelFormatEnumToMasks(mode->format, &bpp, &Rmask, &Gmask, &Bmask, |
375 PrintFlags(screen->flags); | 457 &Amask); |
376 printf("\n"); | 458 printf(" Current mode: %dx%d@%dHz, %d bits-per-pixel\n", mode->w, |
377 continue; | 459 mode->h, mode->refresh_rate, bpp); |
378 } | 460 if (Rmask || Gmask || Bmask) { |
379 if ( ! RunModeTests(screen) ) { | 461 printf(" Red Mask = 0x%.8x\n", Rmask); |
380 return; | 462 printf(" Green Mask = 0x%.8x\n", Gmask); |
381 } | 463 printf(" Blue Mask = 0x%.8x\n", Bmask); |
382 } | 464 if (Amask) |
383 } | 465 printf(" Alpha Mask = 0x%.8x\n", Amask); |
466 } | |
467 | |
468 /* Print available fullscreen video modes */ | |
469 nmodes = SDL_GetNumDisplayModes(); | |
470 if (nmodes == 0) { | |
471 printf("No available fullscreen video modes\n"); | |
472 } else { | |
473 printf(" Fullscreen video modes:\n"); | |
474 for (i = 0; i < nmodes; ++i) { | |
475 mode = SDL_GetDisplayMode(i); | |
476 SDL_PixelFormatEnumToMasks(mode->format, &bpp, &Rmask, | |
477 &Gmask, &Bmask, &Amask); | |
478 printf(" Mode %d: %dx%d@%dHz, %d bits-per-pixel\n", i, | |
479 mode->w, mode->h, mode->refresh_rate, bpp); | |
480 if (Rmask || Gmask || Bmask) { | |
481 printf(" Red Mask = 0x%.8x\n", Rmask); | |
482 printf(" Green Mask = 0x%.8x\n", Gmask); | |
483 printf(" Blue Mask = 0x%.8x\n", Bmask); | |
484 if (Amask) | |
485 printf(" Alpha Mask = 0x%.8x\n", Amask); | |
486 } | |
487 } | |
488 } | |
489 } | |
490 | |
491 info = SDL_GetVideoInfo(); | |
492 if (info->wm_available) { | |
493 printf("A window manager is available\n"); | |
494 } | |
495 if (info->hw_available) { | |
496 printf("Hardware surfaces are available (%dK video memory)\n", | |
497 info->video_mem); | |
498 } | |
499 if (info->blit_hw) { | |
500 printf("Copy blits between hardware surfaces are accelerated\n"); | |
501 } | |
502 if (info->blit_hw_CC) { | |
503 printf("Colorkey blits between hardware surfaces are accelerated\n"); | |
504 } | |
505 if (info->blit_hw_A) { | |
506 printf("Alpha blits between hardware surfaces are accelerated\n"); | |
507 } | |
508 if (info->blit_sw) { | |
509 printf | |
510 ("Copy blits from software surfaces to hardware surfaces are accelerated\n"); | |
511 } | |
512 if (info->blit_sw_CC) { | |
513 printf | |
514 ("Colorkey blits from software surfaces to hardware surfaces are accelerated\n"); | |
515 } | |
516 if (info->blit_sw_A) { | |
517 printf | |
518 ("Alpha blits from software surfaces to hardware surfaces are accelerated\n"); | |
519 } | |
520 if (info->blit_fill) { | |
521 printf("Color fills on hardware surfaces are accelerated\n"); | |
522 } | |
523 #if 0 | |
524 if (argv[1] && (strcmp(argv[1], "-benchmark") == 0)) { | |
525 RunVideoTests(); | |
526 } | |
527 #endif | |
528 | |
529 SDL_Quit(); | |
530 return (0); | |
384 } | 531 } |
385 | |
386 int main(int argc, char *argv[]) | |
387 { | |
388 const SDL_VideoInfo *info; | |
389 int i; | |
390 SDL_Rect **modes; | |
391 char driver[128]; | |
392 | |
393 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { | |
394 fprintf(stderr, | |
395 "Couldn't initialize SDL: %s\n", SDL_GetError()); | |
396 exit(1); | |
397 } | |
398 if ( SDL_VideoDriverName(driver, sizeof(driver)) ) { | |
399 printf("Video driver: %s\n", driver); | |
400 } | |
401 info = SDL_GetVideoInfo(); | |
402 printf( | |
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); | |
409 } | |
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"); | |
414 } else | |
415 if ( modes == (SDL_Rect **)-1 ) { | |
416 printf("No special fullscreen video modes\n"); | |
417 } else { | |
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); | |
421 } | |
422 } | |
423 if ( info->wm_available ) { | |
424 printf("A window manager is available\n"); | |
425 } | |
426 if ( info->hw_available ) { | |
427 printf("Hardware surfaces are available (%dK video memory)\n", | |
428 info->video_mem); | |
429 } | |
430 if ( info->blit_hw ) { | |
431 printf( | |
432 "Copy blits between hardware surfaces are accelerated\n"); | |
433 } | |
434 if ( info->blit_hw_CC ) { | |
435 printf( | |
436 "Colorkey blits between hardware surfaces are accelerated\n"); | |
437 } | |
438 if ( info->blit_hw_A ) { | |
439 printf( | |
440 "Alpha blits between hardware surfaces are accelerated\n"); | |
441 } | |
442 if ( info->blit_sw ) { | |
443 printf( | |
444 "Copy blits from software surfaces to hardware surfaces are accelerated\n"); | |
445 } | |
446 if ( info->blit_sw_CC ) { | |
447 printf( | |
448 "Colorkey blits from software surfaces to hardware surfaces are accelerated\n"); | |
449 } | |
450 if ( info->blit_sw_A ) { | |
451 printf( | |
452 "Alpha blits from software surfaces to hardware surfaces are accelerated\n"); | |
453 } | |
454 if ( info->blit_fill ) { | |
455 printf( | |
456 "Color fills on hardware surfaces are accelerated\n"); | |
457 } | |
458 | |
459 if ( argv[1] && (strcmp(argv[1], "-benchmark") == 0) ) { | |
460 RunVideoTests(); | |
461 } | |
462 | |
463 SDL_Quit(); | |
464 return(0); | |
465 } |