[PATCH weston 5/8] compositor-drm: Take a reference to the drm_output's base where it makes sense

Emmanuel Gil Peyrot emmanuel.peyrot at collabora.com
Mon May 2 21:40:14 UTC 2016


This makes the code more uniform with the functions taking a
weston_output* as argument, and reduces the churn of the following
commits.

Signed-off-by: Emmanuel Gil Peyrot <emmanuel.peyrot at collabora.com>
---
 src/compositor-drm.c | 130 ++++++++++++++++++++++++++-------------------------
 1 file changed, 67 insertions(+), 63 deletions(-)

diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index f9a997b..5938d53 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -474,19 +474,20 @@ static struct weston_plane *
 drm_output_prepare_scanout_view(struct drm_output *output,
 				struct weston_view *ev)
 {
+	struct weston_output *output_base = &output->base;
 	struct drm_backend *b =
-		(struct drm_backend *)output->base.compositor->backend;
+		(struct drm_backend *)output_base->compositor->backend;
 	struct weston_buffer *buffer = ev->surface->buffer_ref.buffer;
 	struct weston_buffer_viewport *viewport = &ev->surface->buffer_viewport;
 	struct gbm_bo *bo;
 	uint32_t format;
 
-	if (ev->geometry.x != output->base.x ||
-	    ev->geometry.y != output->base.y ||
+	if (ev->geometry.x != output_base->x ||
+	    ev->geometry.y != output_base->y ||
 	    buffer == NULL || b->gbm == NULL ||
-	    buffer->width != output->base.current_mode->width ||
-	    buffer->height != output->base.current_mode->height ||
-	    output->base.transform != viewport->buffer.transform ||
+	    buffer->width != output_base->current_mode->width ||
+	    buffer->height != output_base->current_mode->height ||
+	    output_base->transform != viewport->buffer.transform ||
 	    ev->transform.enabled)
 		return NULL;
 
@@ -589,7 +590,7 @@ drm_output_set_gamma(struct weston_output *output_base,
 	int rc;
 	struct drm_output *output = (struct drm_output *) output_base;
 	struct drm_backend *backend =
-		(struct drm_backend *) output->base.compositor->backend;
+		(struct drm_backend *) output_base->compositor->backend;
 
 	/* check */
 	if (output_base->gamma_size != size)
@@ -635,7 +636,7 @@ drm_output_repaint(struct weston_output *output_base,
 {
 	struct drm_output *output = (struct drm_output *) output_base;
 	struct drm_backend *backend =
-		(struct drm_backend *)output->base.compositor->backend;
+		(struct drm_backend *)output_base->compositor->backend;
 	struct drm_sprite *s;
 	struct drm_mode *mode;
 	int ret = 0;
@@ -648,7 +649,7 @@ drm_output_repaint(struct weston_output *output_base,
 	if (!output->next)
 		return -1;
 
-	mode = container_of(output->base.current_mode, struct drm_mode, base);
+	mode = container_of(output_base->current_mode, struct drm_mode, base);
 	if (!output->current ||
 	    output->current->stride != output->next->stride) {
 		ret = drmModeSetCrtc(backend->drm.fd, output->crtc_id,
@@ -772,7 +773,7 @@ drm_output_start_repaint_loop(struct weston_output *output_base)
 							  &tnow);
 		timespec_sub(&vbl2now, &tnow, &ts);
 		refresh_nsec =
-			millihz_to_nsec(output->base.current_mode->refresh);
+			millihz_to_nsec(output_base->current_mode->refresh);
 		if (timespec_to_nsec(&vbl2now) < refresh_nsec) {
 			drm_output_update_msc(output, vbl.reply.sequence);
 			weston_output_finish_frame(output_base, &ts,
@@ -916,7 +917,8 @@ static struct weston_plane *
 drm_output_prepare_overlay_view(struct drm_output *output,
 				struct weston_view *ev)
 {
-	struct weston_compositor *ec = output->base.compositor;
+	struct weston_output *output_base = &output->base;
+	struct weston_compositor *ec = output_base->compositor;
 	struct drm_backend *b = (struct drm_backend *)ec->backend;
 	struct weston_buffer_viewport *viewport = &ev->surface->buffer_viewport;
 	struct wl_resource *buffer_resource;
@@ -932,16 +934,16 @@ drm_output_prepare_overlay_view(struct drm_output *output,
 	if (b->gbm == NULL)
 		return NULL;
 
-	if (viewport->buffer.transform != output->base.transform)
+	if (viewport->buffer.transform != output_base->transform)
 		return NULL;
 
-	if (viewport->buffer.scale != output->base.current_scale)
+	if (viewport->buffer.scale != output_base->current_scale)
 		return NULL;
 
 	if (b->sprites_are_broken)
 		return NULL;
 
-	if (ev->output_mask != (1u << output->base.id))
+	if (ev->output_mask != (1u << output_base->id))
 		return NULL;
 
 	if (ev->surface->buffer_ref.buffer == NULL)
@@ -1028,13 +1030,13 @@ drm_output_prepare_overlay_view(struct drm_output *output,
 	 */
 	pixman_region32_init(&dest_rect);
 	pixman_region32_intersect(&dest_rect, &ev->transform.boundingbox,
-				  &output->base.region);
-	pixman_region32_translate(&dest_rect, -output->base.x, -output->base.y);
+				  &output_base->region);
+	pixman_region32_translate(&dest_rect, -output_base->x, -output_base->y);
 	box = pixman_region32_extents(&dest_rect);
-	tbox = weston_transformed_rect(output->base.width,
-				       output->base.height,
-				       output->base.transform,
-				       output->base.current_scale,
+	tbox = weston_transformed_rect(output_base->width,
+				       output_base->height,
+				       output_base->transform,
+				       output_base->current_scale,
 				       *box);
 	s->dest_x = tbox.x1;
 	s->dest_y = tbox.y1;
@@ -1044,7 +1046,7 @@ drm_output_prepare_overlay_view(struct drm_output *output,
 
 	pixman_region32_init(&src_rect);
 	pixman_region32_intersect(&src_rect, &ev->transform.boundingbox,
-				  &output->base.region);
+				  &output_base->region);
 	box = pixman_region32_extents(&src_rect);
 
 	weston_view_from_global_fixed(ev,
@@ -1312,7 +1314,7 @@ drm_output_destroy(struct weston_output *output_base)
 {
 	struct drm_output *output = (struct drm_output *) output_base;
 	struct drm_backend *b =
-		(struct drm_backend *)output->base.compositor->backend;
+		(struct drm_backend *)output_base->compositor->backend;
 	drmModeCrtcPtr origcrtc = output->original_crtc;
 
 	if (output->page_flip_pending) {
@@ -1420,13 +1422,13 @@ drm_output_switch_mode(struct weston_output *output_base, struct weston_mode *mo
 		return -1;
 	}
 
-	if (&drm_mode->base == output->base.current_mode)
+	if (&drm_mode->base == output_base->current_mode)
 		return 0;
 
-	output->base.current_mode->flags = 0;
+	output_base->current_mode->flags = 0;
 
-	output->base.current_mode = &drm_mode->base;
-	output->base.current_mode->flags =
+	output_base->current_mode = &drm_mode->base;
+	output_base->current_mode->flags =
 		WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
 
 	/* reset rendering stuff. */
@@ -1754,7 +1756,7 @@ drm_set_dpms(struct weston_output *output_base, enum dpms_enum level)
 				 	  output->dpms_prop->prop_id, level);
 	if (ret) {
 		weston_log("DRM: DPMS: failed property set for %s\n",
-			   output->base.name);
+			   output_base->name);
 		return;
 	}
 
@@ -2302,11 +2304,12 @@ create_output_for_connector(struct drm_backend *b,
 {
 	struct drm_output *output;
 	struct drm_mode *drm_mode, *next, *current;
+	struct weston_output *output_base;
 	struct weston_mode *m;
 	struct weston_config_section *section;
 	drmModeModeInfo crtc_mode, modeline;
 	int i, width, height, scale;
-	char *s;
+	char *s, *name;
 	enum output_config config;
 	uint32_t transform;
 
@@ -2316,19 +2319,22 @@ create_output_for_connector(struct drm_backend *b,
 		return -1;
 	}
 
+	name = make_connector_name(connector);
+
 	output = zalloc(sizeof *output);
 	if (output == NULL)
 		return -1;
 
-	output->base.subpixel = drm_subpixel_to_wayland(connector->subpixel);
-	output->base.name = make_connector_name(connector);
-	output->base.make = "unknown";
-	output->base.model = "unknown";
-	output->base.serial_number = "unknown";
-	wl_list_init(&output->base.mode_list);
+	output_base = &output->base;
+	output_base->subpixel = drm_subpixel_to_wayland(connector->subpixel);
+	output_base->name = name;
+	output_base->make = "unknown";
+	output_base->model = "unknown";
+	output_base->serial_number = "unknown";
+	wl_list_init(&output_base->mode_list);
 
 	section = weston_config_get_section(b->compositor->config, "output", "name",
-					    output->base.name);
+	                                    name);
 	weston_config_section_get_string(section, "mode", &s, "preferred");
 	if (strcmp(s, "off") == 0)
 		config = OUTPUT_CONFIG_OFF;
@@ -2341,8 +2347,7 @@ create_output_for_connector(struct drm_backend *b,
 	else if (parse_modeline(s, &modeline) == 0)
 		config = OUTPUT_CONFIG_MODELINE;
 	else {
-		weston_log("Invalid mode \"%s\" for output %s\n",
-			   s, output->base.name);
+		weston_log("Invalid mode \"%s\" for output %s\n", s, name);
 		config = OUTPUT_CONFIG_PREFERRED;
 	}
 	free(s);
@@ -2350,8 +2355,7 @@ create_output_for_connector(struct drm_backend *b,
 	weston_config_section_get_int(section, "scale", &scale, 1);
 	weston_config_section_get_string(section, "transform", &s, "normal");
 	if (weston_parse_transform(s, &transform) < 0)
-		weston_log("Invalid transform \"%s\" for output %s\n",
-			   s, output->base.name);
+		weston_log("Invalid transform \"%s\" for output %s\n", s, name);
 
 	free(s);
 
@@ -2361,7 +2365,7 @@ create_output_for_connector(struct drm_backend *b,
 		output->gbm_format = b->gbm_format;
 
 	weston_config_section_get_string(section, "seat", &s, "");
-	setup_output_seat_constraint(b, &output->base, s);
+	setup_output_seat_constraint(b, output_base, s);
 	free(s);
 
 	output->crtc_id = resources->crtcs[i];
@@ -2383,7 +2387,7 @@ create_output_for_connector(struct drm_backend *b,
 	}
 
 	if (config == OUTPUT_CONFIG_OFF) {
-		weston_log("Disabling output %s\n", output->base.name);
+		weston_log("Disabling output %s\n", name);
 		drmModeSetCrtc(b->drm.fd, output->crtc_id,
 			       0, 0, 0, 0, 0, NULL);
 		goto err_free;
@@ -2394,10 +2398,10 @@ create_output_for_connector(struct drm_backend *b,
 						 &crtc_mode, &modeline);
 	if (!current)
 		goto err_free;
-	output->base.current_mode = &current->base;
-	output->base.current_mode->flags |= WL_OUTPUT_MODE_CURRENT;
+	output_base->current_mode = &current->base;
+	output_base->current_mode->flags |= WL_OUTPUT_MODE_CURRENT;
 
-	weston_output_init(&output->base, b->compositor, x, y,
+	weston_output_init(output_base, b->compositor, x, y,
 			   connector->mmWidth, connector->mmHeight,
 			   transform, scale);
 
@@ -2416,27 +2420,27 @@ create_output_for_connector(struct drm_backend *b,
 	if (output->backlight) {
 		weston_log("Initialized backlight, device %s\n",
 			   output->backlight->path);
-		output->base.set_backlight = drm_set_backlight;
-		output->base.backlight_current = drm_get_backlight(output);
+		output_base->set_backlight = drm_set_backlight;
+		output_base->backlight_current = drm_get_backlight(output);
 	} else {
 		weston_log("Failed to initialize backlight\n");
 	}
 
-	weston_compositor_add_output(b->compositor, &output->base);
+	weston_compositor_add_output(b->compositor, output_base);
 
 	find_and_parse_output_edid(b, output, connector);
 	if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)
-		output->base.connection_internal = 1;
+		output_base->connection_internal = 1;
 
-	output->base.start_repaint_loop = drm_output_start_repaint_loop;
-	output->base.repaint = drm_output_repaint;
-	output->base.destroy = drm_output_destroy;
-	output->base.assign_planes = drm_assign_planes;
-	output->base.set_dpms = drm_set_dpms;
-	output->base.switch_mode = drm_output_switch_mode;
+	output_base->start_repaint_loop = drm_output_start_repaint_loop;
+	output_base->repaint = drm_output_repaint;
+	output_base->destroy = drm_output_destroy;
+	output_base->assign_planes = drm_assign_planes;
+	output_base->set_dpms = drm_set_dpms;
+	output_base->switch_mode = drm_output_switch_mode;
 
-	output->base.gamma_size = output->original_crtc->gamma_size;
-	output->base.set_gamma = drm_output_set_gamma;
+	output_base->gamma_size = output->original_crtc->gamma_size;
+	output_base->set_gamma = drm_output_set_gamma;
 
 	weston_plane_init(&output->cursor_plane, b->compositor,
 			  INT32_MIN, INT32_MIN);
@@ -2446,9 +2450,9 @@ create_output_for_connector(struct drm_backend *b,
 	weston_compositor_stack_plane(b->compositor, &output->fb_plane,
 				      &b->compositor->primary_plane);
 
-	weston_log("Output %s, (connector %d, crtc %d)\n",
-		   output->base.name, output->connector_id, output->crtc_id);
-	wl_list_for_each(m, &output->base.mode_list, link)
+	weston_log("Output %s, (connector %d, crtc %d)\n", name,
+	           output->connector_id, output->crtc_id);
+	wl_list_for_each(m, &output_base->mode_list, link)
 		weston_log_continue(STAMP_SPACE "mode %dx%d@%.1f%s%s%s\n",
 				    m->width, m->height, m->refresh / 1000.0,
 				    m->flags & WL_OUTPUT_MODE_PREFERRED ?
@@ -2459,15 +2463,15 @@ create_output_for_connector(struct drm_backend *b,
 				    ", built-in" : "");
 
 	/* Set native_ fields, so weston_output_mode_switch_to_native() works */
-	output->base.native_mode = output->base.current_mode;
-	output->base.native_scale = output->base.current_scale;
+	output_base->native_mode = output_base->current_mode;
+	output_base->native_scale = output_base->current_scale;
 
 	return 0;
 
 err_output:
-	weston_output_destroy(&output->base);
+	weston_output_destroy(output_base);
 err_free:
-	wl_list_for_each_safe(drm_mode, next, &output->base.mode_list,
+	wl_list_for_each_safe(drm_mode, next, &output_base->mode_list,
 							base.link) {
 		wl_list_remove(&drm_mode->base.link);
 		free(drm_mode);
-- 
2.8.2



More information about the wayland-devel mailing list