annotate test/testvidinfo.c @ 479:c0a1744bc2cf

Added a -benchmark flag for testing the speeds of various video modes
author Sam Lantinga <slouken@libsdl.org>
date Sat, 31 Aug 2002 19:48:11 +0000
parents c6abdda2f666
children 92596bfe8446
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 /* Simple program -- figure out what kind of video display we have */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
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
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 #include <stdio.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
6 #include <stdlib.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
8 #include "SDL.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
479
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
10 #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
11
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
12 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
13 {
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
14 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
15 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
16 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
17 } else {
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
18 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
19 }
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
20 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
21 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
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_DOUBLEBUF ) {
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_DOUBLEBUF");
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 }
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
27
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
28 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
29 {
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
30 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
31 int maxx;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
32 int maxy;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
33 SDL_Rect *rects;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
34
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
35 rects = (SDL_Rect *)malloc(blitcount * sizeof(*rects));
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
36 if ( ! rects ) {
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
37 return 0;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
38 }
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
39 maxx = (int)screen->w - bmp->w;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
40 maxy = (int)screen->h - bmp->h;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
41 for ( i = 0; i < 100; ++i ) {
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
42 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
43 if ( maxx ) {
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
44 rects[j].x = rand() % maxx;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
45 } else {
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
46 rects[j].x = 0;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
47 }
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
48 if ( maxy ) {
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
49 rects[j].y = rand() % maxy;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
50 } else {
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
51 rects[j].y = 0;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
52 }
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
53 rects[j].w = bmp->w;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
54 rects[j].h = bmp->h;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
55 SDL_BlitSurface(bmp, NULL, screen, &rects[j]);
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
56 }
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
57 if ( screen->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
58 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
59 } else {
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
60 SDL_UpdateRects(screen, blitcount, rects);
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
61 }
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
62 }
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
63 free(rects);
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
64
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
65 return i;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
66 }
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
67
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
68 void RunModeTests(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
69 {
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
70 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
71 Uint32 frames;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
72 int i;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
73 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
74 Uint32 pixel;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
75 SDL_Surface *bmp, *tmp;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
76
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
77 /* 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
78 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
79 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
80 frames = 0;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
81 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
82 r = i;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
83 g = 0;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
84 b = 0;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
85 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
86 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
87 ++frames;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
88 }
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
89 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
90 r = 0;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
91 g = i;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
92 b = 0;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
93 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
94 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
95 ++frames;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
96 }
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
97 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
98 r = 0;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
99 g = 0;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
100 b = i;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
101 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
102 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
103 ++frames;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
104 }
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
105 now = SDL_GetTicks();
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
106 printf("%d fills and flips, %f FPS\n", frames, (float)(now - then) / frames);
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
107
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
108 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
109 if ( ! bmp ) {
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
110 printf("Couldn't load sample.bmp: %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
111 return;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
112 }
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
113 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
114 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
115 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
116 printf("\n");
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
117 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
118 frames = RunBlitTests(screen, bmp, 10);
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
119 now = SDL_GetTicks();
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
120 if ( frames ) {
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
121 printf("%d blits, %d updates, %f FPS\n", 10*frames, frames, (float)(now - then) / frames);
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
122 }
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 tmp = bmp;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
125 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
126 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
127 if ( ! bmp ) {
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
128 printf("Couldn't convert sample.bmp: %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
129 return;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
130 }
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
131 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
132 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
133 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
134 printf("\n");
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
135 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
136 frames = RunBlitTests(screen, bmp, 10);
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
137 now = SDL_GetTicks();
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
138 if ( frames ) {
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
139 printf("%d blits, %d updates, %f FPS\n", 10*frames, frames, (float)(now - then) / frames);
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
140 }
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
141 SDL_FreeSurface(bmp);
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
142 }
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
143
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
144 void RunVideoTests()
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
145 {
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
146 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
147 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
148 } mode_list[] = {
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
149 { 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
150 { 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
151 { 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
152 };
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
153 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
154 (SDL_SWSURFACE),
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
155 (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
156 (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
157 (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
158 };
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
159 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
160 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
161
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
162 /* Test out several different video mode combinations */
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
163 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
164 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
165 printf("===================================\n");
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
166 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
167 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
168 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
169 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
170 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
171 printf("\n");
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
172 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
173 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
174 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
175 flags[j]);
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
176 if ( ! screen ) {
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
177 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
178 continue;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
179 }
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
180 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
181 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
182 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
183 printf("\n");
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
184 continue;
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
185 }
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
186 RunModeTests(screen);
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
187 }
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
188 }
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
189 }
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
190
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
191 int main(int argc, char *argv[])
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
192 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
193 const SDL_VideoInfo *info;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
194 int i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
195 SDL_Rect **modes;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
196
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
197 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
198 fprintf(stderr,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
199 "Couldn't initialize SDL: %s\n", SDL_GetError());
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
200 exit(1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
201 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
202 info = SDL_GetVideoInfo();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
203 printf(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
204 "Current display: %d bits-per-pixel\n",info->vfmt->BitsPerPixel);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
205 if ( info->vfmt->palette == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
206 printf(" Red Mask = 0x%.8x\n", info->vfmt->Rmask);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
207 printf(" Green Mask = 0x%.8x\n", info->vfmt->Gmask);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
208 printf(" Blue Mask = 0x%.8x\n", info->vfmt->Bmask);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
209 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
210 /* Print available fullscreen video modes */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
211 modes = SDL_ListModes(NULL, SDL_FULLSCREEN);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
212 if ( modes == (SDL_Rect **)0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
213 printf("No available fullscreen video modes\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
214 } else
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
215 if ( modes == (SDL_Rect **)-1 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
216 printf("No special fullscreen video modes\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
217 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
218 printf("Fullscreen video modes:\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
219 for ( i=0; modes[i]; ++i ) {
266
c6abdda2f666 Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents: 0
diff changeset
220 printf("\t%dx%dx%d\n", modes[i]->w, modes[i]->h, info->vfmt->BitsPerPixel);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
221 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
222 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
223 if ( info->wm_available ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
224 printf("A window manager is available\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
225 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
226 if ( info->hw_available ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
227 printf("Hardware surfaces are available (%dK video memory)\n",
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
228 info->video_mem);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
229 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
230 if ( info->blit_hw ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
231 printf(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
232 "Copy blits between hardware surfaces are accelerated\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
233 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
234 if ( info->blit_hw_CC ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
235 printf(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
236 "Colorkey blits between hardware surfaces are accelerated\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
237 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
238 if ( info->blit_hw_A ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
239 printf(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
240 "Alpha blits between hardware surfaces are accelerated\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
241 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
242 if ( info->blit_sw ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
243 printf(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
244 "Copy blits from software surfaces to hardware surfaces are accelerated\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
245 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
246 if ( info->blit_sw_CC ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
247 printf(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
248 "Colorkey blits from software surfaces to hardware surfaces are accelerated\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
249 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
250 if ( info->blit_sw_A ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
251 printf(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
252 "Alpha blits from software surfaces to hardware surfaces are accelerated\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
253 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
254 if ( info->blit_fill ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
255 printf(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
256 "Color fills on hardware surfaces are accelerated\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
257 }
479
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
258
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
259 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
260 RunVideoTests();
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
261 }
c0a1744bc2cf Added a -benchmark flag for testing the speeds of various video modes
Sam Lantinga <slouken@libsdl.org>
parents: 266
diff changeset
262
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
263 SDL_Quit();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
264 return(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
265 }