test/testdisplayinfo.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Wed, 17 Aug 2016 21:04:50 +0200
changeset 10275 ba7dc3ebb81e
parent 10038 2bab6f8d403e
permissions -rw-r--r--
Emscripten: Fixed opening previously closed joystick.
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
/*
9998
f67cf37e9cd4 Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents: 9922
diff changeset
     2
  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
9800
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
9802
387821246318 Fixed comment in test program.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9800
diff changeset
    13
/* Program to test querying of display info */
9800
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
9922
b066d5fd5fa7 Replaced tabs with spaces in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9833
diff changeset
    37
    /* Enable standard application logging */
b066d5fd5fa7 Replaced tabs with spaces in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9833
diff changeset
    38
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
9800
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 };
10038
2bab6f8d403e Mac: Implemented SDL_GetDisplayDPI (thanks, Kirill!).
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
    54
        float ddpi, hdpi, vdpi;
9800
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
        int m;
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
        SDL_GetDisplayBounds(dpy, &rect);
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
        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
    59
10038
2bab6f8d403e Mac: Implemented SDL_GetDisplayDPI (thanks, Kirill!).
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
    60
        if (SDL_GetDisplayDPI(dpy, &ddpi, &hdpi, &vdpi) == -1) {
2bab6f8d403e Mac: Implemented SDL_GetDisplayDPI (thanks, Kirill!).
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
    61
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    DPI: failed to query (%s)\n", SDL_GetError());
2bab6f8d403e Mac: Implemented SDL_GetDisplayDPI (thanks, Kirill!).
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
    62
        } else {
2bab6f8d403e Mac: Implemented SDL_GetDisplayDPI (thanks, Kirill!).
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
    63
            SDL_Log("    DPI: ddpi=%f; hdpi=%f; vdpi=%f\n", ddpi, hdpi, vdpi);
2bab6f8d403e Mac: Implemented SDL_GetDisplayDPI (thanks, Kirill!).
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
    64
        }
2bab6f8d403e Mac: Implemented SDL_GetDisplayDPI (thanks, Kirill!).
Ryan C. Gordon <icculus@icculus.org>
parents: 9998
diff changeset
    65
9800
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
        if (SDL_GetCurrentDisplayMode(dpy, &mode) == -1) {
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
            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
    68
        } else {
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
            print_mode("CURRENT", &mode);
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
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
        if (SDL_GetDesktopDisplayMode(dpy, &mode) == -1) {
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
            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
    74
        } else {
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
            print_mode("DESKTOP", &mode);
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
        }
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
        for (m = 0; m < num_modes; m++) {
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
            if (SDL_GetDisplayMode(dpy, m, &mode) == -1) {
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
                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
    81
            } else {
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
                char prefix[64];
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
                SDL_snprintf(prefix, sizeof (prefix), "    MODE %d", m);
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
                print_mode(prefix, &mode);
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
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
        SDL_Log("\n");
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
    }
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
9833
c3214bb33a1d testdisplayinfo.c forgot to SDL_Quit() at the end.
Ryan C. Gordon <icculus@icculus.org>
parents: 9802
diff changeset
    91
    SDL_Quit();
9800
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
    return 0;
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
}
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
/* vi: set ts=4 sw=4 expandtab: */
978b538d177e Added test/testdisplayinfo.c
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96