test/testvidinfo.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 03 Jun 2011 16:03:10 -0400
changeset 5547 4ccecd0901e2
parent 5535 96594ac5fd1a
permissions -rw-r--r--
Assert code's stdio interface was reading from the wrong variable.

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