Atlas - testdisplayinfo.c
Home / ext / SDL / test Lines: 1 | Size: 3167 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* 2 Copyright (C) 1997-2025 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 <stdlib.h> 16 17#include <SDL3/SDL.h> 18#include <SDL3/SDL_main.h> 19#include <SDL3/SDL_test.h> 20 21static void 22print_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", 29 prefix, 30 mode->w, mode->h, mode->pixel_density, mode->refresh_rate, 31 SDL_GetPixelFormatName(mode->format)); 32} 33 34int 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 /* Parse commandline */ 49 if (!SDLTest_CommonDefaultArgs(state, argc, argv)) { 50 return 1; 51 } 52 53 /* Load the SDL library */ 54 if (!SDL_Init(SDL_INIT_VIDEO)) { 55 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s", SDL_GetError()); 56 return 1; 57 } 58 59 SDL_Log("Using video target '%s'.", SDL_GetCurrentVideoDriver()); 60 displays = SDL_GetDisplays(&num_displays); 61 62 SDL_Log("See %d displays.", num_displays); 63 64 for (i = 0; i < num_displays; i++) { 65 SDL_DisplayID dpy = displays[i]; 66 SDL_PropertiesID props = SDL_GetDisplayProperties(dpy); 67 SDL_Rect rect = { 0, 0, 0, 0 }; 68 int m, num_modes = 0; 69 const bool has_HDR = SDL_GetBooleanProperty(props, SDL_PROP_DISPLAY_HDR_ENABLED_BOOLEAN, false); 70 71 SDL_GetDisplayBounds(dpy, &rect); 72 modes = SDL_GetFullscreenDisplayModes(dpy, &num_modes); 73 SDL_Log("%" SDL_PRIu32 ": \"%s\" (%dx%d at %d,%d), content scale %.2f, %d fullscreen modes, HDR capable: %s.", dpy, SDL_GetDisplayName(dpy), rect.w, rect.h, rect.x, rect.y, SDL_GetDisplayContentScale(dpy), num_modes, has_HDR ? "yes" : "no"); 74 75 mode = SDL_GetCurrentDisplayMode(dpy); 76 if (mode) { 77 print_mode("CURRENT", mode); 78 } else { 79 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " CURRENT: failed to query (%s)", SDL_GetError()); 80 } 81 82 mode = SDL_GetDesktopDisplayMode(dpy); 83 if (mode) { 84 print_mode("DESKTOP", mode); 85 } else { 86 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " DESKTOP: failed to query (%s)", SDL_GetError()); 87 } 88 89 for (m = 0; m < num_modes; m++) { 90 char prefix[64]; 91 (void)SDL_snprintf(prefix, sizeof(prefix), " MODE %d", m); 92 print_mode(prefix, modes[m]); 93 } 94 SDL_free(modes); 95 96 SDL_Log("%s", ""); 97 } 98 SDL_free(displays); 99 100 SDL_Quit(); 101 SDLTest_CommonDestroyState(state); 102 return 0; 103} 104[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.