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

Submitted by Quentin Glidic on Feb. 19, 2018, 7:19 p.m.

Details

Message ID 20180219191905.23769-3-sardemff7+wayland@sardemff7.net
State New
Headers show
Series "Event loop abstraction API" ( rev: 1 ) in Wayland

Not browsing as part of any series.

Commit Message

Quentin Glidic Feb. 19, 2018, 7:19 p.m.
From: Quentin Glidic <sardemff7+git@sardemff7.net>

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

Patch hide | download patch | download mbox

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)

Comments

On Mon, 19 Feb 2018 20:19:05 +0100
Quentin Glidic <sardemff7+wayland@sardemff7.net> wrote:

> From: Quentin Glidic <sardemff7+git@sardemff7.net>
> 
> Signed-off-by: Quentin Glidic <sardemff7+git@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;

Instead of void*, we should have a unique opaque pointer type. It does
not matter if the actual struct does not exist at all, we do that in
libwayland-client extensively.

It would be good for the pointer type to make it "impossible" to call
an API function that is not meant for the event source type.

>  
>  	xcb_gc_t		gc;
>  	xcb_shm_seg_t		segment;

> @@ -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)

What does the equivalent of wl_event_sourche_check(), or can we just
remove all the calls in upstream already?


Thanks,
pq