test/testvidinfo.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 14 Feb 2004 20:22:21 +0000
changeset 821 30168104389f
parent 524 1b8ea19e9ee4
child 886 05c551e5bc64
permissions -rw-r--r--
Date: Sat, 14 Feb 2004 14:52:40 +0200
From: "Mike Gorchak"
Subject: Batch of the QNX6 fixes for the SDL

1. Updated readme.QNX
2. Fixed crashes during intensive window updating under fast machines (got over 200 rectangles for update).
3. Fixed double-buffered fullscreen modes, now it works as needed.
4. Fixed Photon detection algorithm.
5. Fixed HWSURFACE update function.
6. Added SDL_PHOTON_FULLSCREEN_REFRESH environment variable support for control refresh rates under Photon.
7. Added 640x400 fullscreen mode emulation via 640x480 (if videodriver not supports original 640x400 mode of course) shifted by 40 vertical pixels from begin, to center it. It's needed for some old DOS games which ran in doubled 320x200 mode.
8. Added available video ram amount support.
8. Added hardware surface allocation/deallocation support if current videomode and videodriver supports it.
9. Added hardware filling support.
10. Added hardware blits support (simple and colorkeyed).

And I've added to testvidinfo test color-keyed blits benchmark (maybe need to add alpha blits benchmark too ?). Currently Photon not supporting any alpha hardware blittings (all drivers lack of alpha blitting code support, only software alpha blitting exist in photon, which is hundreds times slowest than the SDL's one). So I've not added the alpha support. I suppose new QNX 6.3 will have the hardware alpha support, so when it will be done, I'll add alpha support.
slouken@0
     1
slouken@0
     2
/* Simple program -- figure out what kind of video display we have */
slouken@0
     3
slouken@479
     4
#include <stdlib.h>
slouken@0
     5
#include <stdio.h>
slouken@0
     6
#include <stdlib.h>
slouken@524
     7
#include <string.h>
slouken@0
     8
slouken@0
     9
#include "SDL.h"
slouken@0
    10
slouken@480
    11
#define NUM_BLITS	10
slouken@480
    12
#define NUM_UPDATES	500
slouken@480
    13
slouken@479
    14
#define FLAG_MASK	(SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF)
slouken@479
    15
slouken@479
    16
void PrintFlags(Uint32 flags)
slouken@479
    17
{
slouken@479
    18
	printf("0x%8.8x", (flags & FLAG_MASK));
slouken@479
    19
	if ( flags & SDL_HWSURFACE ) {
slouken@479
    20
		printf(" SDL_HWSURFACE");
slouken@479
    21
	} else {
slouken@479
    22
		printf(" SDL_SWSURFACE");
slouken@479
    23
	}
slouken@479
    24
	if ( flags & SDL_FULLSCREEN ) {
slouken@479
    25
		printf(" | SDL_FULLSCREEN");
slouken@479
    26
	}
slouken@479
    27
	if ( flags & SDL_DOUBLEBUF ) {
slouken@479
    28
		printf(" | SDL_DOUBLEBUF");
slouken@479
    29
	}
slouken@821
    30
	if ( flags & SDL_SRCCOLORKEY ) {
slouken@821
    31
		printf(" | SDL_SRCCOLORKEY");
slouken@821
    32
	}
slouken@821
    33
	if ( flags & SDL_RLEACCEL ) {
slouken@821
    34
		printf(" | SDL_RLEACCEL");
slouken@821
    35
	}
slouken@479
    36
}
slouken@479
    37
slouken@479
    38
