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 /drm-common.c | |
parent | a09d38f94e27dcc5fe52adf99404c821028e3e9d (diff) | |
download | kmscube-a0a4c0238026b24ac7ace5919132921160673ce2.tar.gz |
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>
Diffstat (limited to 'drm-common.c')
-rw-r--r-- | drm-common.c | 40 |
1 files changed, 29 insertions, 11 deletions
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; + } } } |