[RFC weston 04/14] compositor-drm: Refactor getting current mode into a new function
Daniel Stone
daniels at collabora.com
Thu May 21 00:29:01 PDT 2015
From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
Makes create_output_for_connector() slightly easier to read.
Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
---
src/compositor-drm.c | 41 ++++++++++++++++++++++++++---------------
1 file changed, 26 insertions(+), 15 deletions(-)
diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index 53736a6..d47bbd9 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -2052,6 +2052,30 @@ drm_output_choose_initial_mode(struct drm_output *output,
}
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;
+}
+
+static int
create_output_for_connector(struct drm_compositor *ec,
drmModeRes *resources,
drmModeConnector *connector,
@@ -2061,9 +2085,7 @@ create_output_for_connector(struct drm_compositor *ec,
struct drm_mode *drm_mode, *next, *current;
struct weston_mode *m;
struct weston_config_section *section;
- drmModeEncoder *encoder;
drmModeModeInfo crtc_mode, modeline;
- drmModeCrtc *crtc;
int i, width, height, scale;
char *s;
enum output_config config;
@@ -2132,19 +2154,8 @@ create_output_for_connector(struct drm_compositor *ec,
output->original_crtc = drmModeGetCrtc(ec->drm.fd, output->crtc_id);
output->dpms_prop = drm_get_prop(ec->drm.fd, connector, "DPMS");
- /* Get the current mode on the crtc that's currently driving
- * this connector. */
- encoder = drmModeGetEncoder(ec->drm.fd, connector->encoder_id);
- memset(&crtc_mode, 0, sizeof crtc_mode);
- if (encoder != NULL) {
- crtc = drmModeGetCrtc(ec->drm.fd, encoder->crtc_id);
- drmModeFreeEncoder(encoder);
- if (crtc == NULL)
- goto err_free;
- if (crtc->mode_valid)
- crtc_mode = crtc->mode;
- drmModeFreeCrtc(crtc);
- }
+ if (connector_get_current_mode(connector, ec->drm.fd, &crtc_mode) < 0)
+ goto err_free;
for (i = 0; i < connector->count_modes; i++) {
drm_mode = drm_output_add_mode(output, &connector->modes[i]);
--
2.4.1
More information about the wayland-devel
mailing list