[PATCH 4/6] Initialize the randr interface in drm backend

Quanxian Wang quanxian.wang at intel.com
Wed Feb 26 19:28:03 PST 2014


Function get_disoutputs is added in order to provide
display port information embedded on the machine.

Signed-off-by: Quanxian Wang <quanxian.wang at intel.com>
Reviewed-by: Zhang, Xiong Y <xiong.y.zhang at intel.com>
---
 src/compositor-drm.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index 154e15e..1f43071 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -2222,6 +2222,54 @@ create_outputs(struct drm_compositor *ec, uint32_t option_connector,
 }
 
 static void
+get_disoutputs(struct weston_compositor *ec,
+			char *ret_str)
+{
+	struct drm_compositor *drm_ec =
+		container_of(ec, struct drm_compositor, base);
+	drmModeConnector *connector;
+	drmModeRes *resources;
+	char name[128];
+	const char *type_name;
+	int i;
+
+	if (!ret_str)
+		return;
+	memset(ret_str, 0x0, strlen(ret_str));
+
+	resources = drmModeGetResources(drm_ec->drm.fd);
+	if (!resources) {
+		weston_log("drmModeGetResources failed\n");
+		return;
+	}
+
+	/* Collect disconnected connects */
+	for (i = 0; i < resources->count_connectors; i++) {
+		int connector_id = resources->connectors[i];
+
+		connector = drmModeGetConnector(drm_ec->drm.fd, connector_id);
+		if (connector == NULL)
+			continue;
+
+		if (connector->connection != DRM_MODE_CONNECTED) {
+			type_name =
+				connector_type_names[connector->connector_type];
+			if (connector->connector_type >=
+			    ARRAY_LENGTH(connector_type_names))
+				type_name = "UNKNOWN";
+
+			snprintf(name, 128, "%s%d disconnected.\n",
+				 type_name, connector->connector_type_id);
+			strcat(ret_str, name);
+
+			drmModeFreeConnector(connector);
+		}
+	}
+
+	return;
+}
+
+static void
 update_outputs(struct drm_compositor *ec, struct udev_device *drm_device)
 {
 	drmModeConnector *connector;
@@ -2652,6 +2700,22 @@ renderer_switch_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
 	switch_to_gl_renderer(c);
 }
 
+static void
+randr_init(struct weston_compositor *ec)
+{
+	/* Initialize randr */
+	ec->randr = zalloc(sizeof *(ec->randr));
+	if (!ec->randr)
+		return;
+
+	ec->randr->get_disoutputs = get_disoutputs;
+
+	if (weston_randr_init(ec->randr, ec) < 0) {
+		free(ec->randr);
+		weston_log("Failed to initialize randr interface.\n");
+	}
+}
+
 static struct weston_compositor *
 drm_compositor_create(struct wl_display *display,
 		      struct drm_parameters *param,
@@ -2769,6 +2833,9 @@ drm_compositor_create(struct wl_display *display,
 		goto err_sprite;
 	}
 
+	/* Initialize randr */
+	randr_init(&ec->base);
+
 	loop = wl_display_get_event_loop(ec->base.wl_display);
 	ec->drm_source =
 		wl_event_loop_add_fd(loop, ec->drm.fd,
-- 
1.8.1.2



More information about the wayland-devel mailing list