2
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
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.
8
Permission is granted to anyone to use this software for any purpose,
9
including commercial applications, and to alter it and redistribute it
13
/* Program to test querying of display info */
18
#include <SDL3/SDL_main.h>
19
#include <SDL3/SDL_test.h>
22
print_mode(const char *prefix, const SDL_DisplayMode *mode)
28
SDL_Log("%s: %dx%d@%gx, %gHz, fmt=%s\n",
30
mode->w, mode->h, mode->pixel_density, mode->refresh_rate,
31
SDL_GetPixelFormatName(mode->format));
34
int main(int argc, char *argv[])
36
SDL_DisplayID *displays;
37
SDL_DisplayMode **modes;
38
const SDL_DisplayMode *mode;
40
SDLTest_CommonState *state;
42
/* Initialize test framework */
43
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
48
/* Enable standard application logging */
49
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
51
/* Parse commandline */
52
if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
56
/* Load the SDL library */
57
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
58
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
62
SDL_Log("Using video target '%s'.\n", SDL_GetCurrentVideoDriver());
63
displays = SDL_GetDisplays(&num_displays);
65
SDL_Log("See %d displays.\n", num_displays);
67
for (i = 0; i < num_displays; i++) {
68
SDL_DisplayID dpy = displays[i];
69
SDL_PropertiesID props = SDL_GetDisplayProperties(dpy);
70
SDL_Rect rect = { 0, 0, 0, 0 };
72
const SDL_bool has_HDR = SDL_GetBooleanProperty(props, SDL_PROP_DISPLAY_HDR_ENABLED_BOOLEAN, SDL_FALSE);
74
SDL_GetDisplayBounds(dpy, &rect);
75
modes = SDL_GetFullscreenDisplayModes(dpy, &num_modes);
76
SDL_Log("%" SDL_PRIu32 ": \"%s\" (%dx%d at %d,%d), content scale %.2f, %d fullscreen modes, HDR capable: %s.\n", dpy, SDL_GetDisplayName(dpy), rect.w, rect.h, rect.x, rect.y, SDL_GetDisplayContentScale(dpy), num_modes, has_HDR ? "yes" : "no");
78
mode = SDL_GetCurrentDisplayMode(dpy);
80
print_mode("CURRENT", mode);
82
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " CURRENT: failed to query (%s)\n", SDL_GetError());
85
mode = SDL_GetDesktopDisplayMode(dpy);
87
print_mode("DESKTOP", mode);
89
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " DESKTOP: failed to query (%s)\n", SDL_GetError());
92
for (m = 0; m < num_modes; m++) {
94
(void)SDL_snprintf(prefix, sizeof(prefix), " MODE %d", m);
95
print_mode(prefix, modes[m]);
104
SDLTest_CommonDestroyState(state);