aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2017-04-12 09:04:35 +0200
committerGerd Hoffmann <kraxel@redhat.com>2017-04-12 09:04:35 +0200
commitd77ea2edc9cb9ea1e910c2455cadc39a8875e4ea (patch)
tree5372d69c1d6bdcb1707d82d5bc6ec1858d995754
parentf6b5f814f0a8cc97aff65a9a4981d7874af2d3e4 (diff)
downloaddrminfo-d77ea2edc9cb9ea1e910c2455cadc39a8875e4ea.tar.gz
add support for picking output
-rw-r--r--drminfo.c8
-rw-r--r--drmtest.c48
-rw-r--r--drmtools.c13
-rw-r--r--drmtools.h1
4 files changed, 60 insertions, 10 deletions
diff --git a/drminfo.c b/drminfo.c
index 471267e..97ab8da 100644
--- a/drminfo.c
+++ b/drminfo.c
@@ -23,6 +23,7 @@ static void drm_info(int devnr)
drmModeCrtc *crtc;
drmModeRes *res;
char dev[64], *busid;
+ char name[64];
int fd, i, m, c, e;
snprintf(dev, sizeof(dev), DRM_DEV_NAME, DRM_DIR_NAME, devnr);
@@ -49,10 +50,9 @@ static void drm_info(int devnr)
if (!conn)
continue;
- fprintf(stdout, "%s-%d, %s\n",
- drm_connector_type_name(conn->connector_type),
- conn->connector_type_id,
- drm_connector_mode_name(conn->connection));
+ drm_conn_name(conn, name, sizeof(name));
+ fprintf(stdout, "%s, %s\n",
+ name, drm_connector_mode_name(conn->connection));
for (e = 0; e < conn->count_encoders; e++) {
enc = drmModeGetEncoder(fd, conn->encoders[e]);
diff --git a/drmtest.c b/drmtest.c
index 1404df0..88c85be 100644
--- a/drmtest.c
+++ b/drmtest.c
@@ -18,6 +18,8 @@
#include <epoxy/gl.h>
#include <epoxy/egl.h>
+#include "drmtools.h"
+
/* ------------------------------------------------------------------ */
/* device */
@@ -42,10 +44,12 @@ static EGLSurface surface;
/* ------------------------------------------------------------------ */
-static void drm_init_dev(int devnr, bool need_dumb, bool need_master)
+static void drm_init_dev(int devnr, const char *output,
+ bool need_dumb, bool need_master)
{
drmModeRes *res;
char dev[64];
+ char name[64];
int i, rc;
uint64_t has_dumb;
@@ -66,13 +70,13 @@ static void drm_init_dev(int devnr, bool need_dumb, bool need_master)
}
if (need_master) {
rc = drmSetMaster(fd);
- if (rc < 0 || !has_dumb) {
+ if (rc < 0) {
fprintf(stderr, "drmSetMaster() failed, X11 running?\n");
exit(1);
}
}
- /* find connector (using first for now) */
+ /* find connector */
res = drmModeGetResources(fd);
if (res == NULL) {
fprintf(stderr, "drmModeGetResources() failed\n");
@@ -82,6 +86,33 @@ static void drm_init_dev(int devnr, bool need_dumb, bool need_master)
conn = drmModeGetConnector(fd, res->connectors[i]);
if (conn &&
(conn->connection == DRM_MODE_CONNECTED) &&
+ conn->count_modes) {
+ if (output) {
+ drm_conn_name(conn, name, sizeof(name));
+ if (strcmp(name, output) == 0) {
+ break;
+ }
+ } else {
+ break;
+ }
+ }
+ drmModeFreeConnector(conn);
+ conn = NULL;
+ }
+ if (!conn) {
+ if (output) {
+ fprintf(stderr, "drm: output %s not found or disconnected\n",
+ output);
+ } else {
+ fprintf(stderr, "drm: no usable output found\n");
+ }
+ exit(1);
+ }
+
+ for (i = 0; i < res->count_connectors; i++) {
+ conn = drmModeGetConnector(fd, res->connectors[i]);
+ if (conn &&
+ (conn->connection == DRM_MODE_CONNECTED) &&
conn->count_modes)
break;
drmModeFreeConnector(conn);
@@ -309,6 +340,7 @@ static void usage(FILE *fp)
"options:\n"
" -h print this\n"
" -c <nr> pick card\n"
+ " -o <name> pick output\n"
" -g openngl mode\n"
#if 0
" -d debug mode (opengl)\n"
@@ -320,16 +352,20 @@ int main(int argc, char **argv)
{
int card = 0;
bool gl = false;
+ char *output = NULL;
int c;
for (;;) {
- c = getopt(argc, argv, "hgdc:");
+ c = getopt(argc, argv, "hgdc:o:");
if (c == -1)
break;
switch (c) {
case 'c':
card = atoi(optarg);
break;
+ case 'o':
+ output = optarg;
+ break;
case 'g':
gl = true;
break;
@@ -349,12 +385,12 @@ int main(int argc, char **argv)
}
if (gl) {
- drm_init_dev(card, true, true);
+ drm_init_dev(card, output, true, true);
drm_init_egl();
drm_draw_egl();
drm_make_egl_fb();
} else {
- drm_init_dev(card, false, true);
+ drm_init_dev(card, output, false, true);
drm_init_dumb_fb();
drm_draw_dumb_fb();
}
diff --git a/drmtools.c b/drmtools.c
index 0d4d62b..8ff054b 100644
--- a/drmtools.c
+++ b/drmtools.c
@@ -77,5 +77,18 @@ const char *drm_encoder_type_name(int nr)
return enum2name(enc_type, sizeof(enc_type)/sizeof(enc_type[0]), nr);
}
+void drm_conn_name(drmModeConnector *conn, char *dest, int dlen)
+{
+ const char *type;
+
+ if (conn->connector_type_id < sizeof(conn_type)/sizeof(conn_type[0]) &&
+ conn_type[conn->connector_type]) {
+ type = conn_type[conn->connector_type];
+ } else {
+ type = "unknown";
+ }
+ snprintf(dest, dlen, "%s-%d", type, conn->connector_type_id);
+}
+
/* ------------------------------------------------------------------ */
diff --git a/drmtools.h b/drmtools.h
index 910f83d..ed43544 100644
--- a/drmtools.h
+++ b/drmtools.h
@@ -1,3 +1,4 @@
const char *drm_connector_type_name(int nr);
const char *drm_connector_mode_name(int nr);
const char *drm_encoder_type_name(int nr);
+void drm_conn_name(drmModeConnector *conn, char *dest, int dlen);