Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
546 lines (501 loc) · 16.6 KB

testvidinfo.c

File metadata and controls

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