[Mesa-dev] [PATCH v2] gallium-egl: Simplify native_wayland_drm_bufmgr_helper interface

Ander Conselvan de Oliveira ander.conselvan.de.oliveira at intel.com
Fri Jul 19 01:15:09 PDT 2013


The helper provides a series of functions to easy the implementation
of the WL_bind_wayland_display extension on different platforms. But
even with the helpers there was still a bit of duplicated code between
platforms, with the drm authentication being the only part that
differs.

This patch changes the bufmgr interface to provide a self contained
object with a create function that takes a drm authentication callback
as an argument. That way all the helper functions are made static and
the "_helper" suffix was removed from the sources file name.

This change also removes the mix of Wayland client and server code in
the wayland drm platform source file. All the uses of libwayland-server
are now contained in native_wayland_drm_bufmgr.c.

v2: - guard calls to wayland_drm_bufmgr_destroy() with ifdefs;
    - delete now unused fields wl_server_drm from dri2_display in x11
      and drm_display in drm.
---
 src/gallium/state_trackers/egl/Makefile.am         |   2 +-
 src/gallium/state_trackers/egl/common/native.h     |   2 +-
 .../egl/common/native_wayland_drm_bufmgr.c         | 214 +++++++++++++++++++++
 .../egl/common/native_wayland_drm_bufmgr.h         |  37 ++++
 .../egl/common/native_wayland_drm_bufmgr_helper.c  | 106 ----------
 .../egl/common/native_wayland_drm_bufmgr_helper.h  |  47 -----
 src/gallium/state_trackers/egl/drm/native_drm.c    |  54 +-----
 src/gallium/state_trackers/egl/drm/native_drm.h    |   6 +-
 .../state_trackers/egl/wayland/native_drm.c        |  93 +++------
 src/gallium/state_trackers/egl/x11/native_dri2.c   |  92 +++------
 10 files changed, 309 insertions(+), 344 deletions(-)
 create mode 100644 src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr.c
 create mode 100644 src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr.h
 delete mode 100644 src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.c
 delete mode 100644 src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.h

diff --git a/src/gallium/state_trackers/egl/Makefile.am b/src/gallium/state_trackers/egl/Makefile.am
index f78b36e..126fafc 100644
--- a/src/gallium/state_trackers/egl/Makefile.am
+++ b/src/gallium/state_trackers/egl/Makefile.am
@@ -38,7 +38,7 @@ libegl_la_SOURCES = \
 	common/egl_g3d_st.c \
 	common/egl_g3d_sync.c \
 	common/native_helper.c \
-	common/native_wayland_drm_bufmgr_helper.c
+	common/native_wayland_drm_bufmgr.c
 
 if HAVE_EGL_PLATFORM_X11
 libegl_la_SOURCES += \
