drm: move mode selection to get_preferred_mode function
This commit is contained in:
parent
af1ba566ba
commit
953c5ec377
2 changed files with 25 additions and 17 deletions
40
src/drm.cpp
40
src/drm.cpp
|
@ -347,13 +347,35 @@ static bool get_properties(struct drm_t *drm, uint32_t obj_id, uint32_t obj_type
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const drmModeModeInfo *get_preferred_mode( const drmModeConnector *connector )
|
||||||
|
{
|
||||||
|
/* find preferred mode or the highest resolution mode */
|
||||||
|
int highest_area = 0;
|
||||||
|
const drmModeModeInfo *highest_mode = NULL;
|
||||||
|
for (int i = 0; i < connector->count_modes; i++) {
|
||||||
|
const drmModeModeInfo *mode = &connector->modes[i];
|
||||||
|
|
||||||
|
if (mode->type & DRM_MODE_TYPE_PREFERRED) {
|
||||||
|
return mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
int area = mode->hdisplay * mode->vdisplay;
|
||||||
|
if (area > highest_area) {
|
||||||
|
highest_mode = mode;
|
||||||
|
highest_area = area;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return highest_mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int init_drm(struct drm_t *drm, const char *device)
|
int init_drm(struct drm_t *drm, const char *device)
|
||||||
{
|
{
|
||||||
drmModeRes *resources;
|
drmModeRes *resources;
|
||||||
drmModeConnector *connector = NULL;
|
drmModeConnector *connector = NULL;
|
||||||
drmModeEncoder *encoder = NULL;
|
drmModeEncoder *encoder = NULL;
|
||||||
int i, ret, area;
|
int i, ret;
|
||||||
|
|
||||||
if (device) {
|
if (device) {
|
||||||
drm->fd = open(device, O_RDWR | O_CLOEXEC);
|
drm->fd = open(device, O_RDWR | O_CLOEXEC);
|
||||||
|
@ -393,22 +415,8 @@ int init_drm(struct drm_t *drm, const char *device)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* find preferred mode or the highest resolution mode: */
|
|
||||||
if (!drm->mode) {
|
if (!drm->mode) {
|
||||||
for (i = 0, area = 0; i < connector->count_modes; i++) {
|
drm->mode = get_preferred_mode(connector);
|
||||||
drmModeModeInfo *current_mode = &connector->modes[i];
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!drm->mode) {
|
if (!drm->mode) {
|
||||||
|
|
|
@ -63,7 +63,7 @@ struct drm_t {
|
||||||
int kms_in_fence_fd;
|
int kms_in_fence_fd;
|
||||||
int kms_out_fence_fd;
|
int kms_out_fence_fd;
|
||||||
|
|
||||||
drmModeModeInfo *mode;
|
const drmModeModeInfo *mode;
|
||||||
uint32_t mode_id;
|
uint32_t mode_id;
|
||||||
uint32_t crtc_id;
|
uint32_t crtc_id;
|
||||||
uint32_t connector_id;
|
uint32_t connector_id;
|
||||||
|
|
Loading…
Reference in a new issue