[Commits] SDL: Added test/testdisplayinfo.c

libsdl.org revision control commits-owner at libsdl.org
Tue Jul 14 20:11:20 PDT 2015


details:   https://hg.libsdl.org/SDL/rev/978b538d177e
changeset: 9800:978b538d177e
user:      Ryan C. Gordon <icculus at icculus.org>
date:      Tue Jul 14 21:28:26 2015 -0400
description:
Added test/testdisplayinfo.c

diffstat:

 .hgignore              |   1 +
 test/Makefile.in       |   4 ++
 test/testdisplayinfo.c |  88 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 93 insertions(+), 0 deletions(-)

diffs (124 lines):

diff -r d1e20d38e5f5 -r 978b538d177e .hgignore
--- a/.hgignore	Sat Jul 11 00:59:56 2015 -0400
+++ b/.hgignore	Tue Jul 14 21:28:26 2015 -0400
@@ -117,6 +117,7 @@
 test/testviewport
 test/testwm2
 test/torturethread
+test/testdisplayinfo
 test/*.exe
 test/*.dSYM
 buildbot
diff -r d1e20d38e5f5 -r 978b538d177e test/Makefile.in
--- a/test/Makefile.in	Sat Jul 11 00:59:56 2015 -0400
+++ b/test/Makefile.in	Tue Jul 14 21:28:26 2015 -0400
@@ -60,6 +60,7 @@
 	torturethread$(EXE) \
 	testrendercopyex$(EXE) \
 	testmessage$(EXE) \
+	testdisplayinfo$(EXE) \
 	controllermap$(EXE) \
 	
 all: Makefile $(TARGETS)
@@ -266,6 +267,9 @@
 testmessage$(EXE): $(srcdir)/testmessage.c
 	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
 
+testdisplayinfo$(EXE): $(srcdir)/testdisplayinfo.c
+	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
+
 controllermap$(EXE): $(srcdir)/controllermap.c
 	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
 
diff -r d1e20d38e5f5 -r 978b538d177e test/testdisplayinfo.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/testdisplayinfo.c	Tue Jul 14 21:28:26 2015 -0400
@@ -0,0 +1,88 @@
+/*
+  Copyright (C) 1997-2015 Sam Lantinga <slouken at libsdl.org>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely.
+*/
+
+/* Program to test hotplugging of audio devices */
+
+#include "SDL.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+static void
+print_mode(const char *prefix, const SDL_DisplayMode *mode)
+{
+    if (!mode)
+        return;
+
+    SDL_Log("%s: fmt=%s w=%d h=%d refresh=%d\n",
+            prefix, SDL_GetPixelFormatName(mode->format),
+            mode->w, mode->h, mode->refresh_rate);
+}
+
+int
+main(int argc, char *argv[])
+{
+    SDL_DisplayMode mode;
+    int num_displays, dpy;
+
+	/* Enable standard application logging */
+	SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
+
+    /* Load the SDL library */
+    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
+        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
+        return 1;
+    }
+
+    SDL_Log("Using video target '%s'.\n", SDL_GetCurrentVideoDriver());
+    num_displays = SDL_GetNumVideoDisplays();
+
+    SDL_Log("See %d displays.\n", num_displays);
+
+    for (dpy = 0; dpy < num_displays; dpy++) {
+        const int num_modes = SDL_GetNumDisplayModes(dpy);
+        SDL_Rect rect = { 0, 0, 0, 0 };
+        int m;
+
+        SDL_GetDisplayBounds(dpy, &rect);
+        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);
+
+        if (SDL_GetCurrentDisplayMode(dpy, &mode) == -1) {
+            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    CURRENT: failed to query (%s)\n", SDL_GetError());
+        } else {
+            print_mode("CURRENT", &mode);
+        }
+
+        if (SDL_GetDesktopDisplayMode(dpy, &mode) == -1) {
+            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    DESKTOP: failed to query (%s)\n", SDL_GetError());
+        } else {
+            print_mode("DESKTOP", &mode);
+        }
+
+        for (m = 0; m < num_modes; m++) {
+            if (SDL_GetDisplayMode(dpy, m, &mode) == -1) {
+                SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    MODE %d: failed to query (%s)\n", m, SDL_GetError());
+            } else {
+                char prefix[64];
+                SDL_snprintf(prefix, sizeof (prefix), "    MODE %d", m);
+                print_mode(prefix, &mode);
+            }
+        }
+
+        SDL_Log("\n");
+    }
+
+    return 0;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
+


More information about the commits mailing list