SDL

Форк
0
/
testdisplayinfo.c 
106 строк · 3.2 Кб
1
/*
2
  Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
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 <stdlib.h>
16

17
#include <SDL3/SDL.h>
18
#include <SDL3/SDL_main.h>
19
#include <SDL3/SDL_test.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: %dx%d@%gx, %gHz, fmt=%s\n",
29
            prefix,
30
            mode->w, mode->h, mode->pixel_density, mode->refresh_rate,
31
            SDL_GetPixelFormatName(mode->format));
32
}
33

34
int main(int argc, char *argv[])
35
{
36
    SDL_DisplayID *displays;
37
    SDL_DisplayMode **modes;
38
    const SDL_DisplayMode *mode;
39
    int num_displays, i;
40
    SDLTest_CommonState *state;
41

42
    /* Initialize test framework */
43
    state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
44
    if (!state) {
45
        return 1;
46
    }
47

48
    /* Enable standard application logging */
49
    SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
50

51
    /* Parse commandline */
52
    if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
53
        return 1;
54
    }
55

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());
59
        return 1;
60
    }
61

62
    SDL_Log("Using video target '%s'.\n", SDL_GetCurrentVideoDriver());
63
    displays = SDL_GetDisplays(&num_displays);
64

65
    SDL_Log("See %d displays.\n", num_displays);
66

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 };
71
        int m, num_modes = 0;
72
        const SDL_bool has_HDR = SDL_GetBooleanProperty(props, SDL_PROP_DISPLAY_HDR_ENABLED_BOOLEAN, SDL_FALSE);
73

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");
77

78
        mode = SDL_GetCurrentDisplayMode(dpy);
79
        if (mode) {
80
            print_mode("CURRENT", mode);
81
        } else {
82
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    CURRENT: failed to query (%s)\n", SDL_GetError());
83
        }
84

85
        mode = SDL_GetDesktopDisplayMode(dpy);
86
        if (mode) {
87
            print_mode("DESKTOP", mode);
88
        } else {
89
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    DESKTOP: failed to query (%s)\n", SDL_GetError());
90
        }
91

92
        for (m = 0; m < num_modes; m++) {
93
            char prefix[64];
94
            (void)SDL_snprintf(prefix, sizeof(prefix), "    MODE %d", m);
95
            print_mode(prefix, modes[m]);
96
        }
97
        SDL_free(modes);
98

99
        SDL_Log("\n");
100
    }
101
    SDL_free(displays);
102

103
    SDL_Quit();
104
    SDLTest_CommonDestroyState(state);
105
    return 0;
106
}
107

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.