int RunBlitTests(SDL_Surface *screen, SDL_Surface *bmp, int blitcount)
slouken@479
    39
{
slouken@479
    40
	int i, j;
slouken@479
    41
	int maxx;
slouken@479
    42
	int maxy;
slouken@480
    43
	SDL_Rect dst;
slouken@479
    44
slouken@480
    45
	maxx = (int)screen->w - bmp->w + 1;
slouken@480
    46
	maxy = (int)screen->h - bmp->h + 1;
slouken@480
    47
	for ( i = 0; i < NUM_UPDATES; ++i ) {
slouken@479
    48
		for ( j = 0; j < blitcount; ++j ) {
slouken@479
    49
			if ( maxx ) {
slouken@480
    50
				dst.x = rand() % maxx;
slouken@479
    51
			} else {
slouken@480
    52
				dst.x = 0;
slouken@479
    53
			}
slouken@479
    54
			if ( maxy ) {
slouken@480
    55
				dst.y = rand() % maxy;
slouken@479
    56
			} else {
slouken@480
    57
				dst.y = 0;
slouken@479
    58
			}
slouken@480
    59
			dst.w = bmp->w;
slouken@480
    60
			dst.h = bmp->h;
slouken@480
    61
			SDL_BlitSurface(bmp, NULL, screen, &dst);
slouken@479
    62
		}
slouken@480
    63
		SDL_Flip(screen);
slouken@479
    64
	}
slouken@479
    65
slouken@479
    66
	return i;
slouken@479
    67
}
slouken@479
    68
slouken@480
    69
int RunModeTests(SDL_Surface *screen)
slouken@479
    70
{
slouken@479
    71
	Uint32 then, now;
slouken@479
    72
	Uint32 frames;
slouken@480
    73
	float seconds;
slouken@479
    74
	int i;
slouken@479
    75
	Uint8 r, g, b;
slouken@821
    76
	SDL_Surface *bmp, *bmpcc, *tmp;
slouken@480
    77
	SDL_Event event;
slouken@480
    78
slouken@480
    79
	while ( SDL_PollEvent(&event) ) {
slouken@480
    80
		if ( event.type == SDL_KEYDOWN )
slouken@480
    81
			return 0;
slouken@480
    82
	}
slouken@479
    83
slouken@479
    84
	/* First test fills and screen update speed */
slouken@479
    85
	printf("Running color fill and fullscreen update test\n");
slouken@479
    86
	then = SDL_GetTicks();
slouken@479
    87
	frames = 0;
slouken@479
    88
	for ( i = 0; i < 256; ++i ) {
slouken@479
    89
		r = i;
slouken@479
    90
		g = 0;
slouken@479
    91
		b = 0;
slouken@479
    92
		SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b));
slouken@479
    93
		SDL_Flip(screen);
slouken@479
    94
		++frames;
slouken@479
    95
	}
slouken@479
    96
	for ( i = 0; i < 256; ++i ) {
slouken@479
    97
		r = 0;
slouken@479
    98
		g = i;
slouken@479
    99
		b = 0;
slouken@479
   100
		SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b));
slouken@479
   101
		SDL_Flip(screen);
slouken@479
   102
		++frames;
slouken@479
   103
	}
slouken@479
   104
	for ( i = 0; i < 256; ++i ) {
slouken@479
   105
		r = 0;
slouken@479
   106
		g = 0;
slouken@479
   107
		b = i;
slouken@479
   108
		SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b));
slouken@479
   109
		SDL_Flip(screen);
slouken@479
   110
		++frames;
slouken@479
   111
	}
slouken@479
   112
	now = SDL_GetTicks();
slouken@480
   113
	seconds = (float)(now - then) / 1000.0f;
slouken@480
   114
	if ( seconds > 0.0f ) {
slouken@480
   115
		printf("%d fills and flips in %2.2f seconds, %2.2f FPS\n", frames, seconds, (float)frames / seconds);
slouken@480
   116
	} else {
slouken@480
   117
		printf("%d fills and flips in zero seconds!n", frames);
slouken@480
   118
	}
slouken@480
   119
slouken@480
   120
	while ( SDL_PollEvent(&event) ) {
slouken@480
   121
		if ( event.type == SDL_KEYDOWN )
slouken@480
   122
			return 0;
slouken@480
   123
	}
slouken@479
   124
slouken@821
   125
        /* run the generic blit test */
slouken@479
   126
	bmp = SDL_LoadBMP("sample.bmp");
slouken@479
   127
	if ( ! bmp ) {
slouken@479
   128
		printf("Couldn't load sample.bmp: %s\n", SDL_GetError());
slouken@482
   129
		return 0;
slouken@479
   130
	}
slouken@479
   131
	printf("Running freshly loaded blit test: %dx%d at %d bpp, flags: ",
slouken@479
   132
		bmp->w, bmp->h, bmp->format->BitsPerPixel);
slouken@479
   133
	PrintFlags(bmp->flags);
slouken@479
   134
	printf("\n");
slouken@479
   135
	then = SDL_GetTicks();
