[PATCH v2 weston 03/16] compositor-drm: Refactor getting current mode into a new function

Daniel Stone daniels at collabora.com
Mon Jun 22 09:25:08 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>
Signed-off-by: Daniel Stone <daniels at collabora.com>
---
 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 25a4567..43dd483 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -2105,6 +2105,30 @@ drm_output_choose_initial_mode(struct drm_output *output,
  * @returns 0 on success, or -1 on failure
  */
 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,
@@ -2114,9 +2138,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;
@@ -2185,19 +2207,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.3



More information about the wayland-devel mailing list