diff --git a/src/gallium/state_trackers/egl/common/native.h b/src/gallium/state_trackers/egl/common/native.h
index 431bd3f..797933d 100644
--- a/src/gallium/state_trackers/egl/common/native.h
+++ b/src/gallium/state_trackers/egl/common/native.h
@@ -245,7 +245,7 @@ struct native_display {
 
    const struct native_display_buffer *buffer;
    const struct native_display_modeset *modeset;
-   const struct native_display_wayland_bufmgr *wayland_bufmgr;
+   struct native_display_wayland_bufmgr *wayland_bufmgr;
 };
 
 /**
diff --git a/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr.c b/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr.c
new file mode 100644
index 0000000..1603a3a
--- /dev/null
+++ b/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr.c
@@ -0,0 +1,214 @@
+#include <stdint.h>
+#include <string.h>
+
+#include "native.h"
+#include "util/u_inlines.h"
+#include "state_tracker/drm_driver.h"
+
+#ifdef HAVE_WAYLAND_BACKEND
+
+#include <wayland-server.h>
+#include <wayland-drm-server-protocol.h>
+
+#include "native_wayland_drm_bufmgr.h"
+
+#include "wayland-drm.h"
+
+struct wayland_drm_bufmgr {
+   struct native_display_wayland_bufmgr base;
+
+   struct wl_drm *wl_server_drm;
+   char *device_name;
+
+   void *user_data;
+
+   wayland_drm_bufmgr_authenticate_func authenticate;
+};
+
+static INLINE struct wayland_drm_bufmgr *
+wayland_drm_bufmgr(const struct native_display_wayland_bufmgr *base)
+{
+   return (struct wayland_drm_bufmgr *) base;
+}
+
+static int
+wayland_drm_bufmgr_authenticate(void *user_data, uint32_t magic)
+{
+   struct native_display *ndpy = user_data;
+   struct wayland_drm_bufmgr *bufmgr;
+
+   bufmgr = wayland_drm_bufmgr(ndpy->wayland_bufmgr);
+
+   return bufmgr->authenticate(user_data, magic);
+}
+
+static void
+wayland_drm_bufmgr_reference_buffer(void *user_data, uint32_t name, int fd,
+                                    struct wl_drm_buffer *buffer)
+{
+   struct native_display *ndpy = user_data;
+   struct pipe_resource templ;
+   struct winsys_handle wsh;
+   enum pipe_format pf;
+
+   switch (buffer->format) {
+   case WL_DRM_FORMAT_ARGB8888:
+      pf = PIPE_FORMAT_B8G8R8A8_UNORM;
+      break;
+   case WL_DRM_FORMAT_XRGB8888:
+      pf = PIPE_FORMAT_B8G8R8X8_UNORM;
+      break;
+   default:
+      pf = PIPE_FORMAT_NONE;
+      break;
+   }
+
+   if (pf == PIPE_FORMAT_NONE)
+      return;
+
+   memset(&templ, 0, sizeof(templ));
+   templ.target = PIPE_TEXTURE_2D;
+   templ.format = pf;
+   templ.bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
+   templ.width0 = buffer->buffer.width;
+   templ.height0 = buffer->buffer.height;
+   templ.depth0 = 1;
+   templ.array_size = 1;
+
+   memset(&wsh, 0, sizeof(wsh));
+   wsh.handle = name;
+   wsh.stride = buffer->stride[0];
+
+   buffer->driver_buffer =
+      ndpy->screen->resource_from_handle(ndpy->screen, &templ, &wsh);
+}
+
+static void
+wayland_drm_bufmgr_unreference_buffer(void *user_data,
+                                      struct wl_drm_buffer *buffer)
+{
+   struct pipe_resource *resource = buffer->driver_buffer;
+
+   pipe_resource_reference(&resource, NULL);
+}
+
+static struct wayland_drm_callbacks wl_drm_callbacks = {
+   wayland_drm_bufmgr_authenticate,
+   wayland_drm_bufmgr_reference_buffer,
+   wayland_drm_bufmgr_unreference_buffer
+};
+
+static boolean
+wayland_drm_bufmgr_bind_display(struct native_display *ndpy,
+                                struct wl_display *wl_dpy)
+{
+   struct wayland_drm_bufmgr *bufmgr;
+
+   bufmgr = wayland_drm_bufmgr(ndpy->wayland_bufmgr);
+
+   if (bufmgr->wl_server_drm)
+      return FALSE;
+
+   bufmgr->wl_server_drm = wayland_drm_init(wl_dpy, bufmgr->device_name,
+         &wl_drm_callbacks, ndpy, 0);
+
+   if (!bufmgr->wl_server_drm)
+      return FALSE;
+
+   return TRUE;
+}
+
+static boolean
+wayland_drm_bufmgr_unbind_display(struct native_display *ndpy,
+                                  struct wl_display *wl_dpy)
+{
+   struct wayland_drm_bufmgr *bufmgr;
+
+   bufmgr = wayland_drm_bufmgr(ndpy->wayland_bufmgr);
+
+   if (!bufmgr->wl_server_drm)
+      return FALSE;
+
+   wayland_drm_uninit(bufmgr->wl_server_drm);
+   bufmgr->wl_server_drm = NULL;
+
+   return TRUE;
+}
+
+static struct pipe_resource *
+wayland_drm_bufmgr_wl_buffer_get_resource(struct native_display *ndpy,
+                                          struct wl_buffer *buffer)
+{
+   return wayland_drm_buffer_get_buffer(buffer);
+}
+
+static EGLBoolean
+wayland_drm_bufmgr_query_buffer(struct native_display *ndpy,
+                                struct wl_buffer *_buffer,
+                                EGLint attribute, EGLint *value)
+{
+   struct wl_drm_buffer *buffer = (struct wl_drm_buffer *) _buffer;
+   struct pipe_resource *resource = buffer->driver_buffer;
+
+   if (!wayland_buffer_is_drm(&buffer->buffer))
+      return EGL_FALSE;
+
+   switch (attribute) {
+   case EGL_TEXTURE_FORMAT:
+      switch (resource->format) {
+      case PIPE_FORMAT_B8G8R8A8_UNORM:
+         *value = EGL_TEXTURE_RGBA;
+         return EGL_TRUE;
+      case PIPE_FORMAT_B8G8R8X8_UNORM:
+         *value = EGL_TEXTURE_RGB;
+         return EGL_TRUE;
+      default:
+         return EGL_FALSE;
+      }
+   case EGL_WIDTH:
+      *value = buffer->buffer.width;
+      return EGL_TRUE;
+   case EGL_HEIGHT:
+      *value = buffer->buffer.height;
+      return EGL_TRUE;
+   default:
+      return EGL_FALSE;
+   }
+}
+
+
+struct native_display_wayland_bufmgr *
+wayland_drm_bufmgr_create(wayland_drm_bufmgr_authenticate_func authenticate,
+                          void *user_data, char *device_name)
+{
+   struct wayland_drm_bufmgr *bufmgr;
+
+   bufmgr = calloc(1, sizeof *bufmgr);
+   if (!bufmgr)
+      return NULL;
+
+   bufmgr->user_data = user_data;
+   bufmgr->authenticate = authenticate;
+   bufmgr->device_name = strdup(device_name);
+
+   bufmgr->base.bind_display = wayland_drm_bufmgr_bind_display;
+   bufmgr->base.unbind_display = wayland_drm_bufmgr_unbind_display;
+   bufmgr->base.buffer_get_resource = wayland_drm_bufmgr_wl_buffer_get_resource;
+   bufmgr->base.query_buffer = wayland_drm_bufmgr_query_buffer;
+
+   return &bufmgr->base;
+}
+
+void
+wayland_drm_bufmgr_destroy(struct native_display_wayland_bufmgr *_bufmgr)
+{
+   struct wayland_drm_bufmgr *bufmgr = wayland_drm_bufmgr(_bufmgr);
+
+   if (!bufmgr)
+      return;
+
+   free(bufmgr->device_name);
+   free(bufmgr);
+}
+
+#endif
diff --git a/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr.h b/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr.h
new file mode 100644
index 0000000..7bf6513
--- /dev/null
+++ b/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr.h
@@ -0,0 +1,37 @@
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (C) 2011 Benjamin Franzke <benjaminfranzke at googlemail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _NATIVE_WAYLAND_DRM_BUFMGR_H_
+#define _NATIVE_WAYLAND_DRM_BUFMGR_H_
+
+typedef int (*wayland_drm_bufmgr_authenticate_func)(void *, uint32_t);
+
+struct native_display_wayland_bufmgr *
+wayland_drm_bufmgr_create(wayland_drm_bufmgr_authenticate_func authenticate,
+                          void *user_data, char *device_name);
+
+void
+wayland_drm_bufmgr_destroy(struct native_display_wayland_bufmgr *bufmgr);
+
+#endif /* _NATIVE_WAYLAND_DRM_BUFMGR_H_ */
diff --git a/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.c b/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.c
deleted file mode 100644
index a9e7342..0000000
--- a/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.c
+++ /dev/null
@@ -1,106 +0,0 @@
-#include <stdint.h>
-#include <string.h>
-
-#include "native.h"
-#include "util/u_inlines.h"
-#include "state_tracker/drm_driver.h"
-
-#ifdef HAVE_WAYLAND_BACKEND
-
-#include <wayland-server.h>
-#include <wayland-drm-server-protocol.h>
-
-#include "native_wayland_drm_bufmgr_helper.h"
-
-void
-egl_g3d_wl_drm_helper_reference_buffer(void *user_data, uint32_t name, int fd,
-                                       struct wl_drm_buffer *buffer)
-{
-   struct native_display *ndpy = user_data;
-   struct pipe_resource templ;
-   struct winsys_handle wsh;
-   enum pipe_format pf;
-
-   switch (buffer->format) {
-   case WL_DRM_FORMAT_ARGB8888:
-      pf = PIPE_FORMAT_B8G8R8A8_UNORM;
-      break;
-   case WL_DRM_FORMAT_XRGB8888:
-      pf = PIPE_FORMAT_B8G8R8X8_UNORM;
-      break;
-   default:
-      pf = PIPE_FORMAT_NONE;
-      break;
-   }
-
-   if (pf == PIPE_FORMAT_NONE)
-      return;
-
-   memset(&templ, 0, sizeof(templ));
-   templ.target = PIPE_TEXTURE_2D;
-   templ.format = pf;
-   templ.bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
-   templ.width0 = buffer->buffer.width;
-   templ.height0 = buffer->buffer.height;
-   templ.depth0 = 1;
-   templ.array_size = 1;
-
-   memset(&wsh, 0, sizeof(wsh));
-   wsh.handle = name;
-   wsh.stride = buffer->stride[0];
-
-   buffer->driver_buffer =
-      ndpy->screen->resource_from_handle(ndpy->screen, &templ, &wsh);
-}
-
-void
-egl_g3d_wl_drm_helper_unreference_buffer(void *user_data,
-                                         struct wl_drm_buffer *buffer)
-{
-   struct pipe_resource *resource = buffer->driver_buffer;
-
-   pipe_resource_reference(&resource, NULL);
-}
-
-struct pipe_resource *
-egl_g3d_wl_drm_common_wl_buffer_get_resource(struct native_display *ndpy,
-                                             struct wl_buffer *buffer)
-{
-   return wayland_drm_buffer_get_buffer(buffer);
-}
-
-EGLBoolean
-egl_g3d_wl_drm_common_query_buffer(struct native_display *ndpy,
-                                   struct wl_buffer *_buffer,
-                                   EGLint attribute, EGLint *value)
-{
-   struct wl_drm_buffer *buffer = (struct wl_drm_buffer *) _buffer;
-   struct pipe_resource *resource = buffer->driver_buffer;
-
-   if (!wayland_buffer_is_drm(&buffer->buffer))
-      return EGL_FALSE;
-
-   switch (attribute) {
-   case EGL_TEXTURE_FORMAT:
-      switch (resource->format) {
-      case PIPE_FORMAT_B8G8R8A8_UNORM:
-         *value = EGL_TEXTURE_RGBA;
-         return EGL_TRUE;
-      case PIPE_FORMAT_B8G8R8X8_UNORM:
-         *value = EGL_TEXTURE_RGB;
-         return EGL_TRUE;
-      default:
-         return EGL_FALSE;
-      }
-   case EGL_WIDTH:
-      *value = buffer->buffer.width;
-      return EGL_TRUE;
-   case EGL_HEIGHT:
-      *value = buffer->buffer.height;
-      return EGL_TRUE;
-   default:
-      return EGL_FALSE;
-   }
-}
-
-#endif
diff --git a/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.h b/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.h
deleted file mode 100644
index 543dc6f..0000000
--- a/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Mesa 3-D graphics library
- *
- * Copyright (C) 2011 Benjamin Franzke <benjaminfranzke at googlemail.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef _NATIVE_WAYLAND_DRM_BUFMGR_HELPER_H_
-#define _NATIVE_WAYLAND_DRM_BUFMGR_HELPER_H_
-
-#include "wayland-drm.h"
-
-void
-egl_g3d_wl_drm_helper_reference_buffer(void *user_data, uint32_t name, int fd,
-                                       struct wl_drm_buffer *buffer);
-
-void
-egl_g3d_wl_drm_helper_unreference_buffer(void *user_data,
-                                         struct wl_drm_buffer *buffer);
-
-struct pipe_resource *
-egl_g3d_wl_drm_common_wl_buffer_get_resource(struct native_display *ndpy,
-                                             struct wl_buffer *buffer);
-
-EGLBoolean
-egl_g3d_wl_drm_common_query_buffer(struct native_display *ndpy,
-                                   struct wl_buffer *buffer,
-                                   EGLint attribute, EGLint *value);
-
-#endif /* _NATIVE_WAYLAND_DRM_BUFMGR_HELPER_H_ */
diff --git a/src/gallium/state_trackers/egl/drm/native_drm.c b/src/gallium/state_trackers/egl/drm/native_drm.c
index 03bfdda..c82bbe4 100644
--- a/src/gallium/state_trackers/egl/drm/native_drm.c
+++ b/src/gallium/state_trackers/egl/drm/native_drm.c
@@ -132,6 +132,10 @@ drm_display_destroy(struct native_display *ndpy)
 
    FREE(drmdpy->device_name);
 
