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