wayland-drm: Drop the non-premul formats, use format codes from drm_fourcc.h
[mesa.git] / src / gallium / state_trackers / egl / wayland / native_shm.c
index 018fbe8e0efadec77381e55f4679df22711b865f..b76e5db33db734073792421032734dff243961af 100644 (file)
@@ -63,8 +63,8 @@ wayland_shm_display_destroy(struct native_display *ndpy)
 {
    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);
 
@@ -73,7 +73,6 @@ wayland_shm_display_destroy(struct native_display *ndpy)
    FREE(shmdpy);
 }
 
-
 static struct wl_buffer *
 wayland_create_shm_buffer(struct wayland_display *display,
                           struct wayland_surface *surface,
@@ -84,7 +83,7 @@ wayland_create_shm_buffer(struct wayland_display *display,
    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);
@@ -93,22 +92,43 @@ wayland_create_shm_buffer(struct wayland_display *display,
 
    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)
 {
@@ -127,6 +147,13 @@ wayland_shm_display_init_screen(struct native_display *ndpy)
    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;