+#ifdef HAVE_WAYLAND_BACKEND
+   wayland_drm_bufmgr_destroy(ndpy->wayland_bufmgr);
+#endif
+
    if (drmdpy->own_gbm) {
       gbm_device_destroy(&drmdpy->gbmdrm->base.base);
       if (drmdpy->fd >= 0)
@@ -195,53 +199,6 @@ drm_display_authenticate(void *user_data, uint32_t magic)
    return drmAuthMagic(drmdpy->fd, magic);
 }
 
-static struct wayland_drm_callbacks wl_drm_callbacks = {
-   drm_display_authenticate,
-   egl_g3d_wl_drm_helper_reference_buffer,
-   egl_g3d_wl_drm_helper_unreference_buffer
-};
-
-static boolean
-drm_display_bind_wayland_display(struct native_display *ndpy,
-                                  struct wl_display *wl_dpy)
-{
-   struct drm_display *drmdpy = drm_display(ndpy);
-
-   if (drmdpy->wl_server_drm)
-      return FALSE;
-
-   drmdpy->wl_server_drm = wayland_drm_init(wl_dpy,
-         drmdpy->device_name,
-         &wl_drm_callbacks, ndpy, 0);
-
-   if (!drmdpy->wl_server_drm)
-      return FALSE;
-   
-   return TRUE;
-}
-
-static boolean
-drm_display_unbind_wayland_display(struct native_display *ndpy,
-                                    struct wl_display *wl_dpy)
-{
-   struct drm_display *drmdpy = drm_display(ndpy);
-
-   if (!drmdpy->wl_server_drm)
-      return FALSE;
-
-   wayland_drm_uninit(drmdpy->wl_server_drm);
-   drmdpy->wl_server_drm = NULL;
-
-   return TRUE;
-}
-
-static struct native_display_wayland_bufmgr drm_display_wayland_bufmgr = {
-   drm_display_bind_wayland_display,
-   drm_display_unbind_wayland_display,
-   egl_g3d_wl_drm_common_wl_buffer_get_resource,
-   egl_g3d_wl_drm_common_query_buffer
-};
-
 #endif /* HAVE_WAYLAND_BACKEND */
 
 static struct native_surface *
