[RFC weston 2/2] compositor-x11: Use event loop abstraction API

Quentin Glidic sardemff7+wayland at sardemff7.net
Mon Feb 19 19:19:05 UTC 2018


From: Quentin Glidic <sardemff7+git at sardemff7.net>

Signed-off-by: Quentin Glidic <sardemff7+git at sardemff7.net>
---
 libweston/compositor-x11.c | 64 +++++++++++++++++++++-------------------------
 1 file changed, 29 insertions(+), 35 deletions(-)

diff --git a/libweston/compositor-x11.c b/libweston/compositor-x11.c
index 14faeda03..7675b7275 100644
--- a/libweston/compositor-x11.c
+++ b/libweston/compositor-x11.c
@@ -81,7 +81,7 @@ struct x11_backend {
 	xcb_screen_t		*screen;
 	xcb_cursor_t		 null_cursor;
 	struct wl_array		 keys;
-	struct wl_event_source	*xcb_source;
+	void			*xcb_source;
 	struct xkb_keymap	*xkb_keymap;
 	unsigned int		 has_xkb;
 	uint8_t			 xkb_event_base;
@@ -122,7 +122,7 @@ struct x11_output {
 	xcb_window_t		window;
 	struct weston_mode	mode;
 	struct weston_mode	native;
-	struct wl_event_source *finish_frame_timer;
+	void		       *finish_frame_timer;
 
 	xcb_gc_t		gc;
 	xcb_shm_seg_t		segment;
@@ -411,7 +411,9 @@ x11_output_repaint_gl(struct weston_output *output_base,
 	pixman_region32_subtract(&ec->primary_plane.damage,
 				 &ec->primary_plane.damage, damage);
 
-	wl_event_source_timer_update(output->finish_frame_timer, 10);
+	weston_compositor_event_source_update_timeout(ec,
+						      output->finish_frame_timer,
+						      10);
 	return 0;
 }
 
@@ -498,11 +500,13 @@ x11_output_repaint_shm(struct weston_output *output_base,
 		free(err);
 	}
 
-	wl_event_source_timer_update(output->finish_frame_timer, 10);
+	weston_compositor_event_source_update_timeout(ec,
+						      output->finish_frame_timer,
+						      10);
 	return 0;
 }
 
-static int
+static enum weston_event_source_status
 finish_frame_handler(void *data)
 {
 	struct x11_output *output = data;
@@ -511,7 +515,7 @@ finish_frame_handler(void *data)
 	weston_compositor_read_presentation_clock(output->base.compositor, &ts);
 	weston_output_finish_frame(&output->base, &ts, 0);
 
-	return 1;
+	return WESTON_EVENT_SOURCE_CONTINUE;
 }
 
 static void
@@ -874,7 +878,8 @@ x11_output_disable(struct weston_output *base)
 	if (!output->base.enabled)
 		return 0;
 
-	wl_event_source_remove(output->finish_frame_timer);
+	weston_compositor_event_source_remove(base->compositor,
+					      output->finish_frame_timer);
 
 	if (backend->use_pixman) {
 		pixman_renderer_output_destroy(&output->base);
@@ -1044,7 +1049,11 @@ x11_output_enable(struct weston_output *base)
 
 	loop = wl_display_get_event_loop(b->compositor->wl_display);
 	output->finish_frame_timer =
-		wl_event_loop_add_timer(loop, finish_frame_handler, output);
+		weston_compositor_event_source_add_timeout(base->compositor,
+							   WESTON_EVENT_SOURCE_PRIORITY_TIMEOUT,
+							   0,
+							   finish_frame_handler,
+							   output);
 
 	weston_log("x11 output %dx%d, window id %d\n",
 		   output->base.current_mode->width,
@@ -1394,20 +1403,8 @@ x11_backend_deliver_enter_event(struct x11_backend *b,
 	b->prev_y = y;
 }
 
-static int
-x11_backend_next_event(struct x11_backend *b,
-		       xcb_generic_event_t **event, uint32_t mask)
-{
-	if (mask & WL_EVENT_READABLE)
-		*event = xcb_poll_for_event(b->conn);
-	else
-		*event = xcb_poll_for_queued_event(b->conn);
-
-	return *event != NULL;
-}
-
-static int
-x11_backend_handle_event(int fd, uint32_t mask, void *data)
+static enum weston_event_source_status
+x11_backend_handle_event(int fd, enum weston_event_source_fd_events mask, void *data)
 {
 	struct x11_backend *b = data;
 	struct x11_output *output;
@@ -1424,12 +1421,10 @@ x11_backend_handle_event(int fd, uint32_t mask, void *data)
 	uint32_t *k;
 	uint32_t i, set;
 	uint8_t response_type;
-	int count;
 	struct timespec time;
 
 	prev = NULL;
-	count = 0;
-	while (x11_backend_next_event(b, &event, mask)) {
+	while ((event = xcb_poll_for_event(b->conn)) != NULL) {
 		response_type = event->response_type & ~0x80;
 
 		switch (prev ? prev->response_type & ~0x80 : 0x80) {
@@ -1637,7 +1632,6 @@ x11_backend_handle_event(int fd, uint32_t mask, void *data)
 		}
 #endif
 
-		count++;
 		if (prev != event)
 			free (event);
 	}
@@ -1659,7 +1653,7 @@ x11_backend_handle_event(int fd, uint32_t mask, void *data)
 		break;
 	}
 
-	return count;
+	return WESTON_EVENT_SOURCE_CONTINUE;
 }
 
 #define F(field) offsetof(struct x11_backend, field)
@@ -1747,7 +1741,8 @@ x11_destroy(struct weston_compositor *ec)
 {
 	struct x11_backend *backend = to_x11_backend(ec);
 
-	wl_event_source_remove(backend->xcb_source);
+	weston_compositor_event_source_remove(backend->compositor,
+					      backend->xcb_source);
 	x11_input_destroy(backend);
 
 	weston_compositor_shutdown(ec); /* destroys outputs, too */
@@ -1783,7 +1778,6 @@ x11_backend_create(struct weston_compositor *compositor,
 		   struct weston_x11_backend_config *config)
 {
 	struct x11_backend *b;
-	struct wl_event_loop *loop;
 	int ret;
 
 	b = zalloc(sizeof *b);
@@ -1840,13 +1834,13 @@ x11_backend_create(struct weston_compositor *compositor,
 		goto err_renderer;
 	}
 
-	loop = wl_display_get_event_loop(compositor->wl_display);
 	b->xcb_source =
-		wl_event_loop_add_fd(loop,
-				     xcb_get_file_descriptor(b->conn),
-				     WL_EVENT_READABLE,
-				     x11_backend_handle_event, b);
-	wl_event_source_check(b->xcb_source);
+		weston_compositor_event_source_add_fd(compositor,
+						      WESTON_EVENT_SOURCE_PRIORITY_DEFAULT,
+						      xcb_get_file_descriptor(b->conn),
+						      WESTON_EVENT_SOURCE_FD_IN,
+						      x11_backend_handle_event,
+						      b);
 
 	if (compositor->renderer->import_dmabuf) {
 		if (linux_dmabuf_setup(compositor) < 0)
-- 
2.15.1



More information about the wayland-devel mailing list