[PATCH weston 1/2] Split weston_compositor_init into base and _gl
Kristian Høgsberg
hoegsberg at gmail.com
Fri Jun 22 12:13:47 PDT 2012
On Fri, Jun 22, 2012 at 02:04:36PM +0100, Daniel Stone wrote:
> weston_compositor_init is always called late because most
> implementations can't initialise GL until fairly late in the game.
> Split it into a base version with the same name, followed by
> weston_compositor_init_gl which can be called later on.
Thanks, that looks good, happy to be able to do
weston_compositor_init() right after malloc.
Kristian
> This simplifies compositor-wayland, which no longer needs a separate
> global handler just for wl_seat.
>
> Signed-off-by: Daniel Stone <daniel at fooishbar.org>
> ---
> src/compositor-android.c | 7 ++++--
> src/compositor-drm.c | 10 ++++----
> src/compositor-openwfd.c | 7 ++++--
> src/compositor-wayland.c | 36 ++++++++--------------------
> src/compositor-x11.c | 8 ++++---
> src/compositor.c | 58 ++++++++++++++++++++++++++--------------------
> src/compositor.h | 2 ++
> 7 files changed, 66 insertions(+), 62 deletions(-)
>
> diff --git a/src/compositor-android.c b/src/compositor-android.c
> index 02c5224..54cfa2e 100644
> --- a/src/compositor-android.c
> +++ b/src/compositor-android.c
> @@ -417,6 +417,10 @@ android_compositor_create(struct wl_display *display, int argc, char *argv[],
> if (compositor == NULL)
> return NULL;
>
> + if (weston_compositor_init(&compositor->base, display, argc, argv,
> + config_file) < 0)
> + return NULL;
> +
> compositor->base.destroy = android_compositor_destroy;
>
> compositor->base.focus = 1;
> @@ -430,8 +434,7 @@ android_compositor_create(struct wl_display *display, int argc, char *argv[],
> if (android_init_egl(compositor, output) < 0)
> return NULL;
>
> - if (weston_compositor_init(&compositor->base, display, argc, argv,
> - config_file) < 0)
> + if (weston_compositor_init_gl(&compositor->base) < 0)
> return NULL;
>
> android_compositor_add_output(compositor, output);
> diff --git a/src/compositor-drm.c b/src/compositor-drm.c
> index 2aa2ab0..8309715 100644
> --- a/src/compositor-drm.c
> +++ b/src/compositor-drm.c
> @@ -1774,8 +1774,12 @@ drm_compositor_create(struct wl_display *display,
> ec = malloc(sizeof *ec);
> if (ec == NULL)
> return NULL;
> -
> memset(ec, 0, sizeof *ec);
> +
> + if (weston_compositor_init(&ec->base, display, argc, argv,
> + config_file) < 0)
> + return NULL;
> +
> ec->udev = udev_new();
> if (ec->udev == NULL) {
> weston_log("failed to initialize udev context\n");
> @@ -1826,9 +1830,7 @@ drm_compositor_create(struct wl_display *display,
>
> ec->prev_state = WESTON_COMPOSITOR_ACTIVE;
>
> - /* Can't init base class until we have a current egl context */
> - if (weston_compositor_init(&ec->base, display, argc, argv,
> - config_file) < 0)
> + if (weston_compositor_init_gl(&ec->base) < 0)
> return NULL;
>
> for (key = KEY_F1; key < KEY_F9; key++)
> diff --git a/src/compositor-openwfd.c b/src/compositor-openwfd.c
> index d6616f5..38bdd35 100644
> --- a/src/compositor-openwfd.c
> +++ b/src/compositor-openwfd.c
> @@ -612,6 +612,10 @@ wfd_compositor_create(struct wl_display *display,
>
> memset(ec, 0, sizeof *ec);
>
> + /* XXX: This is totally broken and doesn't even compile. */
> + if (weston_compositor_init(&ec->base, display) < 0)
> + return NULL;
> +
> gettimeofday(&tv, NULL);
> ec->start_time = tv.tv_sec * 1000 + tv.tv_usec / 1000;
>
> @@ -645,8 +649,7 @@ wfd_compositor_create(struct wl_display *display,
> glGenFramebuffers(1, &ec->base.fbo);
> glBindFramebuffer(GL_FRAMEBUFFER, ec->base.fbo);
>
> - /* Can't init base class until we have a current egl context */
> - if (weston_compositor_init(&ec->base, display) < 0)
> + if (weston_compositor_init_gl(&ec->base) < 0)
> return NULL;
>
> if (create_outputs(ec, connector) < 0) {
> diff --git a/src/compositor-wayland.c b/src/compositor-wayland.c
> index 3fee7c1..ea09730 100644
> --- a/src/compositor-wayland.c
> +++ b/src/compositor-wayland.c
> @@ -759,22 +759,6 @@ display_add_seat(struct wayland_compositor *c, uint32_t id)
> wl_seat_set_user_data(input->seat, input);
> }
>
> -/* We can't start adding input devices until weston_compositor_init, but
> - * also can't call weston_compositor_init until we've handled some of the
> - * base display code first. So, we have a separate global handler for
> - * seats. */
> -static void
> -display_handle_global_input(struct wl_display *display, uint32_t id,
> - const char *interface, uint32_t version,
> - void *data)
> -{
> - struct wayland_compositor *c = data;
> -
> - if (strcmp(interface, "wl_seat") == 0)
> - display_add_seat(c, id);
> -}
> -
> -
> static void
> display_handle_global(struct wl_display *display, uint32_t id,
> const char *interface, uint32_t version, void *data)
> @@ -791,6 +775,8 @@ display_handle_global(struct wl_display *display, uint32_t id,
> } else if (strcmp(interface, "wl_shell") == 0) {
> c->parent.shell =
> wl_display_bind(display, id, &wl_shell_interface);
> + } else if (strcmp(interface, "wl_seat") == 0) {
> + display_add_seat(c, id);
> }
> }
>
> @@ -833,10 +819,6 @@ wayland_input_create(struct wayland_compositor *c)
>
> c->base.seat = seat;
>
> - wl_display_add_global_listener(c->parent.wl_display,
> - display_handle_global_input,
> - c);
> -
> return 0;
> }
>
> @@ -863,6 +845,13 @@ wayland_compositor_create(struct wl_display *display,
>
> memset(c, 0, sizeof *c);
>
> + if (weston_compositor_init(&c->base, display, argc, argv,
> + config_file) < 0)
> + return NULL;
> +
> + if (wayland_input_create(c) < 0)
> + return NULL;
> +
> c->parent.wl_display = wl_display_connect(display_name);
>
> if (c->parent.wl_display == NULL) {
> @@ -882,18 +871,13 @@ wayland_compositor_create(struct wl_display *display,
>
> c->base.destroy = wayland_destroy;
>
> - /* Can't init base class until we have a current egl context */
> - if (weston_compositor_init(&c->base, display, argc, argv,
> - config_file) < 0)
> + if (weston_compositor_init_gl(&c->base) < 0)
> return NULL;
>
> create_border(c);
> if (wayland_compositor_create_output(c, width, height) < 0)
> return NULL;
>
> - if (wayland_input_create(c) < 0)
> - return NULL;
> -
> loop = wl_display_get_event_loop(c->base.wl_display);
>
> fd = wl_display_get_fd(c->parent.wl_display, update_event_mask, c);
> diff --git a/src/compositor-x11.c b/src/compositor-x11.c
> index a039269..9c46b27 100644
> --- a/src/compositor-x11.c
> +++ b/src/compositor-x11.c
> @@ -1060,6 +1060,10 @@ x11_compositor_create(struct wl_display *display,
>
> memset(c, 0, sizeof *c);
>
> + if (weston_compositor_init(&c->base, display, argc, argv,
> + config_file) < 0)
> + return NULL;
> +
> c->dpy = XOpenDisplay(NULL);
> if (c->dpy == NULL)
> return NULL;
> @@ -1082,9 +1086,7 @@ x11_compositor_create(struct wl_display *display,
>
> c->base.destroy = x11_destroy;
>
> - /* Can't init base class until we have a current egl context */
> - if (weston_compositor_init(&c->base, display, argc, argv,
> - config_file) < 0)
> + if (weston_compositor_init_gl(&c->base) < 0)
> return NULL;
>
> if (x11_input_create(c, no_input) < 0)
> diff --git a/src/compositor.c b/src/compositor.c
> index b57d10b..eb795a2 100644
> --- a/src/compositor.c
> +++ b/src/compositor.c
> @@ -2988,7 +2988,6 @@ weston_compositor_init(struct weston_compositor *ec,
> const char *config_file)
> {
> struct wl_event_loop *loop;
> - const char *extensions;
> struct xkb_rule_names xkb_names;
> const struct config_key keyboard_config_keys[] = {
> { "keymap_rules", CONFIG_KEY_STRING, &xkb_names.rules },
> @@ -3020,8 +3019,41 @@ weston_compositor_init(struct weston_compositor *ec,
> ec, compositor_bind))
> return -1;
>
> + wl_list_init(&ec->surface_list);
> + wl_list_init(&ec->layer_list);
> + wl_list_init(&ec->seat_list);
> + wl_list_init(&ec->output_list);
> + wl_list_init(&ec->key_binding_list);
> + wl_list_init(&ec->button_binding_list);
> + wl_list_init(&ec->axis_binding_list);
> + wl_list_init(&ec->fade.animation.link);
> +
> + weston_compositor_xkb_init(ec, &xkb_names);
> +
> + ec->ping_handler = NULL;
> +
> + screenshooter_create(ec);
> + text_cursor_position_notifier_create(ec);
> + input_method_create(ec);
> +
> + wl_data_device_manager_init(ec->wl_display);
> +
> wl_display_init_shm(display);
>
> + loop = wl_display_get_event_loop(ec->wl_display);
> + ec->idle_source = wl_event_loop_add_timer(loop, idle_handler, ec);
> + wl_event_source_timer_update(ec->idle_source, ec->idle_time * 1000);
> +
> + ec->input_loop = wl_event_loop_create();
> +
> + return 0;
> +}
> +
> +WL_EXPORT int
> +weston_compositor_init_gl(struct weston_compositor *ec)
> +{
> + const char *extensions;
> +
> log_egl_gl_info(ec->egl_display);
>
> ec->image_target_texture_2d =
> @@ -3066,28 +3098,12 @@ weston_compositor_init(struct weston_compositor *ec,
> if (ec->has_bind_display)
> ec->bind_display(ec->egl_display, ec->wl_display);
>
> - wl_list_init(&ec->surface_list);
> - wl_list_init(&ec->layer_list);
> - wl_list_init(&ec->seat_list);
> - wl_list_init(&ec->output_list);
> - wl_list_init(&ec->key_binding_list);
> - wl_list_init(&ec->button_binding_list);
> - wl_list_init(&ec->axis_binding_list);
> weston_spring_init(&ec->fade.spring, 30.0, 1.0, 1.0);
> ec->fade.animation.frame = fade_frame;
> - wl_list_init(&ec->fade.animation.link);
>
> weston_layer_init(&ec->fade_layer, &ec->layer_list);
> weston_layer_init(&ec->cursor_layer, &ec->fade_layer.link);
>
> - screenshooter_create(ec);
> - text_cursor_position_notifier_create(ec);
> - input_method_create(ec);
> -
> - ec->ping_handler = NULL;
> -
> - wl_data_device_manager_init(ec->wl_display);
> -
> glActiveTexture(GL_TEXTURE0);
>
> if (weston_shader_init(&ec->texture_shader,
> @@ -3097,14 +3113,6 @@ weston_compositor_init(struct weston_compositor *ec,
> vertex_shader, solid_fragment_shader) < 0)
> return -1;
>
> - weston_compositor_xkb_init(ec, &xkb_names);
> -
> - loop = wl_display_get_event_loop(ec->wl_display);
> - ec->idle_source = wl_event_loop_add_timer(loop, idle_handler, ec);
> - wl_event_source_timer_update(ec->idle_source, ec->idle_time * 1000);
> -
> - ec->input_loop = wl_event_loop_create();
> -
> weston_compositor_schedule_repaint(ec);
>
> return 0;
> diff --git a/src/compositor.h b/src/compositor.h
> index 14420c5..4e2d305 100644
> --- a/src/compositor.h
> +++ b/src/compositor.h
> @@ -645,6 +645,8 @@ weston_compositor_get_time(void);
> int
> weston_compositor_init(struct weston_compositor *ec, struct wl_display *display,
> int argc, char *argv[], const char *config_file);
> +int
> +weston_compositor_init_gl(struct weston_compositor *ec);
> void
> weston_compositor_shutdown(struct weston_compositor *ec);
> void
> --
> 1.7.10
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
More information about the wayland-devel
mailing list