@@ -293,7 +250,8 @@ drm_create_display(struct gbm_gallium_drm_device *gbmdrm, int own_gbm,
    drmdpy->base.buffer = &drm_display_buffer;
 #ifdef HAVE_WAYLAND_BACKEND
    if (drmdpy->device_name)
-      drmdpy->base.wayland_bufmgr = &drm_display_wayland_bufmgr;
+      drmdpy->base.wayland_bufmgr = wayland_drm_bufmgr_create(
+             drm_display_authenticate, drmdpy, drmdpy->device_name);
 #endif
    drm_display_init_modeset(&drmdpy->base);
 
diff --git a/src/gallium/state_trackers/egl/drm/native_drm.h b/src/gallium/state_trackers/egl/drm/native_drm.h
index 16a4251..6a1cd5d 100644
--- a/src/gallium/state_trackers/egl/drm/native_drm.h
+++ b/src/gallium/state_trackers/egl/drm/native_drm.h
@@ -37,7 +37,7 @@
 #include "common/native_helper.h"
 
 #ifdef HAVE_WAYLAND_BACKEND
-#include "common/native_wayland_drm_bufmgr_helper.h"
+#include "common/native_wayland_drm_bufmgr.h"
 #endif
 
 #include "gbm_gallium_drmint.h"
@@ -67,10 +67,6 @@ struct drm_display {
    struct drm_surface **shown_surfaces;
    /* save the original settings of the CRTCs */
    struct drm_crtc *saved_crtcs;
-
-#ifdef HAVE_WAYLAND_BACKEND
-   struct wl_drm *wl_server_drm; /* for EGL_WL_bind_wayland_display */
-#endif
 };
 
 struct drm_config {
diff --git a/src/gallium/state_trackers/egl/wayland/native_drm.c b/src/gallium/state_trackers/egl/wayland/native_drm.c
index fc8aac7..a4bcdd8 100644
--- a/src/gallium/state_trackers/egl/wayland/native_drm.c
+++ b/src/gallium/state_trackers/egl/wayland/native_drm.c
@@ -40,7 +40,7 @@
 #include "wayland-drm-client-protocol.h"
 #include "wayland-egl-priv.h"
 
-#include "common/native_wayland_drm_bufmgr_helper.h"
+#include "common/native_wayland_drm_bufmgr.h"
 
 #include <xf86drm.h>
 #include <sys/types.h>
@@ -53,7 +53,6 @@ struct wayland_drm_display {
    const struct native_event_handler *event_handler;
 
    struct wl_drm *wl_drm;
-   struct wl_drm *wl_server_drm; /* for EGL_WL_bind_wayland_display */
    int fd;
    char *device_name;
    boolean authenticated;
@@ -77,6 +76,8 @@ wayland_drm_display_destroy(struct native_display *ndpy)
    if (drmdpy->base.own_dpy)
       wl_display_disconnect(drmdpy->base.dpy);
 
+   wayland_drm_bufmgr_destroy(ndpy->wayland_bufmgr);
+
    ndpy_uninit(ndpy);
 
    if (drmdpy->fd)
@@ -195,6 +196,24 @@ static const struct wl_registry_listener registry_listener = {
        registry_handle_global
 };
 
+static int
+wayland_drm_display_authenticate(void *user_data, uint32_t magic)
+{
+   struct native_display *ndpy = user_data;
+   struct wayland_drm_display *drmdpy = wayland_drm_display(ndpy);
+   boolean current_authenticate, authenticated;
+
+   current_authenticate = drmdpy->authenticated;
+
+   wl_drm_authenticate(drmdpy->wl_drm, magic);
+   wl_display_roundtrip(drmdpy->base.dpy);
+   authenticated = drmdpy->authenticated;
+
+   drmdpy->authenticated = current_authenticate;
+
+   return authenticated ? 0 : -1;
+}
+
 static boolean
 wayland_drm_display_init_screen(struct native_display *ndpy)
 {
@@ -226,6 +245,9 @@ wayland_drm_display_init_screen(struct native_display *ndpy)
       return FALSE;
    }
 
+   drmdpy->base.base.wayland_bufmgr = wayland_drm_bufmgr_create(
+          wayland_drm_display_authenticate, drmdpy, drmdpy->device_name);
+
    return TRUE;
 }
 
@@ -235,72 +257,6 @@ static struct native_display_buffer wayland_drm_display_buffer = {
    drm_display_export_native_buffer
 };
 
-static int
-wayland_drm_display_authenticate(void *user_data, uint32_t magic)
-{
-   struct native_display *ndpy = user_data;
-   struct wayland_drm_display *drmdpy = wayland_drm_display(ndpy);
-   boolean current_authenticate, authenticated;
-
-   current_authenticate = drmdpy->authenticated;
-
-   wl_drm_authenticate(drmdpy->wl_drm, magic);
-   wl_display_roundtrip(drmdpy->base.dpy);
-   authenticated = drmdpy->authenticated;
-
-   drmdpy->authenticated = current_authenticate;
-
-   return authenticated ? 0 : -1;
-}
-
-static struct wayland_drm_callbacks wl_drm_callbacks = {
-   wayland_drm_display_authenticate,
-   egl_g3d_wl_drm_helper_reference_buffer,
-   egl_g3d_wl_drm_helper_unreference_buffer
-};
-
-static boolean
-wayland_drm_display_bind_wayland_display(struct native_display *ndpy,
-                                         struct wl_display *wl_dpy)
-{
-   struct wayland_drm_display *drmdpy = wayland_drm_display(ndpy);
-
-   if (drmdpy->wl_server_drm)
-      return FALSE;
-
-   drmdpy->wl_server_drm =
-      wayland_drm_init(wl_dpy, drmdpy->device_name,
-                       &wl_drm_callbacks, ndpy, 0);
-
-   if (!drmdpy->wl_server_drm)
-      return FALSE;
-   
-   return TRUE;
-}
-
-static boolean
-wayland_drm_display_unbind_wayland_display(struct native_display *ndpy,
-                                           struct wl_display *wl_dpy)
-{
-   struct wayland_drm_display *drmdpy = wayland_drm_display(ndpy);
-
-   if (!drmdpy->wl_server_drm)
-      return FALSE;
-
-   wayland_drm_uninit(drmdpy->wl_server_drm);
-   drmdpy->wl_server_drm = NULL;
-
-   return TRUE;
-}
-
-static struct native_display_wayland_bufmgr wayland_drm_display_wayland_bufmgr = {
-   wayland_drm_display_bind_wayland_display,
-   wayland_drm_display_unbind_wayland_display,
-   egl_g3d_wl_drm_common_wl_buffer_get_resource,
-   egl_g3d_wl_drm_common_query_buffer
-};
-
-
 struct wayland_display *
 wayland_create_drm_display(struct wl_display *dpy,
                            const struct native_event_handler *event_handler)
@@ -322,7 +278,6 @@ wayland_create_drm_display(struct wl_display *dpy,
    drmdpy->base.base.init_screen = wayland_drm_display_init_screen;
    drmdpy->base.base.destroy = wayland_drm_display_destroy;
    drmdpy->base.base.buffer = &wayland_drm_display_buffer;
-   drmdpy->base.base.wayland_bufmgr = &wayland_drm_display_wayland_bufmgr;
 
    drmdpy->base.create_buffer = wayland_create_drm_buffer;
 
diff --git a/src/gallium/state_trackers/egl/x11/native_dri2.c b/src/gallium/state_trackers/egl/x11/native_dri2.c
index 053044a..3aa7c17 100644
--- a/src/gallium/state_trackers/egl/x11/native_dri2.c
+++ b/src/gallium/state_trackers/egl/x11/native_dri2.c
@@ -39,7 +39,7 @@
 
 #include "common/native_helper.h"
 #ifdef HAVE_WAYLAND_BACKEND
-#include "common/native_wayland_drm_bufmgr_helper.h"
+#include "common/native_wayland_drm_bufmgr.h"
 #endif
 
 #ifdef GLX_DIRECT_RENDERING
@@ -60,9 +60,6 @@ struct dri2_display {
    int num_configs;
 
    struct util_hash_table *surfaces;
-#ifdef HAVE_WAYLAND_BACKEND
-   struct wl_drm *wl_server_drm; /* for EGL_WL_bind_wayland_display */
-#endif
 };
 
 struct dri2_surface {
@@ -757,6 +754,10 @@ dri2_display_destroy(struct native_display *ndpy)
    if (dri2dpy->surfaces)
       util_hash_table_destroy(dri2dpy->surfaces);
 
+#ifdef HAVE_WAYLAND_BACKEND
+   wayland_drm_bufmgr_destroy(ndpy->wayland_bufmgr);
+#endif
+
    if (dri2dpy->xscr)
       x11_screen_destroy(dri2dpy->xscr);
    if (dri2dpy->own_dpy)
@@ -785,6 +786,19 @@ dri2_display_invalidate_buffers(struct x11_screen *xscr, Drawable drawable,
          &dri2surf->base, dri2surf->server_stamp);
 }
 
+#ifdef HAVE_WAYLAND_BACKEND
+
+static int
+dri2_display_authenticate(void *user_data, uint32_t magic)
+{
+   struct native_display *ndpy = user_data;
+   struct dri2_display *dri2dpy = dri2_display(ndpy);
+
+   return x11_screen_authenticate(dri2dpy->xscr, magic);
+}
+
+#endif /* HAVE_WAYLAND_BACKEND */
+
 /**
  * Initialize DRI2 and pipe screen.
  */
@@ -816,6 +830,13 @@ dri2_display_init_screen(struct native_display *ndpy)
       return FALSE;
    }
 
+#ifdef HAVE_WAYLAND_BACKEND
+   dri2dpy->base.wayland_bufmgr = wayland_drm_bufmgr_create(
+         dri2_display_authenticate, dri2dpy,
+         x11_screen_get_device_name(dri2dpy->xscr));
+
+#endif
+
    return TRUE;
 }
 
@@ -832,66 +853,6 @@ dri2_display_hash_table_compare(void *key1, void *key2)
    return ((char *) key1 - (char *) key2);
 }
 
