diff options
author | Antonio Borneo <antonio.borneo@st.com> | 2019-02-20 17:48:22 +0100 |
---|---|---|
committer | Antonio Borneo <borneo.antonio@gmail.com> | 2019-07-23 15:11:17 +0200 |
commit | a0a4c0238026b24ac7ace5919132921160673ce2 (patch) | |
tree | 6cadb13be7617d0628797c7769cdb0fae46441d8 | |
parent | a09d38f94e27dcc5fe52adf99404c821028e3e9d (diff) |
kmscube: add command-line selection of video mode
The mode of type "DRM_MODE_TYPE_PREFERED" can be miss-configured,
making kmscube not working.
Plus, user could need to test the other available video modes at
the connector.
Add a command line flag to specify the video mode. If the mode is
not present, print an informative message and fall-back to the
default behaviour (preferred mode or highest resolution mode).
Signed-off-by: Antonio Borneo <antonio.borneo@st.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
-rw-r--r-- | drm-atomic.c | 4 | ||||
-rw-r--r-- | drm-common.c | 40 | ||||
-rw-r--r-- | drm-common.h | 6 | ||||
-rw-r--r-- | drm-legacy.c | 4 | ||||
-rw-r--r-- | kmscube.c | 30 | ||||
-rw-r--r-- | texturator.c | 2 |
6 files changed, 62 insertions, 24 deletions
diff --git a/drm-atomic.c b/drm-atomic.c index 393bf7a..d748772 100644 --- a/drm-atomic.c +++ b/drm-atomic.c @@ -337,12 +337,12 @@ static int get_plane_id(void) return ret; } -const struct drm * init_drm_atomic(const char *device) +const struct drm * init_drm_atomic(const char *device, const char *mode_str, unsigned int vrefresh) { uint32_t plane_id; int ret; - ret = init_drm(&drm, device); + ret = init_drm(&drm, device, mode_str, vrefresh); if (ret) return NULL; diff --git a/drm-common.c b/drm-common.c index e4dad9c..3fa56e8 100644 --- a/drm-common.c +++ b/drm-common.c @@ -160,7 +160,7 @@ static uint32_t find_crtc_for_connector(const struct drm *drm, const drmModeRes return -1; } -int init_drm(struct drm *drm, const char *device) +int init_drm(struct drm *drm, const char *device, const char *mode_str, unsigned int vrefresh) { drmModeRes *resources; drmModeConnector *connector = NULL; @@ -199,19 +199,37 @@ int init_drm(struct drm *drm, const char *device) return -1; } - /* find preferred mode or the highest resolution mode: */ - for (i = 0, area = 0; i < connector->count_modes; i++) { - drmModeModeInfo *current_mode = &connector->modes[i]; + /* find user requested mode: */ + if (mode_str && *mode_str) { + for (i = 0; i < connector->count_modes; i++) { + drmModeModeInfo *current_mode = &connector->modes[i]; - if (current_mode->type & DRM_MODE_TYPE_PREFERRED) { - drm->mode = current_mode; - break; + if (strcmp(current_mode->name, mode_str) == 0) { + if (vrefresh == 0 || current_mode->vrefresh == vrefresh) { + drm->mode = current_mode; + break; + } + } } + if (!drm->mode) + printf("requested mode not found, using default mode!\n"); + } + + /* find preferred mode or the highest resolution mode: */ + if (!drm->mode) { + for (i = 0, area = 0; i < connector->count_modes; i++) { + drmModeModeInfo *current_mode = &connector->modes[i]; - int current_area = current_mode->hdisplay * current_mode->vdisplay; - if (current_area > area) { - drm->mode = current_mode; - area = current_area; + if (current_mode->type & DRM_MODE_TYPE_PREFERRED) { + drm->mode = current_mode; + break; + } + + int current_area = current_mode->hdisplay * current_mode->vdisplay; + if (current_area > area) { + drm->mode = current_mode; + area = current_area; + } } } diff --git a/drm-common.h b/drm-common.h index 53af2cf..c4eb886 100644 --- a/drm-common.h +++ b/drm-common.h @@ -73,8 +73,8 @@ struct drm_fb { struct drm_fb * drm_fb_get_from_bo(struct gbm_bo *bo); -int init_drm(struct drm *drm, const char *device); -const struct drm * init_drm_legacy(const char *device); -const struct drm * init_drm_atomic(const char *device); +int init_drm(struct drm *drm, const char *device, const char *mode_str, unsigned int vrefresh); +const struct drm * init_drm_legacy(const char *device, const char *mode_str, unsigned int vrefresh); +const struct drm * init_drm_atomic(const char *device, const char *mode_str, unsigned int vrefresh); #endif /* _DRM_COMMON_H */ diff --git a/drm-legacy.c b/drm-legacy.c index fd98a38..56a0fed 100644 --- a/drm-legacy.c +++ b/drm-legacy.c @@ -122,11 +122,11 @@ static int legacy_run(const struct gbm *gbm, const struct egl *egl) return 0; } -const struct drm * init_drm_legacy(const char *device) +const struct drm * init_drm_legacy(const char *device, const char *mode_str, unsigned int vrefresh) { int ret; - ret = init_drm(&drm, device); + ret = init_drm(&drm, device, mode_str, vrefresh); if (ret) return NULL; @@ -41,7 +41,7 @@ static const struct egl *egl; static const struct gbm *gbm; static const struct drm *drm; -static const char *shortopts = "AD:M:m:V:"; +static const char *shortopts = "AD:M:m:V:v:"; static const struct option longopts[] = { {"atomic", no_argument, 0, 'A'}, @@ -50,12 +50,13 @@ static const struct option longopts[] = { {"modifier", required_argument, 0, 'm'}, {"samples", required_argument, 0, 's'}, {"video", required_argument, 0, 'V'}, + {"vmode", required_argument, 0, 'v'}, {0, 0, 0, 0} }; static void usage(const char *name) { - printf("Usage: %s [-ADMmV]\n" + printf("Usage: %s [-ADMmVv]\n" "\n" "options:\n" " -A, --atomic use atomic modesetting and fencing\n" @@ -67,7 +68,9 @@ static void usage(const char *name) " nv12-1img - yuv textured (single nv12 texture)\n" " -m, --modifier=MODIFIER hardcode the selected modifier\n" " -s, --samples=N use MSAA\n" - " -V, --video=FILE video textured cube\n", + " -V, --video=FILE video textured cube\n" + " -v, --vmode=VMODE specify the video mode in the format\n" + " <mode>[-<vrefresh>]\n", name); } @@ -75,11 +78,15 @@ int main(int argc, char *argv[]) { const char *device = "/dev/dri/card0"; const char *video = NULL; + char mode_str[DRM_DISPLAY_MODE_LEN] = ""; + char *p; enum mode mode = SMOOTH; uint64_t modifier = DRM_FORMAT_MOD_LINEAR; int samples = 0; int atomic = 0; int opt; + unsigned int len; + unsigned int vrefresh = 0; #ifdef HAVE_GST gst_init(&argc, &argv); @@ -119,6 +126,19 @@ int main(int argc, char *argv[]) mode = VIDEO; video = optarg; break; + case 'v': + p = strchr(optarg, '-'); + if (p == NULL) { + len = strlen(optarg); + } else { + vrefresh = strtoul(p + 1, NULL, 0); + len = p - optarg; + } + if (len > sizeof(mode_str) - 1) + len = sizeof(mode_str) - 1; + strncpy(mode_str, optarg, len); + mode_str[len] = '\0'; + break; default: usage(argv[0]); return -1; @@ -126,9 +146,9 @@ int main(int argc, char *argv[]) } if (atomic) - drm = init_drm_atomic(device); + drm = init_drm_atomic(device, mode_str, vrefresh); else - drm = init_drm_legacy(device); + drm = init_drm_legacy(device, mode_str, vrefresh); if (!drm) { printf("failed to initialize %s DRM\n", atomic ? "atomic" : "legacy"); return -1; diff --git a/texturator.c b/texturator.c index 3fcacb3..8fcdb39 100644 --- a/texturator.c +++ b/texturator.c @@ -928,7 +928,7 @@ int main(int argc, char *argv[]) print_summary(); /* no real need for atomic here: */ - drm = init_drm_legacy(device); + drm = init_drm_legacy(device, NULL, 0); if (!drm) { printf("failed to initialize DRM\n"); return -1; |