struct wayland_shm_display {
struct wayland_display base;
- struct native_event_handler *event_handler;
+ const struct native_event_handler *event_handler;
struct wl_shm *wl_shm;
};
{
struct wayland_shm_display *shmdpy = wayland_shm_display(ndpy);
- if (shmdpy->base.config)
- FREE(shmdpy->base.config);
+ if (shmdpy->base.configs)
+ FREE(shmdpy->base.configs);
if (shmdpy->base.own_dpy)
wl_display_destroy(shmdpy->base.dpy);
FREE(shmdpy);
}
-
static struct wl_buffer *
wayland_create_shm_buffer(struct wayland_display *display,
struct wayland_surface *surface,
struct pipe_resource *resource;
struct winsys_handle wsh;
uint width, height;
- struct wl_visual *visual;
+ enum wl_shm_format format;
resource = resource_surface_get_single_resource(surface->rsurf, attachment);
resource_surface_get_size(surface->rsurf, &width, &height);
pipe_resource_reference(&resource, NULL);
- switch (surface->type) {
- case WL_WINDOW_SURFACE:
- visual = surface->win->visual;
+ switch (surface->color_format) {
+ case PIPE_FORMAT_B8G8R8A8_UNORM:
+ format = (surface->premultiplied_alpha) ?
+ WL_SHM_FORMAT_PREMULTIPLIED_ARGB32 : WL_SHM_FORMAT_ARGB32;
break;
- case WL_PIXMAP_SURFACE:
- visual = surface->pix->visual;
+ case PIPE_FORMAT_B8G8R8X8_UNORM:
+ format = WL_SHM_FORMAT_XRGB32;
break;
default:
return NULL;
+ break;
}
return wl_shm_create_buffer(shmdpy->wl_shm, wsh.fd,
width, height,
- wsh.stride, visual);
+ wsh.stride, format);
+}
+
+static void
+shm_handle_format(void *data, struct wl_shm *shm, uint32_t format)
+{
+ struct wayland_shm_display *shmdpy = data;
+
+ switch (format) {
+ case WL_SHM_FORMAT_ARGB32:
+ shmdpy->base.formats |= HAS_ARGB8888;
+ break;
+ case WL_SHM_FORMAT_XRGB8888:
+ shmdpy->base.formats |= HAS_XRGB8888;
+ break;
+ }
}
+static const struct wl_shm_listener shm_listener = {
+ shm_handle_format
+};
+
static boolean
wayland_shm_display_init_screen(struct native_display *ndpy)
{
if (id == 0)
return FALSE;
- shmdpy->wl_shm = wl_shm_create(shmdpy->base.dpy, id, 1);
+ shmdpy->wl_shm = wl_display_bind(shmdpy->base.dpy, id, &wl_shm_interface);
if (!shmdpy->wl_shm)
return FALSE;
+ wl_shm_add_listener(shmdpy->wl_shm, &shm_listener, shmdpy);
+
+ if (shmdpy->base.formats == 0)
+ wl_display_roundtrip(shmdpy->base.dpy);
+ if (shmdpy->base.formats == 0)
+ return FALSE;
+
winsys = wayland_create_sw_winsys(shmdpy->base.dpy);
if (!winsys)
return FALSE;
struct wayland_display *
wayland_create_shm_display(struct wl_display *dpy,
- struct native_event_handler *event_handler,
- void *user_data)
+ const struct native_event_handler *event_handler)
{
struct wayland_shm_display *shmdpy;
return NULL;
shmdpy->event_handler = event_handler;
- shmdpy->base.base.user_data = user_data;
shmdpy->base.dpy = dpy;
if (!shmdpy->base.dpy) {
return NULL;
}
- if (!wayland_shm_display_init_screen(&shmdpy->base.base)) {
- wayland_shm_display_destroy(&shmdpy->base.base);
- return NULL;
- }
-
+ shmdpy->base.base.init_screen = wayland_shm_display_init_screen;
shmdpy->base.base.destroy = wayland_shm_display_destroy;
shmdpy->base.create_buffer = wayland_create_shm_buffer;