[RFC weston 02/14] compositor-drm: Refactor initial mode out of create_output

Daniel Stone daniels at collabora.com
Thu May 21 00:28:59 PDT 2015


From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>

Refactor the code for choosing the initial mode for an output from
create_output_for_connector() to drm_output_choose_initial_mode().

This makes create_output_for_connector() slightly easier to read.

Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
---
 src/compositor-drm.c | 119 ++++++++++++++++++++++++++++++---------------------
 1 file changed, 70 insertions(+), 49 deletions(-)

diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index bf921be..516693b 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -1460,7 +1460,7 @@ init_pixman(struct drm_compositor *ec)
 }
 
 static struct drm_mode *
-drm_output_add_mode(struct drm_output *output, drmModeModeInfo *info)
+drm_output_add_mode(struct drm_output *output, const drmModeModeInfo *info)
 {
 	struct drm_mode *mode;
 	uint64_t refresh;
@@ -1973,6 +1973,69 @@ get_gbm_format_from_section(struct weston_config_section *section,
 	return ret;
 }
 
+static struct drm_mode *
+drm_output_choose_initial_mode(struct drm_output *output,
+			       enum output_config kind,
+			       int width, int height,
+			       const drmModeModeInfo *current_mode,
+			       const drmModeModeInfo *modeline)
+{
+	struct drm_mode *preferred = NULL;
+	struct drm_mode *current = NULL;
+	struct drm_mode *configured = NULL;
+	struct drm_mode *best = NULL;
+	struct drm_mode *drm_mode;
+
+	wl_list_for_each_reverse(drm_mode, &output->base.mode_list, base.link) {
+		if (kind == OUTPUT_CONFIG_MODE &&
+		    width == drm_mode->base.width &&
+		    height == drm_mode->base.height)
+			configured = drm_mode;
+
+		if (memcmp(&current_mode, &drm_mode->mode_info,
+			   sizeof *current_mode) == 0)
+			current = drm_mode;
+
+		if (drm_mode->base.flags & WL_OUTPUT_MODE_PREFERRED)
+			preferred = drm_mode;
+
+		best = drm_mode;
+	}
+
+	if (kind == OUTPUT_CONFIG_MODELINE) {
+		configured = drm_output_add_mode(output, modeline);
+		if (!configured)
+			return NULL;
+	}
+
+	if (current == NULL && current_mode->clock != 0) {
+		current = drm_output_add_mode(output, current_mode);
+		if (!current)
+			return NULL;
+	}
+
+	if (kind == OUTPUT_CONFIG_CURRENT)
+		configured = current;
+
+	if (option_current_mode && current)
+		return current;
+
+	if (configured)
+		return configured;
+
+	if (preferred)
+		return preferred;
+
+	if (current)
+		return current;
+
+	if (best)
+		return best;
+
+	weston_log("no available modes for %s\n", output->base.name);
+	return NULL;
+}
+
 static int
 create_output_for_connector(struct drm_compositor *ec,
 			    drmModeRes *resources,
@@ -1980,7 +2043,7 @@ create_output_for_connector(struct drm_compositor *ec,
 			    int x, int y, struct udev_device *drm_device)
 {
 	struct drm_output *output;
-	struct drm_mode *drm_mode, *next, *preferred, *current, *configured, *best;
+	struct drm_mode *drm_mode, *next, *current;
 	struct weston_mode *m;
 	struct weston_config_section *section;
 	drmModeEncoder *encoder;
@@ -2088,54 +2151,12 @@ create_output_for_connector(struct drm_compositor *ec,
 		goto err_free;
 	}
 
-	preferred = NULL;
-	current = NULL;
-	configured = NULL;
-	best = NULL;
-
-	wl_list_for_each_reverse(drm_mode, &output->base.mode_list, base.link) {
-		if (config == OUTPUT_CONFIG_MODE &&
-		    width == drm_mode->base.width &&
-		    height == drm_mode->base.height)
-			configured = drm_mode;
-		if (!memcmp(&crtc_mode, &drm_mode->mode_info, sizeof crtc_mode))
-			current = drm_mode;
-		if (drm_mode->base.flags & WL_OUTPUT_MODE_PREFERRED)
-			preferred = drm_mode;
-		best = drm_mode;
-	}
-
-	if (config == OUTPUT_CONFIG_MODELINE) {
-		configured = drm_output_add_mode(output, &modeline);
-		if (!configured)
-			goto err_free;
-	}
-
-	if (current == NULL && crtc_mode.clock != 0) {
-		current = drm_output_add_mode(output, &crtc_mode);
-		if (!current)
-			goto err_free;
-	}
-
-	if (config == OUTPUT_CONFIG_CURRENT)
-		configured = current;
-
-	if (option_current_mode && current)
-		output->base.current_mode = &current->base;
-	else if (configured)
-		output->base.current_mode = &configured->base;
-	else if (preferred)
-		output->base.current_mode = &preferred->base;
-	else if (current)
-		output->base.current_mode = &current->base;
-	else if (best)
-		output->base.current_mode = &best->base;
-
-	if (output->base.current_mode == NULL) {
-		weston_log("no available modes for %s\n", output->base.name);
+	current = drm_output_choose_initial_mode(output, config,
+						 width, height,
+						 &crtc_mode, &modeline);
+	if (!current)
 		goto err_free;
-	}
-
+	output->base.current_mode = &current->base;
 	output->base.current_mode->flags |= WL_OUTPUT_MODE_CURRENT;
 
 	weston_output_init(&output->base, &ec->base, x, y,
-- 
2.4.1



More information about the wayland-devel mailing list