slouken@480
   136
	frames = RunBlitTests(screen, bmp, NUM_BLITS);
slouken@479
   137
	now = SDL_GetTicks();
slouken@480
   138
	seconds = (float)(now - then) / 1000.0f;
slouken@480
   139
	if ( seconds > 0.0f ) {
slouken@480
   140
		printf("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds);
slouken@480
   141
	} else {
slouken@480
   142
		printf("%d blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames);
slouken@479
   143
	}
slouken@479
   144
slouken@821
   145
        /* run the colorkeyed blit test */
slouken@821
   146
	bmpcc = SDL_LoadBMP("sample.bmp");
slouken@821
   147
	if ( ! bmpcc ) {
slouken@821
   148
		printf("Couldn't load sample.bmp: %s\n", SDL_GetError());
slouken@821
   149
		return 0;
slouken@821
   150
	}
slouken@821
   151
	printf("Running freshly loaded cc blit test: %dx%d at %d bpp, flags: ",
slouken@821
   152
		bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel);
slouken@821
   153
        SDL_SetColorKey(bmpcc, SDL_SRCCOLORKEY | SDL_RLEACCEL, *(Uint8 *)bmpcc->pixels);
slouken@821
   154
slouken@821
   155
	PrintFlags(bmpcc->flags);
slouken@821
   156
	printf("\n");
slouken@821
   157
	then = SDL_GetTicks();
slouken@821
   158
	frames = RunBlitTests(screen, bmpcc, NUM_BLITS);
slouken@821
   159
	now = SDL_GetTicks();
slouken@821
   160
	seconds = (float)(now - then) / 1000.0f;
slouken@821
   161
	if ( seconds > 0.0f ) {
slouken@821
   162
		printf("%d cc blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds);
slouken@821
   163
	} else {
slouken@821
   164
		printf("%d cc blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames);
slouken@821
   165
	}
slouken@821
   166
slouken@821
   167
        /* run the generic blit test */
slouken@479
   168
	tmp = bmp;
slouken@479
   169
	bmp = SDL_DisplayFormat(bmp);
slouken@479
   170
	SDL_FreeSurface(tmp);
slouken@479
   171
	if ( ! bmp ) {
slouken@479
   172
		printf("Couldn't convert sample.bmp: %s\n", SDL_GetError());
slouken@482
   173
		return 0;
slouken@479
   174
	}
slouken@479
   175
	printf("Running display format blit test: %dx%d at %d bpp, flags: ",
slouken@479
   176
		bmp->w, bmp->h, bmp->format->BitsPerPixel);
slouken@479
   177
	PrintFlags(bmp->flags);
slouken@479
   178
	printf("\n");
slouken@479
   179
	then = SDL_GetTicks();
slouken@480
   180
	frames = RunBlitTests(screen, bmp, NUM_BLITS);
slouken@479
   181
	now = SDL_GetTicks();
slouken@480
   182
	seconds = (float)(now - then) / 1000.0f;
slouken@480
   183
	if ( seconds > 0.0f ) {
slouken@480
   184
		printf("%d blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds);
slouken@480
   185
	} else {
slouken@480
   186
		printf("%d blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames);
slouken@479
   187
	}
slouken@821
   188
slouken@821
   189
        /* run the colorkeyed blit test */
slouken@821
   190
	tmp = bmpcc;
slouken@821
   191
	bmpcc = SDL_DisplayFormat(bmpcc);
slouken@821
   192
	SDL_FreeSurface(tmp);
slouken@821
   193
	if ( ! bmpcc ) {
slouken@821
   194
		printf("Couldn't convert sample.bmp: %s\n", SDL_GetError());
slouken@821
   195
		return 0;
slouken@821
   196
	}
slouken@821
   197
	printf("Running display format cc blit test: %dx%d at %d bpp, flags: ",
slouken@821
   198
		bmpcc->w, bmpcc->h, bmpcc->format->BitsPerPixel);
slouken@821
   199
	PrintFlags(bmpcc->flags);
slouken@821
   200
	printf("\n");
slouken@821
   201
	then = SDL_GetTicks();
slouken@821
   202
	frames = RunBlitTests(screen, bmpcc, NUM_BLITS);
slouken@821
   203
	now = SDL_GetTicks();
slouken@821
   204
	seconds = (float)(now - then) / 1000.0f;
slouken@821
   205
	if ( seconds > 0.0f ) {
slouken@821
   206
		printf("%d cc blits / %d updates in %2.2f seconds, %2.2f FPS\n", NUM_BLITS*frames, frames, seconds, (float)frames / seconds);
slouken@821
   207
	} else {
slouken@821
   208
		printf("%d cc blits / %d updates in zero seconds!\n", NUM_BLITS*frames, frames);
slouken@821
   209
	}
slouken@821
   210
slouken@821
   211
	SDL_FreeSurface(bmpcc);
slouken@479
   212
	SDL_FreeSurface(bmp);
slouken@480
   213
slouken@480
   214
	while ( SDL_PollEvent(&event) ) {
slouken@480
   215
		if ( event.type == SDL_KEYDOWN )
slouken@480
   216
			return 0;
slouken@480
   217
	}
slouken@480
   218
	return 1;
slouken@479
   219
}
slouken@479
   220
slouken@479
   221
void RunVideoTests()
slouken@479
   222
{
slouken@479
   223
	static const struct {
slouken@479
   224
		int w, h, bpp;
slouken@479
   225
	} mode_list[] = {
slouken@479
   226
		{ 640, 480, 8 }, { 640, 480, 16 }, { 640, 480, 32 },
slouken@479
   227
		{ 800, 600, 8 }, { 800, 600, 16 }, { 800, 600, 32 },
slouken@479
   228
		{ 1024, 768, 8 }, { 1024, 768, 16 }, { 1024, 768, 32 }
slouken@479
   229
	};
slouken@479
   230
	static const Uint32 flags[] = {
slouken@479
   231
		(SDL_SWSURFACE),
slouken@479
   232
		(SDL_SWSURFACE | SDL_FULLSCREEN),
slouken@479
   233
		(SDL_HWSURFACE | SDL_FULLSCREEN),
slouken@479
   234
		(SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF)
slouken@479
   235
	};
slouken@479
   236
	int i, j;
slouken@479
   237
	SDL_Surface *screen;
slouken@479
   238
slouken@479
   239
	/* Test out several different video mode combinations */
slouken@480
   240
	SDL_WM_SetCaption("SDL Video Benchmark", "vidtest");
slouken@480
   241
	SDL_ShowCursor(0);
slouken@479
   242
	for ( i = 0; i < SDL_TABLESIZE(mode_list); ++i ) {
slouken@479
   243
		for ( j = 0; j < SDL_TABLESIZE(flags); ++j ) {
slouken@479
   244
			printf("===================================\n");
slouken@479
   245
			printf("Setting video mode: %dx%d at %d bpp, flags: ",
slouken@479
   246
			                          mode_list[i].w,
slouken@479
   247
			                          mode_list[i].h,
slouken@479
   248
			                          mode_list[i].bpp);
slouken@479
   249
			PrintFlags(flags[j]);
slouken@479
   250
			printf("\n");
slouken@479
   251
			screen = SDL_SetVideoMode(mode_list[i].w,
slouken@479
   252
			                          mode_list[i].h,
slouken@479
   253
			                          mode_list[i].bpp,
slouken@479
   254
			                          flags[j]);
slouken@479
   255
			if ( ! screen ) {
slouken@479
   256
				printf("Setting video mode failed: %s\n", SDL_GetError());
slouken@479
   257
				continue;
slouken@479
   258
			}
slouken@479
   259
			if ( (screen->flags & FLAG_MASK) != flags[j] ) {
slouken@479
   260
				printf("Flags didn't match: ");
slouken@479
   261
				PrintFlags(screen->flags);
slouken@479
   262
				printf("\n");
slouken@479
   263
				continue;
slouken@479
   264
			}
slouken@480
   265
			if ( ! RunModeTests(screen) ) {
slouken@480
   266
				return;
slouken@480
   267
			}
slouken@479
   268
		}
slouken@479
   269
	}
slouken@479
   270
}
slouken@479
   271
slouken@0
   272
int main(int argc, char *argv[])
slouken@0
   273
{
slouken@0
   274
	const SDL_VideoInfo *info;
slouken@0
   275
	int i;
slouken@0
   276
	SDL_Rect **modes;
slouken@480
   277
	char driver[128];
slouken@0
   278
slouken@0
   279
	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
slouken@0
   280
		fprintf(stderr,
slouken@0
   281
			"Couldn't initialize SDL: %s\n", SDL_GetError());
slouken@0
   282
		exit(1);
slouken@0
   283
	}
slouken@480
   284
	if ( SDL_VideoDriverName(driver, sizeof(driver)) ) {
slouken@480
   285
		printf("Video driver: %s\n", driver);
slouken@480
   286
	}
slouken@0
   287
	info = SDL_GetVideoInfo();
slouken@0
   288
	printf(
slouken@0
   289
"Current display: %d bits-per-pixel\n",info->vfmt->BitsPerPixel);
slouken@0
   290
	if ( info->vfmt->palette == NULL ) {
slouken@0
   291
		printf("	Red Mask = 0x%.8x\n", info->vfmt->Rmask);
slouken@0
   292
		printf("	Green Mask = 0x%.8x\n", info->vfmt->Gmask);
slouken@0
   293
		printf("	Blue Mask = 0x%.8x\n", info->vfmt->Bmask);
slouken@0
   294
	}
slouken@0
   295
	/* Print available fullscreen video modes */
slouken@0
   296
	modes = SDL_ListModes(NULL, SDL_FULLSCREEN);
slouken@0
   297
	if ( modes == (SDL_Rect **)0 ) {
slouken@0
   298
		printf("No available fullscreen video modes\n");
slouken@0
   299
	} else
slouken@0
   300
	if ( modes == (SDL_Rect **)-1 ) {
slouken@0
   301
		printf("No special fullscreen video modes\n");
slouken@0
   302
	} else {
slouken@0
   303
		printf("Fullscreen video modes:\n");
slouken@0
   304
		for ( i=0; modes[i]; ++i ) {
slouken@266
   305
			printf("\t%dx%dx%d\n", modes[i]->w, modes[i]->h, info->vfmt->BitsPerPixel);
slouken@0
   306
		}
slouken@0
   307
	}
slouken@0
   308
	if ( info->wm_available ) {
slouken@0
   309
		printf("A window manager is available\n");
slouken@0
   310
	}
slouken@0
   311
	if ( info->hw_available ) {
slouken@0
   312
		printf("Hardware surfaces are available (%dK video memory)\n",
slouken@0
   313
			info->video_mem);
slouken@0
   314
	}
slouken@0
   315
	if ( info->blit_hw ) {
slouken@0
   316
		printf(
slouken@0
   317
"Copy blits between hardware surfaces are accelerated\n");
slouken@0
   318
	}
slouken@0
   319
	if ( info->blit_hw_CC ) {
slouken@0
   320
		printf(
slouken@0
   321
"Colorkey blits between hardware surfaces are accelerated\n");
slouken@0
   322
	}
slouken@0
   323
	if ( info->blit_hw_A ) {
slouken@0
   324
		printf(
slouken@0
   325
"Alpha blits between hardware surfaces are accelerated\n");
slouken@0
   326
	}
slouken@0
   327
	if ( info->blit_sw ) {
slouken@0
   328
		printf(
slouken@0
   329
"Copy blits from software surfaces to hardware surfaces are accelerated\n");
slouken@0
   330
	}
slouken@0
   331
	if ( info->blit_sw_CC ) {
slouken@0
   332
		printf(
slouken@0
   333
"Colorkey blits from software surfaces to hardware surfaces are accelerated\n");
slouken@0
   334
	}
slouken@0
   335
	if ( info->blit_sw_A ) {
slouken@0
   336
		printf(
slouken@0
   337
"Alpha blits from software surfaces to hardware surfaces are accelerated\n");
slouken@0
   338
	}
slouken@0
   339
	if ( info->blit_fill ) {
slouken@0
   340
		printf(
slouken@0
   341
"Color fills on hardware surfaces are accelerated\n");
slouken@0
   342
	}
slouken@479
   343
slouken@479
   344
	if ( argv[1] && (strcmp(argv[1], "-benchmark") == 0) ) {
slouken@479
   345
		RunVideoTests();
slouken@479
   346
	}
slouken@479
   347
slouken@0
   348
	SDL_Quit();
slouken@0
   349
	return(0);
slouken@0
   350
}