[PATCH 6/9] compositor-drm: Abstract drm_output_set_mode()

Xiong Zhang xiong.y.zhang at intel.com
Thu Feb 13 23:17:41 PST 2014


Signed-off-by: Xiong Zhang <xiong.y.zhang at intel.com>
---
 src/compositor-drm.c | 81 +++++++++++++++++++---------------------------------
 1 file changed, 29 insertions(+), 52 deletions(-)

diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index 842710f..836f81d 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -583,6 +583,27 @@ drm_output_set_gamma(struct weston_output *output_base,
 }
 
 static int
+drm_output_set_mode(struct drm_output *output,
+				uint32_t fb_id)
+{
+	struct drm_compositor *compositor =
+		(struct drm_compositor *)output->base.compositor;
+	struct drm_mode *mode;
+	int ret = 0;
+
+	mode = container_of(output->base.current_mode,
+			    struct drm_mode, base);
+	ret = drmModeSetCrtc(compositor->drm.fd, output->crtc_id,
+			     fb_id, 0, 0,
+			     &output->connector_id, 1,
+			     &mode->mode_info);
+	if (ret)
+		weston_log("set mode failed:%m\n");
+
+	return ret;
+}
+
+static int
 drm_output_repaint(struct weston_output *output_base,
 		   pixman_region32_t *damage)
 {
@@ -590,7 +611,6 @@ drm_output_repaint(struct weston_output *output_base,
 	struct drm_compositor *compositor =
 		(struct drm_compositor *) output->base.compositor;
 	struct drm_sprite *s;
-	struct drm_mode *mode;
 	int ret = 0;
 	struct drm_output *clone_output;
 
@@ -602,33 +622,18 @@ drm_output_repaint(struct weston_output *output_base,
 	if (!output->next)
 		return -1;
 
-	mode = container_of(output->base.current_mode, struct drm_mode, base);
 	if (!output->current ||
 	    output->current->stride != output->next->stride) {
-		ret = drmModeSetCrtc(compositor->drm.fd, output->crtc_id,
-				     output->next->fb_id, 0, 0,
-				     &output->connector_id, 1,
-				     &mode->mode_info);
-		if (ret) {
-			weston_log("set mode failed: %m\n");
+		if (drm_output_set_mode(output, output->next->fb_id))
 			goto err_pageflip;
-		}
+
 		output_base->set_dpms(output_base, WESTON_DPMS_ON);
 
 		wl_list_for_each(clone_output, &output->base.clone_output_list,
 				 base.link) {
-			mode = container_of(clone_output->base.current_mode,
-					    struct drm_mode, base);
-
-			ret = drmModeSetCrtc(compositor->drm.fd,
-					     clone_output->crtc_id,
-					     output->next->fb_id, 0, 0,
-					     &clone_output->connector_id, 1,
-					     &mode->mode_info);
-			if (ret) {
-				weston_log("set mode failed:%m\n");
+			if (drm_output_set_mode(clone_output,
+						output->next->fb_id))
 				goto err_pageflip;
-			}
 
 			clone_output->base.set_dpms(&clone_output->base,
 						    WESTON_DPMS_ON);
@@ -2699,8 +2704,6 @@ static void
 drm_compositor_set_modes(struct drm_compositor *compositor)
 {
 	struct drm_output *output;
-	struct drm_mode *drm_mode;
-	int ret;
 	struct drm_output *clone_output;
 
 	wl_list_for_each(output, &compositor->base.output_list, base.link) {
@@ -2714,40 +2717,14 @@ drm_compositor_set_modes(struct drm_compositor *compositor)
 			continue;
 		}
 
-		drm_mode = (struct drm_mode *) output->base.current_mode;
-		ret = drmModeSetCrtc(compositor->drm.fd, output->crtc_id,
-				     output->current->fb_id, 0, 0,
-				     &output->connector_id, 1,
-				     &drm_mode->mode_info);
-		if (ret < 0) {
-			weston_log(
-				"failed to set mode %dx%d for output at %d,%d: %m\n",
-				drm_mode->base.width, drm_mode->base.height,
-				output->base.x, output->base.y);
-		}
+		drm_output_set_mode(output, output->current->fb_id);
 
 		if (!output->base.is_slave) {
 			wl_list_for_each(clone_output,
 					 &output->base.clone_output_list,
-					 base.link) {
-				drm_mode = (struct drm_mode *)
-					clone_output->base.current_mode;
-				ret = drmModeSetCrtc(compositor->drm.fd,
-						     clone_output->crtc_id,
-						     output->current->fb_id,
-						     0, 0,
-						     &clone_output->connector_id,
-						     1,
-						     &drm_mode->mode_info);
-				if (ret < 0) {
-					weston_log("failed to set mode %dx%d
-						    for output at %d,%d: %m\n",
-						    drm_mode->base.width,
-						    drm_mode->base.height,
-						    clone_output->base.x,
-						    clone_output->base.y);
-				}
-			}
+					 base.link)
+				drm_output_set_mode(clone_output,
+						    output->current->fb_id);
 		}
 	}
 }
-- 
1.8.3.2



More information about the wayland-devel mailing list