Skip to content

Latest commit

 

History

History
295 lines (273 loc) · 7.26 KB

testvidinfo.c

File metadata and controls

295 lines (273 loc) · 7.26 KB
 
Apr 26, 2001
Apr 26, 2001
1
2
3
/* Simple program -- figure out what kind of video display we have */
Aug 31, 2002
Aug 31, 2002
4
#include <stdlib.h>
Apr 26, 2001
Apr 26, 2001
5
6
7
8
9
#include <stdio.h>
#include <stdlib.h>
#include "SDL.h"
Aug 31, 2002
Aug 31, 2002
10
11
12
#define NUM_BLITS 10
#define NUM_UPDATES 500
Aug 31, 2002
Aug 31, 2002
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#define FLAG_MASK (SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF)
void PrintFlags(Uint32 flags)
{
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");
}
}
int RunBlitTests(SDL_Surface *screen, SDL_Surface *bmp, int blitcount)
{
int i, j;
int maxx;
int maxy;
Aug 31, 2002
Aug 31, 2002
36
SDL_Rect dst;
Aug 31, 2002
Aug 31, 2002
37
Aug 31, 2002
Aug 31, 2002
38
39
40
maxx = (int)screen->w - bmp->w + 1;
maxy = (int)screen->h - bmp->h + 1;
for ( i = 0; i < NUM_UPDATES; ++i ) {
Aug 31, 2002
Aug 31, 2002
41
42
for ( j = 0; j < blitcount; ++j ) {
if ( maxx ) {
Aug 31, 2002
Aug 31, 2002
43
dst.x = rand() % maxx;
Aug 31, 2002
Aug 31, 2002
44
} else {
Aug 31, 2002
Aug 31, 2002
45
dst.x = 0;
Aug 31, 2002
Aug 31, 2002
46
47
}
if ( maxy ) {
Aug 31, 2002
Aug 31, 2002
48
dst.y = rand() % maxy;
Aug 31, 2002
Aug 31, 2002
49
} else {
Aug 31, 2002
Aug 31, 2002
50
dst.y = 0;
Aug 31, 2002
Aug 31, 2002
51
}
Aug 31, 2002
Aug 31, 2002
52
53
54
dst.w = bmp->w;
dst.h = bmp->h;
SDL_BlitSurface(bmp, NULL, screen, &dst);
Aug 31, 2002
Aug 31, 2002
55
}
Aug 31, 2002
Aug 31, 2002
56
SDL_Flip(screen);
Aug 31, 2002
Aug 31, 2002
57
58
59
60
61
}
return i;
}
Aug 31, 2002
Aug 31, 2002
62
int RunModeTests(SDL_Surface *screen)
Aug 31, 2002
Aug 31, 2002
63
64
65
{
Uint32 then, now;
Uint32 frames;
Aug 31, 2002
Aug 31, 2002
66
float seconds;
Aug 31, 2002
Aug 31, 2002
67
68
69
int i;
Uint8 r, g, b;
SDL_Surface *bmp, *tmp;
Aug 31, 2002
Aug 31, 2002
70
71
72
73
74
75
SDL_Event event;
while ( SDL_PollEvent(&event) ) {
if ( event.type == SDL_KEYDOWN )
return 0;
}
Aug 31, 2002
Aug 31, 2002
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* 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();
Aug 31, 2002
Aug 31, 2002
106
107
108
109
110
111
112
113
114
115
116
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;
}
Aug 31, 2002
Aug 31, 2002
117
118
119
120
bmp = SDL_LoadBMP("sample.bmp");
if ( ! bmp ) {
printf("Couldn't load sample.bmp: %s\n", SDL_GetError());
Sep 1, 2002
Sep 1, 2002
121
return 0;
Aug 31, 2002
Aug 31, 2002
122
123
124
125
126
127
}
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();
Aug 31, 2002
Aug 31, 2002
128
frames = RunBlitTests(screen, bmp, NUM_BLITS);
Aug 31, 2002
Aug 31, 2002
129
now = SDL_GetTicks();
Aug 31, 2002
Aug 31, 2002
130
131
132
133
134
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);
Aug 31, 2002
Aug 31, 2002
135
136
137
138
139
140
141
}
tmp = bmp;
bmp = SDL_DisplayFormat(bmp);
SDL_FreeSurface(tmp);
if ( ! bmp ) {
printf("Couldn't convert sample.bmp: %s\n", SDL_GetError());
Sep 1, 2002
Sep 1, 2002
142
return 0;
Aug 31, 2002
Aug 31, 2002
143
144
145
146
147
148
}
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();
Aug 31, 2002
Aug 31, 2002
149
frames = RunBlitTests(screen, bmp, NUM_BLITS);
Aug 31, 2002
Aug 31, 2002
150
now = SDL_GetTicks();
Aug 31, 2002
Aug 31, 2002
151
152
153
154
155
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);
Aug 31, 2002
Aug 31, 2002
156
157
}
SDL_FreeSurface(bmp);
Aug 31, 2002
Aug 31, 2002
158
159
160
161
162
163
while ( SDL_PollEvent(&event) ) {
if ( event.type == SDL_KEYDOWN )
return 0;
}
return 1;
Aug 31, 2002
Aug 31, 2002
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
}
void RunVideoTests()
{
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 */
Aug 31, 2002
Aug 31, 2002
185
186
SDL_WM_SetCaption("SDL Video Benchmark", "vidtest");
SDL_ShowCursor(0);
Aug 31, 2002
Aug 31, 2002
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
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;
}
Aug 31, 2002
Aug 31, 2002
210
211
212
if ( ! RunModeTests(screen) ) {
return;
}
Aug 31, 2002
Aug 31, 2002
213
214
215
216
}
}
}
Apr 26, 2001
Apr 26, 2001
217
218
219
220
221
int main(int argc, char *argv[])
{
const SDL_VideoInfo *info;
int i;
SDL_Rect **modes;
Aug 31, 2002
Aug 31, 2002
222
char driver[128];
Apr 26, 2001
Apr 26, 2001
223
224
225
226
227
228
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr,
"Couldn't initialize SDL: %s\n", SDL_GetError());
exit(1);
}
Aug 31, 2002
Aug 31, 2002
229
230
231
if ( SDL_VideoDriverName(driver, sizeof(driver)) ) {
printf("Video driver: %s\n", driver);
}
Apr 26, 2001
Apr 26, 2001
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
info = SDL_GetVideoInfo();
printf(
"Current display: %d bits-per-pixel\n",info->vfmt->BitsPerPixel);
if ( info->vfmt->palette == NULL ) {
printf(" Red Mask = 0x%.8x\n", info->vfmt->Rmask);
printf(" Green Mask = 0x%.8x\n", info->vfmt->Gmask);
printf(" Blue Mask = 0x%.8x\n", info->vfmt->Bmask);
}
/* Print available fullscreen video modes */
modes = SDL_ListModes(NULL, SDL_FULLSCREEN);
if ( modes == (SDL_Rect **)0 ) {
printf("No available fullscreen video modes\n");
} else
if ( modes == (SDL_Rect **)-1 ) {
printf("No special fullscreen video modes\n");
} else {
printf("Fullscreen video modes:\n");
for ( i=0; modes[i]; ++i ) {
Jan 18, 2002
Jan 18, 2002
250
printf("\t%dx%dx%d\n", modes[i]->w, modes[i]->h, info->vfmt->BitsPerPixel);
Apr 26, 2001
Apr 26, 2001
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
}
}
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");
}
Aug 31, 2002
Aug 31, 2002
288
289
290
291
292
if ( argv[1] && (strcmp(argv[1], "-benchmark") == 0) ) {
RunVideoTests();
}
Apr 26, 2001
Apr 26, 2001
293
294
295
SDL_Quit();
return(0);
}