test/testdisplayinfo.c
author Ryan C. Gordon <icculus@icculus.org>
Tue, 14 Jul 2015 21:28:26 -0400
changeset 9800 978b538d177e
child 9802 387821246318
permissions -rw-r--r--
Added test/testdisplayinfo.c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9800
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
  Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
  This software is provided 'as-is', without any express or implied
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
  warranty.  In no event will the authors be held liable for any damages
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
  arising from the use of this software.
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
  Permission is granted to anyone to use this software for any purpose,
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
  including commercial applications, and to alter it and redistribute it
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
  freely.
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
*/
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
/* Program to test hotplugging of audio devices */
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
#include "SDL.h"
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
#include <stdio.h>
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
#include <stdlib.h>
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
static void
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
print_mode(const char *prefix, const SDL_DisplayMode *mode)
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
{
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
    if (!mode)
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
        return;
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
    SDL_Log("%s: fmt=%s w=%d h=%d refresh=%d\n",
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
            prefix, SDL_GetPixelFormatName(mode->format),
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
            mode->w, mode->h, mode->refresh_rate);
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
}
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
int
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
main(int argc, char *argv[])
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
{
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
    SDL_DisplayMode mode;
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
    int num_displays, dpy;
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
	/* Enable standard application logging */
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
	SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
    /* Load the SDL library */
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
        return 1;
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
    }
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
    SDL_Log("Using video target '%s'.\n", SDL_GetCurrentVideoDriver());
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
    num_displays = SDL_GetNumVideoDisplays();
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
    SDL_Log("See %d displays.\n", num_displays);
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
    for (dpy = 0; dpy < num_displays; dpy++) {
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
        const int num_modes = SDL_GetNumDisplayModes(dpy);
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
        SDL_Rect rect = { 0, 0, 0, 0 };
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
        int m;
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
        SDL_GetDisplayBounds(dpy, &rect);
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
        SDL_Log("%d: \"%s\" (%dx%d, (%d, %d)), %d modes.\n", dpy, SDL_GetDisplayName(dpy), rect.w, rect.h, rect.x, rect.y, num_modes);
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
        if (SDL_GetCurrentDisplayMode(dpy, &mode) == -1) {
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    CURRENT: failed to query (%s)\n", SDL_GetError());
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
        } else {
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
            print_mode("CURRENT", &mode);
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
        }
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
        if (SDL_GetDesktopDisplayMode(dpy, &mode) == -1) {
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    DESKTOP: failed to query (%s)\n", SDL_GetError());
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
        } else {
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
            print_mode("DESKTOP", &mode);
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
        }
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
        for (m = 0; m < num_modes; m++) {
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
            if (SDL_GetDisplayMode(dpy, m, &mode) == -1) {
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
                SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    MODE %d: failed to query (%s)\n", m, SDL_GetError());
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
            } else {
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
                char prefix[64];
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
                SDL_snprintf(prefix, sizeof (prefix), "    MODE %d", m);
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
                print_mode(prefix, &mode);
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
            }
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
        }
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
        SDL_Log("\n");
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
    }
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
    return 0;
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
}
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
/* vi: set ts=4 sw=4 expandtab: */
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88