[PATCH weston v6 56/73] compositor-drm: remove unused_connectors array

Pekka Paalanen ppaalanen at gmail.com
Fri Feb 16 14:57:41 UTC 2018


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

Replace the unused_connectors array by iterating through the head list
instead. A head that is not enabled (attached to an enabled output) is
basically an unused connector.

All connectors regardless of their status have a drm_head. This has the
nice effect that drm_pending_state_apply_atomic() does not need to
re-query the connector properties every time, they can be simply looked
up in the drm_head.

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

diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c
index 679f78be..ea58ca96 100644
--- a/libweston/compositor-drm.c
+++ b/libweston/compositor-drm.c
@@ -253,8 +253,7 @@ struct drm_backend {
 
 	bool state_invalid;
 
-	/* Connector and CRTC IDs not used by any enabled output. */
-	struct wl_array unused_connectors;
+	/* CRTC IDs not used by any enabled output. */
 	struct wl_array unused_crtcs;
 
 	int cursors_are_broken;
@@ -2143,47 +2142,36 @@ drm_pending_state_apply_atomic(struct drm_pending_state *pending_state,
 		return -1;
 
 	if (b->state_invalid) {
+		struct weston_head *head_base;
+		struct drm_head *head;
 		uint32_t *unused;
 		int err;
 
 		/* If we need to reset all our state (e.g. because we've
 		 * just started, or just been VT-switched in), explicitly
 		 * disable all the CRTCs and connectors we aren't using. */
-		wl_array_for_each(unused, &b->unused_connectors) {
-			struct drm_property_info infos[WDRM_CONNECTOR__COUNT];
+		wl_list_for_each(head_base,
+				 &b->compositor->head_list, compositor_link) {
 			struct drm_property_info *info;
-			drmModeObjectProperties *props;
-
-			memset(infos, 0, sizeof(infos));
 
-			props = drmModeObjectGetProperties(b->drm.fd,
-							   *unused,
-							   DRM_MODE_OBJECT_CONNECTOR);
-			if (!props) {
-				ret = -1;
+			if (weston_head_is_enabled(head_base))
 				continue;
-			}
 
-			drm_property_info_populate(b, connector_props, infos,
-						   WDRM_CONNECTOR__COUNT,
-						   props);
-			drmModeFreeObjectProperties(props);
+			head = to_drm_head(head_base);
 
-			info = &infos[WDRM_CONNECTOR_CRTC_ID];
-			err = drmModeAtomicAddProperty(req, *unused,
+			info = &head->props_conn[WDRM_CONNECTOR_CRTC_ID];
+			err = drmModeAtomicAddProperty(req, head->connector_id,
 						       info->prop_id, 0);
 			if (err <= 0)
 				ret = -1;
 
-			info = &infos[WDRM_CONNECTOR_DPMS];
+			info = &head->props_conn[WDRM_CONNECTOR_DPMS];
 			if (info->prop_id > 0)
-				err = drmModeAtomicAddProperty(req, *unused,
+				err = drmModeAtomicAddProperty(req, head->connector_id,
 							       info->prop_id,
 							       DRM_MODE_DPMS_OFF);
 			if (err <= 0)
 				ret = -1;
-
-			drm_property_info_free(infos, WDRM_CONNECTOR__COUNT);
 		}
 
 		wl_array_for_each(unused, &b->unused_crtcs) {
@@ -4846,8 +4834,6 @@ drm_output_enable(struct weston_output *base)
 				      &output->scanout_plane->base,
 				      &b->compositor->primary_plane);
 
-	wl_array_remove_uint32(&b->unused_connectors, head->connector_id);
-
 	weston_log("Output %s, (connector %d, crtc %d)\n",
 		   output->base.name, head->connector_id, output->crtc_id);
 	wl_list_for_each(m, &output->base.mode_list, link)
@@ -4872,9 +4858,7 @@ static void
 drm_output_deinit(struct weston_output *base)
 {
 	struct drm_output *output = to_drm_output(base);
-	struct drm_head *head = to_drm_head(weston_output_get_first_head(base));
 	struct drm_backend *b = to_drm_backend(base->compositor);
-	uint32_t *unused;
 
 	if (b->use_pixman)
 		drm_output_fini_pixman(output);
@@ -4897,9 +4881,6 @@ drm_output_deinit(struct weston_output *base)
 		}
 	}
 
-	unused = wl_array_add(&b->unused_connectors, sizeof(*unused));
-	*unused = head->connector_id;
-
 	drm_output_fini_crtc(output);
 }
 
@@ -4959,7 +4940,7 @@ drm_output_disable(struct weston_output *base)
 /**
  * Update the list of unused connectors and CRTCs
  *
- * This keeps the unused_connectors and unused_crtcs arrays up to date.
+ * This keeps the unused_crtc arrays up to date.
  *
  * @param b Weston backend structure
  * @param resources DRM resources for this device
@@ -4969,22 +4950,6 @@ drm_backend_update_unused_outputs(struct drm_backend *b, drmModeRes *resources)
 {
 	int i;
 
-	wl_array_release(&b->unused_connectors);
-	wl_array_init(&b->unused_connectors);
-
-	for (i = 0; i < resources->count_connectors; i++) {
-		struct drm_head *head;
-		uint32_t *connector_id;
-
-		head = drm_head_find_by_connector(b, resources->connectors[i]);
-		if (head && weston_head_is_enabled(&head->base))
-			continue;
-
-		connector_id = wl_array_add(&b->unused_connectors,
-					    sizeof(*connector_id));
-		*connector_id = resources->connectors[i];
-	}
-
 	wl_array_release(&b->unused_crtcs);
 	wl_array_init(&b->unused_crtcs);
 
@@ -5362,7 +5327,6 @@ drm_destroy(struct weston_compositor *ec)
 	weston_launcher_destroy(ec->launcher);
 
 	wl_array_release(&b->unused_crtcs);
-	wl_array_release(&b->unused_connectors);
 
 	close(b->drm.fd);
 	free(b->drm.filename);
@@ -5796,7 +5760,6 @@ drm_backend_create(struct weston_compositor *compositor,
 	b->state_invalid = true;
 	b->drm.fd = -1;
 	wl_array_init(&b->unused_crtcs);
-	wl_array_init(&b->unused_connectors);
 
 	/*
 	 * KMS support for hardware planes cannot properly synchronize
-- 
2.13.6



More information about the wayland-devel mailing list