test/testdisplayinfo.c
changeset 9800 978b538d177e
child 9802 387821246318
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/testdisplayinfo.c	Tue Jul 14 21:28:26 2015 -0400
     1.3 @@ -0,0 +1,88 @@
     1.4 +/*
     1.5 +  Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
     1.6 +
     1.7 +  This software is provided 'as-is', without any express or implied
     1.8 +  warranty.  In no event will the authors be held liable for any damages
     1.9 +  arising from the use of this software.
    1.10 +
    1.11 +  Permission is granted to anyone to use this software for any purpose,
    1.12 +  including commercial applications, and to alter it and redistribute it
    1.13 +  freely.
    1.14 +*/
    1.15 +
    1.16 +/* Program to test hotplugging of audio devices */
    1.17 +
    1.18 +#include "SDL.h"
    1.19 +
    1.20 +#include <stdio.h>
    1.21 +#include <stdlib.h>
    1.22 +
    1.23 +static void
    1.24 +print_mode(const char *prefix, const SDL_DisplayMode *mode)
    1.25 +{
    1.26 +    if (!mode)
    1.27 +        return;
    1.28 +
    1.29 +    SDL_Log("%s: fmt=%s w=%d h=%d refresh=%d\n",
    1.30 +            prefix, SDL_GetPixelFormatName(mode->format),
    1.31 +            mode->w, mode->h, mode->refresh_rate);
    1.32 +}
    1.33 +
    1.34 +int
    1.35 +main(int argc, char *argv[])
    1.36 +{
    1.37 +    SDL_DisplayMode mode;
    1.38 +    int num_displays, dpy;
    1.39 +
    1.40 +	/* Enable standard application logging */
    1.41 +	SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
    1.42 +
    1.43 +    /* Load the SDL library */
    1.44 +    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    1.45 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
    1.46 +        return 1;
    1.47 +    }
    1.48 +
    1.49 +    SDL_Log("Using video target '%s'.\n", SDL_GetCurrentVideoDriver());
    1.50 +    num_displays = SDL_GetNumVideoDisplays();
    1.51 +
    1.52 +    SDL_Log("See %d displays.\n", num_displays);
    1.53 +
    1.54 +    for (dpy = 0; dpy < num_displays; dpy++) {
    1.55 +        const int num_modes = SDL_GetNumDisplayModes(dpy);
    1.56 +        SDL_Rect rect = { 0, 0, 0, 0 };
    1.57 +        int m;
    1.58 +
    1.59 +        SDL_GetDisplayBounds(dpy, &rect);
    1.60 +        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);
    1.61 +
    1.62 +        if (SDL_GetCurrentDisplayMode(dpy, &mode) == -1) {
    1.63 +            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    CURRENT: failed to query (%s)\n", SDL_GetError());
    1.64 +        } else {
    1.65 +            print_mode("CURRENT", &mode);
    1.66 +        }
    1.67 +
    1.68 +        if (SDL_GetDesktopDisplayMode(dpy, &mode) == -1) {
    1.69 +            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    DESKTOP: failed to query (%s)\n", SDL_GetError());
    1.70 +        } else {
    1.71 +            print_mode("DESKTOP", &mode);
    1.72 +        }
    1.73 +
    1.74 +        for (m = 0; m < num_modes; m++) {
    1.75 +            if (SDL_GetDisplayMode(dpy, m, &mode) == -1) {
    1.76 +                SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    MODE %d: failed to query (%s)\n", m, SDL_GetError());
    1.77 +            } else {
    1.78 +                char prefix[64];
    1.79 +                SDL_snprintf(prefix, sizeof (prefix), "    MODE %d", m);
    1.80 +                print_mode(prefix, &mode);
    1.81 +            }
    1.82 +        }
    1.83 +
    1.84 +        SDL_Log("\n");
    1.85 +    }
    1.86 +
    1.87 +    return 0;
    1.88 +}
    1.89 +
    1.90 +/* vi: set ts=4 sw=4 expandtab: */
    1.91 +