test/testdisplayinfo.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 07 Dec 2017 16:08:09 -0800
changeset 11730 ac6c607e065c
parent 10737 3406a0f8b041
child 11811 5d94cb6b24d3
permissions -rw-r--r--
Enable building the Metal renderer by default, and weak link the Metal framework so the SDL library is safe to use on older Macs
Also generate iOS versions of the Metal shaders
icculus@9800
     1
/*
slouken@10737
     2
  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
icculus@9800
     3
icculus@9800
     4
  This software is provided 'as-is', without any express or implied
icculus@9800
     5
  warranty.  In no event will the authors be held liable for any damages
icculus@9800
     6
  arising from the use of this software.
icculus@9800
     7
icculus@9800
     8
  Permission is granted to anyone to use this software for any purpose,
icculus@9800
     9
  including commercial applications, and to alter it and redistribute it
icculus@9800
    10
  freely.
icculus@9800
    11
*/
icculus@9800
    12
philipp@9802
    13
/* Program to test querying of display info */
icculus@9800
    14
icculus@9800
    15
#include "SDL.h"
icculus@9800
    16
icculus@9800
    17
#include <stdio.h>
icculus@9800
    18
#include <stdlib.h>
icculus@9800
    19
icculus@9800
    20
static void
icculus@9800
    21
print_mode(const char *prefix, const SDL_DisplayMode *mode)
icculus@9800
    22
{
icculus@9800
    23
    if (!mode)
icculus@9800
    24
        return;
icculus@9800
    25
icculus@9800
    26
    SDL_Log("%s: fmt=%s w=%d h=%d refresh=%d\n",
icculus@9800
    27
            prefix, SDL_GetPixelFormatName(mode->format),
icculus@9800
    28
            mode->w, mode->h, mode->refresh_rate);
icculus@9800
    29
}
icculus@9800
    30
icculus@9800
    31
int
icculus@9800
    32
main(int argc, char *argv[])
icculus@9800
    33
{
icculus@9800
    34
    SDL_DisplayMode mode;
icculus@9800
    35
    int num_displays, dpy;
icculus@9800
    36
philipp@9922
    37
    /* Enable standard application logging */
philipp@9922
    38
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
icculus@9800
    39
icculus@9800
    40
    /* Load the SDL library */
icculus@9800
    41
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
icculus@9800
    42
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
icculus@9800
    43
        return 1;
icculus@9800
    44
    }
icculus@9800
    45
icculus@9800
    46
    SDL_Log("Using video target '%s'.\n", SDL_GetCurrentVideoDriver());
icculus@9800
    47
    num_displays = SDL_GetNumVideoDisplays();
icculus@9800
    48
icculus@9800
    49
    SDL_Log("See %d displays.\n", num_displays);
icculus@9800
    50
icculus@9800
    51
    for (dpy = 0; dpy < num_displays; dpy++) {
icculus@9800
    52
        const int num_modes = SDL_GetNumDisplayModes(dpy);
icculus@9800
    53
        SDL_Rect rect = { 0, 0, 0, 0 };
icculus@10038
    54
        float ddpi, hdpi, vdpi;
icculus@9800
    55
        int m;
icculus@9800
    56
icculus@9800
    57
        SDL_GetDisplayBounds(dpy, &rect);
icculus@9800
    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);
icculus@9800
    59
icculus@10038
    60
        if (SDL_GetDisplayDPI(dpy, &ddpi, &hdpi, &vdpi) == -1) {
icculus@10038
    61
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    DPI: failed to query (%s)\n", SDL_GetError());
icculus@10038
    62
        } else {
icculus@10038
    63
            SDL_Log("    DPI: ddpi=%f; hdpi=%f; vdpi=%f\n", ddpi, hdpi, vdpi);
icculus@10038
    64
        }
icculus@10038
    65
icculus@9800
    66
        if (SDL_GetCurrentDisplayMode(dpy, &mode) == -1) {
icculus@9800
    67
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    CURRENT: failed to query (%s)\n", SDL_GetError());
icculus@9800
    68
        } else {
icculus@9800
    69
            print_mode("CURRENT", &mode);
icculus@9800
    70
        }
icculus@9800
    71
icculus@9800
    72
        if (SDL_GetDesktopDisplayMode(dpy, &mode) == -1) {
icculus@9800
    73
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    DESKTOP: failed to query (%s)\n", SDL_GetError());
icculus@9800
    74
        } else {
icculus@9800
    75
            print_mode("DESKTOP", &mode);
icculus@9800
    76
        }
icculus@9800
    77
icculus@9800
    78
        for (m = 0; m < num_modes; m++) {
icculus@9800
    79
            if (SDL_GetDisplayMode(dpy, m, &mode) == -1) {
icculus@9800
    80
                SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    MODE %d: failed to query (%s)\n", m, SDL_GetError());
icculus@9800
    81
            } else {
icculus@9800
    82
                char prefix[64];
icculus@9800
    83
                SDL_snprintf(prefix, sizeof (prefix), "    MODE %d", m);
icculus@9800
    84
                print_mode(prefix, &mode);
icculus@9800
    85
            }
icculus@9800
    86
        }
icculus@9800
    87
icculus@9800
    88
        SDL_Log("\n");
icculus@9800
    89
    }
icculus@9800
    90
icculus@9833
    91
    SDL_Quit();
icculus@9800
    92
    return 0;
icculus@9800
    93
}
icculus@9800
    94
icculus@9800
    95
/* vi: set ts=4 sw=4 expandtab: */
icculus@9800
    96