From c5c510ec7523efc60d955d5daa8df3776c35e65a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= Date: Wed, 8 Dec 2010 15:12:58 -0500 Subject: [PATCH] Set up visuals in wayland-server Still very much hand-wavey, but at least it's only in one place now. --- compositor/compositor.c | 41 ++++++---------------------------------- compositor/compositor.h | 1 - compositor/drm.c | 6 +++--- compositor/shm.c | 6 +++--- wayland/wayland-server.c | 35 ++++++++++++++++++++++++++++++++++ wayland/wayland-server.h | 15 +++++++++++---- 6 files changed, 58 insertions(+), 46 deletions(-) diff --git a/compositor/compositor.c b/compositor/compositor.c index e10404d5..e134ce4e 100644 --- a/compositor/compositor.c +++ b/compositor/compositor.c @@ -251,7 +251,7 @@ create_pointer_images(struct wlsc_compositor *ec) for (i = 0; i < count; i++) { ec->pointer_buffers[i] = wlsc_drm_buffer_create(ec, width, height, - &ec->argb_visual); + &ec->compositor.argb_visual); glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, ec->pointer_buffers[i]->image); texture_from_png(pointer_images[i].filename, width, height); @@ -268,7 +268,7 @@ background_create(struct wlsc_output *output, const char *filename) GLenum format; background = wlsc_surface_create(output->compositor, - &output->compositor->rgb_visual, + &output->compositor->compositor.rgb_visual, output->x, output->y, output->width, output->height); if (background == NULL) @@ -308,10 +308,10 @@ wlsc_surface_draw(struct wlsc_surface *es, struct wlsc_output *output) glUniformMatrix4fv(ec->proj_uniform, 1, GL_FALSE, tmp.d); glUniform1i(ec->tex_uniform, 0); - if (es->visual == &ec->argb_visual) { + if (es->visual == &ec->compositor.argb_visual) { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); - } else if (es->visual == &ec->premultiplied_argb_visual) { + } else if (es->visual == &ec->compositor.premultiplied_argb_visual) { glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); } else { @@ -1303,7 +1303,7 @@ wlsc_input_device_init(struct wlsc_input_device *device, wl_display_add_object(ec->wl_display, &device->input_device.object); wl_display_add_global(ec->wl_display, &device->input_device.object, NULL); - device->sprite = wlsc_surface_create(ec, &ec->argb_visual, + device->sprite = wlsc_surface_create(ec, &ec->compositor.argb_visual, device->input_device.x, device->input_device.y, 32, 32); device->hotspot_x = 16; @@ -1428,27 +1428,6 @@ init_shaders(struct wlsc_compositor *ec) return 0; } -static void -add_visuals(struct wlsc_compositor *ec) -{ - ec->argb_visual.object.interface = &wl_visual_interface; - ec->argb_visual.object.implementation = NULL; - wl_display_add_object(ec->wl_display, &ec->argb_visual.object); - wl_display_add_global(ec->wl_display, &ec->argb_visual.object, NULL); - - ec->premultiplied_argb_visual.object.interface = &wl_visual_interface; - ec->premultiplied_argb_visual.object.implementation = NULL; - wl_display_add_object(ec->wl_display, - &ec->premultiplied_argb_visual.object); - wl_display_add_global(ec->wl_display, - &ec->premultiplied_argb_visual.object, NULL); - - ec->rgb_visual.object.interface = &wl_visual_interface; - ec->rgb_visual.object.implementation = NULL; - wl_display_add_object(ec->wl_display, &ec->rgb_visual.object); - wl_display_add_global(ec->wl_display, &ec->rgb_visual.object, NULL); -} - void wlsc_output_init(struct wlsc_output *output, struct wlsc_compositor *c, int x, int y, int width, int height) @@ -1482,13 +1461,7 @@ wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display) ec->wl_display = display; - ec->compositor.object.interface = &wl_compositor_interface; - ec->compositor.object.implementation = - (void (**)(void)) &compositor_interface; - - wl_display_add_object(display, &ec->compositor.object); - if (wl_display_add_global(display, &ec->compositor.object, NULL)) - return -1; + wl_compositor_init(&ec->compositor, &compositor_interface, display); wlsc_shm_init(ec); @@ -1498,8 +1471,6 @@ wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display) if (wl_display_add_global(display, &ec->shell.object, NULL)) return -1; - add_visuals(ec); - wl_list_init(&ec->surface_list); wl_list_init(&ec->input_device_list); wl_list_init(&ec->output_list); diff --git a/compositor/compositor.h b/compositor/compositor.h index 9731a08a..1a33cb1e 100644 --- a/compositor/compositor.h +++ b/compositor/compositor.h @@ -112,7 +112,6 @@ struct wlsc_shm_buffer { struct wlsc_compositor { struct wl_compositor compositor; - struct wl_visual argb_visual, premultiplied_argb_visual, rgb_visual; struct wlsc_drm drm; struct wlsc_shm shm; diff --git a/compositor/drm.c b/compositor/drm.c index 5d50ab7c..d0eab292 100644 --- a/compositor/drm.c +++ b/compositor/drm.c @@ -121,9 +121,9 @@ drm_create_buffer(struct wl_client *client, struct wl_drm *drm_base, EGL_NONE }; - if (visual != &compositor->argb_visual && - visual != &compositor->premultiplied_argb_visual && - visual != &compositor->rgb_visual) { + if (visual != &compositor->compositor.argb_visual && + visual != &compositor->compositor.premultiplied_argb_visual && + visual != &compositor->compositor.rgb_visual) { /* FIXME: Define a real exception event instead of * abusing this one */ wl_client_post_event(client, diff --git a/compositor/shm.c b/compositor/shm.c index 023cde09..4f31bd4b 100644 --- a/compositor/shm.c +++ b/compositor/shm.c @@ -92,9 +92,9 @@ shm_create_buffer(struct wl_client *client, struct wl_shm *shm, struct wlsc_compositor, shm); struct wlsc_shm_buffer *buffer; - if (visual != &compositor->argb_visual && - visual != &compositor->premultiplied_argb_visual && - visual != &compositor->rgb_visual) { + if (visual != &compositor->compositor.argb_visual && + visual != &compositor->compositor.premultiplied_argb_visual && + visual != &compositor->compositor.rgb_visual) { /* FIXME: Define a real exception event instead of * abusing this one */ wl_client_post_event(client, diff --git a/wayland/wayland-server.c b/wayland/wayland-server.c index 3da95b10..8cc2eae5 100644 --- a/wayland/wayland-server.c +++ b/wayland/wayland-server.c @@ -629,3 +629,38 @@ wl_display_add_socket(struct wl_display *display, const char *name) return 0; } + +WL_EXPORT int +wl_compositor_init(struct wl_compositor *compositor, + const struct wl_compositor_interface *interface, + struct wl_display *display) +{ + compositor->object.interface = &wl_compositor_interface; + compositor->object.implementation = (void (**)(void)) interface; + wl_display_add_object(display, &compositor->object); + if (wl_display_add_global(display, &compositor->object, NULL)) + return -1; + + compositor->argb_visual.object.interface = &wl_visual_interface; + compositor->argb_visual.object.implementation = NULL; + wl_display_add_object(display, &compositor->argb_visual.object); + wl_display_add_global(display, &compositor->argb_visual.object, NULL); + + compositor->premultiplied_argb_visual.object.interface = + &wl_visual_interface; + compositor->premultiplied_argb_visual.object.implementation = NULL; + wl_display_add_object(display, + &compositor->premultiplied_argb_visual.object); + wl_display_add_global(display, + &compositor->premultiplied_argb_visual.object, + NULL); + + compositor->rgb_visual.object.interface = &wl_visual_interface; + compositor->rgb_visual.object.implementation = NULL; + wl_display_add_object(display, + &compositor->rgb_visual.object); + wl_display_add_global(display, + &compositor->rgb_visual.object, NULL); + + return 0; +} diff --git a/wayland/wayland-server.h b/wayland/wayland-server.h index b911f1b3..f0f321bc 100644 --- a/wayland/wayland-server.h +++ b/wayland/wayland-server.h @@ -91,8 +91,15 @@ void wl_client_destroy(struct wl_client *client); void wl_client_post_no_memory(struct wl_client *client); void wl_client_post_global(struct wl_client *client, struct wl_object *object); +struct wl_visual { + struct wl_object object; +}; + struct wl_compositor { struct wl_object object; + struct wl_visual argb_visual; + struct wl_visual premultiplied_argb_visual; + struct wl_visual rgb_visual; }; struct wl_resource { @@ -129,10 +136,6 @@ struct wl_shell { struct wl_object object; }; -struct wl_visual { - struct wl_object object; -}; - struct wl_grab; struct wl_grab_interface { void (*motion)(struct wl_grab *grab, @@ -224,6 +227,10 @@ wl_input_device_set_keyboard_focus(struct wl_input_device *device, struct wl_surface *surface, uint32_t time); +int +wl_compositor_init(struct wl_compositor *compositor, + const struct wl_compositor_interface *interface, + struct wl_display *display); #ifdef __cplusplus }