compositor-drm: Refactor getting current mode into a new function
Makes create_output_for_connector() slightly easier to read. Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk> Signed-off-by: Daniel Stone <daniels@collabora.com> Reviewed-by: Derek Foreman <derekf@osg.samsung.com>
This commit is contained in:
committed by
Daniel Stone
parent
3ce6362a33
commit
eee580b894
+26
-15
@@ -2158,13 +2158,37 @@ drm_output_choose_initial_mode(struct drm_output *output,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
connector_get_current_mode(drmModeConnector *connector, int drm_fd,
|
||||||
|
drmModeModeInfo *mode)
|
||||||
|
{
|
||||||
|
drmModeEncoder *encoder;
|
||||||
|
drmModeCrtc *crtc;
|
||||||
|
|
||||||
|
/* Get the current mode on the crtc that's currently driving
|
||||||
|
* this connector. */
|
||||||
|
encoder = drmModeGetEncoder(drm_fd, connector->encoder_id);
|
||||||
|
memset(mode, 0, sizeof *mode);
|
||||||
|
if (encoder != NULL) {
|
||||||
|
crtc = drmModeGetCrtc(drm_fd, encoder->crtc_id);
|
||||||
|
drmModeFreeEncoder(encoder);
|
||||||
|
if (crtc == NULL)
|
||||||
|
return -1;
|
||||||
|
if (crtc->mode_valid)
|
||||||
|
*mode = crtc->mode;
|
||||||
|
drmModeFreeCrtc(crtc);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create and configure a Weston output structure
|
* Create and configure a Weston output structure
|
||||||
*
|
*
|
||||||
* Given a DRM connector, create a matching drm_output structure and add it
|
* Given a DRM connector, create a matching drm_output structure and add it
|
||||||
* to Weston's output list.
|
* to Weston's output list.
|
||||||
*
|
*
|
||||||
* @param ec DRM compositor structure
|
* @param b Weston backend structure structure
|
||||||
* @param resources DRM resources for this device
|
* @param resources DRM resources for this device
|
||||||
* @param connector DRM connector to use for this new output
|
* @param connector DRM connector to use for this new output
|
||||||
* @param x Horizontal offset to use into global co-ordinate space
|
* @param x Horizontal offset to use into global co-ordinate space
|
||||||
@@ -2182,9 +2206,7 @@ create_output_for_connector(struct drm_backend *b,
|
|||||||
struct drm_mode *drm_mode, *next, *current;
|
struct drm_mode *drm_mode, *next, *current;
|
||||||
struct weston_mode *m;
|
struct weston_mode *m;
|
||||||
struct weston_config_section *section;
|
struct weston_config_section *section;
|
||||||
drmModeEncoder *encoder;
|
|
||||||
drmModeModeInfo crtc_mode, modeline;
|
drmModeModeInfo crtc_mode, modeline;
|
||||||
drmModeCrtc *crtc;
|
|
||||||
int i, width, height, scale;
|
int i, width, height, scale;
|
||||||
char *s;
|
char *s;
|
||||||
enum output_config config;
|
enum output_config config;
|
||||||
@@ -2253,19 +2275,8 @@ create_output_for_connector(struct drm_backend *b,
|
|||||||
output->original_crtc = drmModeGetCrtc(b->drm.fd, output->crtc_id);
|
output->original_crtc = drmModeGetCrtc(b->drm.fd, output->crtc_id);
|
||||||
output->dpms_prop = drm_get_prop(b->drm.fd, connector, "DPMS");
|
output->dpms_prop = drm_get_prop(b->drm.fd, connector, "DPMS");
|
||||||
|
|
||||||
/* Get the current mode on the crtc that's currently driving
|
if (connector_get_current_mode(connector, b->drm.fd, &crtc_mode) < 0)
|
||||||
* this connector. */
|
|
||||||
encoder = drmModeGetEncoder(b->drm.fd, connector->encoder_id);
|
|
||||||
memset(&crtc_mode, 0, sizeof crtc_mode);
|
|
||||||
if (encoder != NULL) {
|
|
||||||
crtc = drmModeGetCrtc(b->drm.fd, encoder->crtc_id);
|
|
||||||
drmModeFreeEncoder(encoder);
|
|
||||||
if (crtc == NULL)
|
|
||||||
goto err_free;
|
goto err_free;
|
||||||
if (crtc->mode_valid)
|
|
||||||
crtc_mode = crtc->mode;
|
|
||||||
drmModeFreeCrtc(crtc);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < connector->count_modes; i++) {
|
for (i = 0; i < connector->count_modes; i++) {
|
||||||
drm_mode = drm_output_add_mode(output, &connector->modes[i]);
|
drm_mode = drm_output_add_mode(output, &connector->modes[i]);
|
||||||
|
|||||||
Reference in New Issue
Block a user