From d77ea2edc9cb9ea1e910c2455cadc39a8875e4ea Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Wed, 12 Apr 2017 09:04:35 +0200 Subject: add support for picking output --- drminfo.c | 8 ++++---- drmtest.c | 48 ++++++++++++++++++++++++++++++++++++++++++------ drmtools.c | 13 +++++++++++++ drmtools.h | 1 + 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 #include +#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,18 +70,45 @@ 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"); 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) { + 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 && @@ -309,6 +340,7 @@ static void usage(FILE *fp) "options:\n" " -h print this\n" " -c pick card\n" + " -o 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); -- cgit