| 1 |
/* |
| 2 |
Copyright (C) 1997-2026 Sam Lantinga <[email protected]> |
| 3 |
|
| 4 |
This software is provided 'as-is', without any express or implied |
| 5 |
warranty. In no event will the authors be held liable for any damages |
| 6 |
arising from the use of this software. |
| 7 |
|
| 8 |
Permission is granted to anyone to use this software for any purpose, |
| 9 |
including commercial applications, and to alter it and redistribute it |
| 10 |
freely. |
| 11 |
*/ |
| 12 |
|
| 13 |
/* Program to test querying of display info */ |
| 14 |
|
| 15 |
#include "SDL.h" |
| 16 |
#include "SDL_test.h" |
| 17 |
|
| 18 |
#include <stdio.h> |
| 19 |
#include <stdlib.h> |
| 20 |
|
| 21 |
static void |
| 22 |
print_mode(const char *prefix, const SDL_DisplayMode *mode) |
| 23 |
{ |
| 24 |
if (!mode) { |
| 25 |
return; |
| 26 |
} |
| 27 |
|
| 28 |
SDL_Log("%s: fmt=%s w=%d h=%d refresh=%d\n", |
| 29 |
prefix, SDL_GetPixelFormatName(mode->format), |
| 30 |
mode->w, mode->h, mode->refresh_rate); |
| 31 |
} |
| 32 |
|
| 33 |
int main(int argc, char *argv[]) |
| 34 |
{ |
| 35 |
SDL_DisplayMode mode; |
| 36 |
int num_displays, dpy; |
| 37 |
SDLTest_CommonState *state; |
| 38 |
|
| 39 |
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO); |
| 40 |
if (!state) { |
| 41 |
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError()); |
| 42 |
return 1; |
| 43 |
} |
| 44 |
|
| 45 |
/* Enable standard application logging */ |
| 46 |
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); |
| 47 |
|
| 48 |
if (!SDLTest_CommonDefaultArgs(state, argc, argv)) { |
| 49 |
return 1; |
| 50 |
} |
| 51 |
|
| 52 |
if (!SDLTest_CommonInit(state)) { |
| 53 |
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); |
| 54 |
return 1; |
| 55 |
} |
| 56 |
|
| 57 |
SDL_Log("Using video target '%s'.\n", SDL_GetCurrentVideoDriver()); |
| 58 |
num_displays = SDL_GetNumVideoDisplays(); |
| 59 |
|
| 60 |
SDL_Log("See %d displays.\n", num_displays); |
| 61 |
|
| 62 |
for (dpy = 0; dpy < num_displays; dpy++) { |
| 63 |
const int num_modes = SDL_GetNumDisplayModes(dpy); |
| 64 |
SDL_Rect rect = { 0, 0, 0, 0 }; |
| 65 |
float ddpi, hdpi, vdpi; |
| 66 |
int m; |
| 67 |
|
| 68 |
SDL_GetDisplayBounds(dpy, &rect); |
| 69 |
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); |
| 70 |
|
| 71 |
if (SDL_GetDisplayDPI(dpy, &ddpi, &hdpi, &vdpi) == -1) { |
| 72 |
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " DPI: failed to query (%s)\n", SDL_GetError()); |
| 73 |
} else { |
| 74 |
SDL_Log(" DPI: ddpi=%f; hdpi=%f; vdpi=%f\n", ddpi, hdpi, vdpi); |
| 75 |
} |
| 76 |
|
| 77 |
if (SDL_GetCurrentDisplayMode(dpy, &mode) == -1) { |
| 78 |
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " CURRENT: failed to query (%s)\n", SDL_GetError()); |
| 79 |
} else { |
| 80 |
print_mode("CURRENT", &mode); |
| 81 |
} |
| 82 |
|
| 83 |
if (SDL_GetDesktopDisplayMode(dpy, &mode) == -1) { |
| 84 |
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " DESKTOP: failed to query (%s)\n", SDL_GetError()); |
| 85 |
} else { |
| 86 |
print_mode("DESKTOP", &mode); |
| 87 |
} |
| 88 |
|
| 89 |
for (m = 0; m < num_modes; m++) { |
| 90 |
if (SDL_GetDisplayMode(dpy, m, &mode) == -1) { |
| 91 |
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " MODE %d: failed to query (%s)\n", m, SDL_GetError()); |
| 92 |
} else { |
| 93 |
char prefix[64]; |
| 94 |
(void)SDL_snprintf(prefix, sizeof(prefix), " MODE %d", m); |
| 95 |
print_mode(prefix, &mode); |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
SDL_Log("\n"); |
| 100 |
} |
| 101 |
|
| 102 |
SDLTest_CommonQuit(state); |
| 103 |
return 0; |
| 104 |
} |
| 105 |
|
| 106 |
/* vi: set ts=4 sw=4 expandtab: */ |
| 107 |
|