Mercurial > sdl-ios-xcode
annotate test/testvidinfo.c @ 482:6417071ba2e5
*** empty log message ***
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 01 Sep 2002 00:38:49 +0000 |
parents | 92596bfe8446 |
children | 32190cba6c40 |
rev | line source |
---|---|
0 | 1 |
2 /* Simple program -- figure out what kind of video display we have */ | |
3 | |
479
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
4 #include <stdlib.h> |
0 | 5 #include <stdio.h> |
6 #include <stdlib.h> | |
7 | |
8 #include "SDL.h" | |
9 | |
480
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
10 #define NUM_BLITS 10 |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
11 #define NUM_UPDATES 500 |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
12 |
479
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
13 #define FLAG_MASK (SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF) |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
14 |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
15 void PrintFlags(Uint32 flags) |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
16 { |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
17 printf("0x%8.8x", (flags & FLAG_MASK)); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
18 if ( flags & SDL_HWSURFACE ) { |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
19 printf(" SDL_HWSURFACE"); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
20 } else { |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
21 printf(" SDL_SWSURFACE"); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
22 } |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
23 if ( flags & SDL_FULLSCREEN ) { |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
24 printf(" | SDL_FULLSCREEN"); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
25 } |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
26 if ( flags & SDL_DOUBLEBUF ) { |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
27 printf(" | SDL_DOUBLEBUF"); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
28 } |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
29 } |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
30 |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
31 int RunBlitTests(SDL_Surface *screen, SDL_Surface *bmp, int blitcount) |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
32 { |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
33 int i, j; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
34 int maxx; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
35 int maxy; |
480
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
36 SDL_Rect dst; |
479
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
37 |
480
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
38 maxx = (int)screen->w - bmp->w + 1; |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
39 maxy = (int)screen->h - bmp->h + 1; |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
40 for ( i = 0; i < NUM_UPDATES; ++i ) { |
479
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
41 for ( j = 0; j < blitcount; ++j ) { |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
42 if ( maxx ) { |
480
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
43 dst.x = rand() % maxx; |
479
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
44 } else { |
480
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
45 dst.x = 0; |
479
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
46 } |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
47 if ( maxy ) { |
480
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
48 dst.y = rand() % maxy; |
479
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
49 } else { |
480
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
50 dst.y = 0; |
479
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
51 } |
480
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
52 dst.w = bmp->w; |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
53 dst.h = bmp->h; |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
54 SDL_BlitSurface(bmp, NULL, screen, &dst); |
479
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
55 } |
480
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
56 SDL_Flip(screen); |
479
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
57 } |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
58 |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
59 return i; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
60 } |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
61 |
480
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
62 int RunModeTests(SDL_Surface *screen) |
479
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
63 { |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
64 Uint32 then, now; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
65 Uint32 frames; |
480
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
66 float seconds; |
479
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
67 int i; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
68 Uint8 r, g, b; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
69 Uint32 pixel; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
70 SDL_Surface *bmp, *tmp; |
480
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
71 SDL_Event event; |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
72 |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
73 while ( SDL_PollEvent(&event) ) { |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
74 if ( event.type == SDL_KEYDOWN ) |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
75 return 0; |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
76 } |
479
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
77 |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
78 /* First test fills and screen update speed */ |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
79 printf("Running color fill and fullscreen update test\n"); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
80 then = SDL_GetTicks(); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
81 frames = 0; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
82 for ( i = 0; i < 256; ++i ) { |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
83 r = i; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
84 g = 0; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
85 b = 0; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
86 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b)); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
87 SDL_Flip(screen); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
88 ++frames; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
89 } |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
90 for ( i = 0; i < 256; ++i ) { |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
91 r = 0; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
92 g = i; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
93 b = 0; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
94 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b)); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
95 SDL_Flip(screen); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
96 ++frames; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
97 } |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
98 for ( i = 0; i < 256; ++i ) { |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
99 r = 0; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
100 g = 0; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
101 b = i; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
102 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b)); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
103 SDL_Flip(screen); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
104 ++frames; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
105 } |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
106 now = SDL_GetTicks(); |
480
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
107 seconds = (float)(now - then) / 1000.0f; |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
108 if ( seconds > 0.0f ) { |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
109 printf("%d fills and flips in %2.2f seconds, %2.2f FPS\n", frames, seconds, (float)frames / seconds); |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
110 } else { |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
111 printf("%d fills and flips in zero seconds!n", frames); |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
112 } |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
113 |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
114 while ( SDL_PollEvent(&event) ) { |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
115 if ( event.type == SDL_KEYDOWN ) |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
116 return 0; |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
117 } |
479
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
118 |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
119 bmp = SDL_LoadBMP("sample.bmp"); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
120 if ( ! bmp ) { |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
121 printf("Couldn't load sample.bmp: %s\n", SDL_GetError()); |
482
6417071ba2e5
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
480
diff
changeset
|
122 return 0; |
479
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
123 } |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
124 printf("Running freshly loaded blit test: %dx%d at %d bpp, flags: ", |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
125 bmp->w, bmp->h, bmp->format->BitsPerPixel); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
126 PrintFlags(bmp->flags); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
127 printf("\n"); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
128 then = SDL_GetTicks(); |
480
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
129 frames = RunBlitTests(screen, bmp, NUM_BLITS); |
479
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
130 now = SDL_GetTicks(); |
480
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
131 seconds = (float)(now - then) / 1000.0f; |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
132 if ( seconds > 0.0f ) { |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
133 printf("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds); |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
134 } else { |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
135 printf("%d blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames); |
479
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
136 } |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
137 |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
138 tmp = bmp; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
139 bmp = SDL_DisplayFormat(bmp); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
140 SDL_FreeSurface(tmp); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
141 if ( ! bmp ) { |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
142 printf("Couldn't convert sample.bmp: %s\n", SDL_GetError()); |
482
6417071ba2e5
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
480
diff
changeset
|
143 return 0; |
479
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
144 } |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
145 printf("Running display format blit test: %dx%d at %d bpp, flags: ", |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
146 bmp->w, bmp->h, bmp->format->BitsPerPixel); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
147 PrintFlags(bmp->flags); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
148 printf("\n"); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
149 then = SDL_GetTicks(); |
480
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
150 frames = RunBlitTests(screen, bmp, NUM_BLITS); |
479
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
151 now = SDL_GetTicks(); |
480
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
152 seconds = (float)(now - then) / 1000.0f; |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
153 if ( seconds > 0.0f ) { |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
154 printf("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds); |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
155 } else { |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
156 printf("%d blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames); |
479
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
157 } |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
158 SDL_FreeSurface(bmp); |
480
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
159 |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
160 while ( SDL_PollEvent(&event) ) { |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
161 if ( event.type == SDL_KEYDOWN ) |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
162 return 0; |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
163 } |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
164 return 1; |
479
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
165 } |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
166 |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
167 void RunVideoTests() |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
168 { |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
169 static const struct { |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
170 int w, h, bpp; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
171 } mode_list[] = { |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
172 { 640, 480, 8 }, { 640, 480, 16 }, { 640, 480, 32 }, |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
173 { 800, 600, 8 }, { 800, 600, 16 }, { 800, 600, 32 }, |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
174 { 1024, 768, 8 }, { 1024, 768, 16 }, { 1024, 768, 32 } |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
175 }; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
176 static const Uint32 flags[] = { |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
177 (SDL_SWSURFACE), |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
178 (SDL_SWSURFACE | SDL_FULLSCREEN), |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
179 (SDL_HWSURFACE | SDL_FULLSCREEN), |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
180 (SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF) |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
181 }; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
182 int i, j; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
183 SDL_Surface *screen; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
184 |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
185 /* Test out several different video mode combinations */ |
480
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
186 SDL_WM_SetCaption("SDL Video Benchmark", "vidtest"); |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
187 SDL_ShowCursor(0); |
479
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
188 for ( i = 0; i < SDL_TABLESIZE(mode_list); ++i ) { |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
189 for ( j = 0; j < SDL_TABLESIZE(flags); ++j ) { |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
190 printf("===================================\n"); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
191 printf("Setting video mode: %dx%d at %d bpp, flags: ", |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
192 mode_list[i].w, |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
193 mode_list[i].h, |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
194 mode_list[i].bpp); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
195 PrintFlags(flags[j]); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
196 printf("\n"); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
197 screen = SDL_SetVideoMode(mode_list[i].w, |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
198 mode_list[i].h, |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
199 mode_list[i].bpp, |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
200 flags[j]); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
201 if ( ! screen ) { |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
202 printf("Setting video mode failed: %s\n", SDL_GetError()); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
203 continue; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
204 } |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
205 if ( (screen->flags & FLAG_MASK) != flags[j] ) { |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
206 printf("Flags didn't match: "); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
207 PrintFlags(screen->flags); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
208 printf("\n"); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
209 continue; |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
210 } |
480
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
211 if ( ! RunModeTests(screen) ) { |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
212 return; |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
213 } |
479
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
214 } |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
215 } |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
216 } |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
217 |
0 | 218 int main(int argc, char *argv[]) |
219 { | |
220 const SDL_VideoInfo *info; | |
221 int i; | |
222 SDL_Rect **modes; | |
480
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
223 char driver[128]; |
0 | 224 |
225 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { | |
226 fprintf(stderr, | |
227 "Couldn't initialize SDL: %s\n", SDL_GetError()); | |
228 exit(1); | |
229 } | |
480
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
230 if ( SDL_VideoDriverName(driver, sizeof(driver)) ) { |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
231 printf("Video driver: %s\n", driver); |
92596bfe8446
Fixed some bugs and added some features to the -benchmark facility
Sam Lantinga <slouken@libsdl.org>
parents:
479
diff
changeset
|
232 } |
0 | 233 info = SDL_GetVideoInfo(); |
234 printf( | |
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); | |
240 } | |
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"); | |
245 } else | |
246 if ( modes == (SDL_Rect **)-1 ) { | |
247 printf("No special fullscreen video modes\n"); | |
248 } else { | |
249 printf("Fullscreen video modes:\n"); | |
250 for ( i=0; modes[i]; ++i ) { | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
251 printf("\t%dx%dx%d\n", modes[i]->w, modes[i]->h, info->vfmt->BitsPerPixel); |
0 | 252 } |
253 } | |
254 if ( info->wm_available ) { | |
255 printf("A window manager is available\n"); | |
256 } | |
257 if ( info->hw_available ) { | |
258 printf("Hardware surfaces are available (%dK video memory)\n", | |
259 info->video_mem); | |
260 } | |
261 if ( info->blit_hw ) { | |
262 printf( | |
263 "Copy blits between hardware surfaces are accelerated\n"); | |
264 } | |
265 if ( info->blit_hw_CC ) { | |
266 printf( | |
267 "Colorkey blits between hardware surfaces are accelerated\n"); | |
268 } | |
269 if ( info->blit_hw_A ) { | |
270 printf( | |
271 "Alpha blits between hardware surfaces are accelerated\n"); | |
272 } | |
273 if ( info->blit_sw ) { | |
274 printf( | |
275 "Copy blits from software surfaces to hardware surfaces are accelerated\n"); | |
276 } | |
277 if ( info->blit_sw_CC ) { | |
278 printf( | |
279 "Colorkey blits from software surfaces to hardware surfaces are accelerated\n"); | |
280 } | |
281 if ( info->blit_sw_A ) { | |
282 printf( | |
283 "Alpha blits from software surfaces to hardware surfaces are accelerated\n"); | |
284 } | |
285 if ( info->blit_fill ) { | |
286 printf( | |
287 "Color fills on hardware surfaces are accelerated\n"); | |
288 } | |
479
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
289 |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
290 if ( argv[1] && (strcmp(argv[1], "-benchmark") == 0) ) { |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
291 RunVideoTests(); |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
292 } |
c0a1744bc2cf
Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
293 |
0 | 294 SDL_Quit(); |
295 return(0); | |
296 } |