-#ifdef HAVE_WAYLAND_BACKEND
-
-static int
-dri2_display_authenticate(void *user_data, uint32_t magic)
-{
-   struct native_display *ndpy = user_data;
-   struct dri2_display *dri2dpy = dri2_display(ndpy);
-
-   return x11_screen_authenticate(dri2dpy->xscr, magic);
-}
-
-static struct wayland_drm_callbacks wl_drm_callbacks = {
-   dri2_display_authenticate,
-   egl_g3d_wl_drm_helper_reference_buffer,
-   egl_g3d_wl_drm_helper_unreference_buffer
-};
-
-static boolean
-dri2_display_bind_wayland_display(struct native_display *ndpy,
-                                  struct wl_display *wl_dpy)
-{
-   struct dri2_display *dri2dpy = dri2_display(ndpy);
-
-   if (dri2dpy->wl_server_drm)
-      return FALSE;
-
-   dri2dpy->wl_server_drm = wayland_drm_init(wl_dpy,
-         x11_screen_get_device_name(dri2dpy->xscr),
-         &wl_drm_callbacks, ndpy, 0);
-
-   if (!dri2dpy->wl_server_drm)
-      return FALSE;
-   
-   return TRUE;
-}
-
-static boolean
-dri2_display_unbind_wayland_display(struct native_display *ndpy,
-                                    struct wl_display *wl_dpy)
-{
-   struct dri2_display *dri2dpy = dri2_display(ndpy);
-
-   if (!dri2dpy->wl_server_drm)
-      return FALSE;
-
-   wayland_drm_uninit(dri2dpy->wl_server_drm);
-   dri2dpy->wl_server_drm = NULL;
-
-   return TRUE;
-}
-
-static struct native_display_wayland_bufmgr dri2_display_wayland_bufmgr = {
-   dri2_display_bind_wayland_display,
-   dri2_display_unbind_wayland_display,
-   egl_g3d_wl_drm_common_wl_buffer_get_resource,
-   egl_g3d_wl_drm_common_query_buffer
-};
-
-#endif /* HAVE_WAYLAND_BACKEND */
-
 struct native_display *
 x11_create_dri2_display(Display *dpy,
                         const struct native_event_handler *event_handler)
@@ -936,9 +897,6 @@ x11_create_dri2_display(Display *dpy,
    dri2dpy->base.copy_to_pixmap = native_display_copy_to_pixmap;
    dri2dpy->base.create_window_surface = dri2_display_create_window_surface;
    dri2dpy->base.create_pixmap_surface = dri2_display_create_pixmap_surface;
-#ifdef HAVE_WAYLAND_BACKEND
-   dri2dpy->base.wayland_bufmgr = &dri2_display_wayland_bufmgr;
-#endif
 
    return &dri2dpy->base;
 }
-- 
1.8.1.2



More information about the mesa-dev mailing list