Re: [PATCH xserver 1/3] xwayland: Decouple GBM from glamor

2018-04-24 Thread Lyude Paul
On Tue, 2018-04-24 at 10:35 +0100, Daniel Stone wrote:
> Hi,
> 
> On 20 April 2018 at 19:38, Adam Jackson  wrote:
> > This takes all of the gbm related code in wayland-glamor.c and moves it
> > into it's own EGL backend for Xwayland, xwayland-glamor-gbm.c.
> > Additionally, we add the egl_backend struct into xwl_screen in order to
> > provide hooks for alternative EGL backends such as nvidia's EGLStreams.
> 
> I do think the end result of this commit is better; there are a lot of
> good cleanups in here. It would be much easier to review next time
> though, if this was broken into a few separate commits. There is mass
> code motion, resequencing of functions, reordering of struct members,
> minor changes of struct declarations (e.g. void * -> EGLImage in
> xwl_pixmap), a lot of formatting changes, and other cleanups like
> moving variable declarations into child blocks. It's taken until now
> to review it because I've got four panes open with new and old code
> side by side, with quite a lot of back and forth.
> 
> > +_X_EXPORT Bool
> > +glamor_get_formats(ScreenPtr screen,
> > +   CARD32 *num_formats, CARD32 **formats)
> > +{
> > +struct xwl_screen *xwl_screen = xwl_screen_get(screen);
> > +struct xwl_gbm_private *xwl_gbm = xwl_gbm_get(xwl_screen);
> > +int i;
> > +
> > +if (!xwl_gbm->dmabuf_capable || !xwl_gbm->dmabuf)
> > +return FALSE;
> > +
> > +if (xwl_screen->num_formats == 0) {
> > +   *num_formats = 0;
> > +   return TRUE;
> > +}
> 
> Changes from ac48724639e0a6a9e421b3b4e545d8506fd6bf5dost in rebase.
> 
> > +_X_EXPORT Bool
> > +glamor_get_modifiers(ScreenPtr screen, CARD32 format,
> > + CARD32 *num_modifiers, uint64_t **modifiers)
> > +{
> > +struct xwl_screen *xwl_screen = xwl_screen_get(screen);
> > +struct xwl_gbm_private *xwl_gbm = xwl_gbm_get(xwl_screen);
> > +struct xwl_format *xwl_format = NULL;
> > +int i;
> > +
> > +if (!xwl_gbm->dmabuf_capable || !xwl_gbm->dmabuf)
> > +return FALSE;
> > +
> > +/* Explicitly zero the count as the caller may ignore the return
> > value */
> > +*num_modifiers = 0;
> 
> Changes from b36a14c0b0e7e38406622eb5ff0666a8b8bc50f4 misplaced in rebase.
> 
> > +static void
> > +xwl_drm_handle_device(void *data, struct wl_drm *drm, const char *device)
> > +{
> > +   struct xwl_screen *xwl_screen = data;
> > +   struct xwl_gbm_private *xwl_gbm = xwl_gbm_get(xwl_screen);
> > +   drm_magic_t magic;
> > +
> > +   xwl_gbm->device_name = strdup(device);
> > +   if (!xwl_gbm->device_name) {
> > +   xwl_glamor_gbm_cleanup(xwl_screen);
> > +   return;
> > +   }
> > +
> > +   xwl_gbm->drm_fd = open(xwl_gbm->device_name, O_RDWR | O_CLOEXEC);
> > +   if (xwl_gbm->drm_fd == -1) {
> > +   ErrorF("wayland-egl: could not open %s (%s)\n",
> > +  xwl_gbm->device_name, strerror(errno));
> > +   xwl_glamor_gbm_cleanup(xwl_screen);
> > +   return;
> > +   }
> > +
> > +   if (is_fd_render_node(xwl_gbm->drm_fd)) {
> > +   xwl_gbm->fd_render_node = 1;
> > +   xwl_screen->expecting_event--;
> > +   } else {
> > +   drmGetMagic(xwl_gbm->drm_fd, );
> > +   wl_drm_authenticate(xwl_gbm->drm, magic);
> > +   }
> > +}
> 
> e.g. here, the change to expecting_event is unnecessary; the previous
> code explicitly decremented and re-incremented to make it clear which
> event was which, and the change meant I had to double back and read
> through the whole init flow again. The current code is still correct,
> and I don't care enough to ask for it to be made back the way it was,
> but in future please try to keep these kinds of subtle changes
> separate from mass code motion.

Will keep that in mind for the future, thanks!
> 
> The rest is:
> Reviewed-by: Daniel Stone 
> 
> Cheers,
> Daniel
-- 
Cheers,
Lyude Paul
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Re: [PATCH xserver 1/3] xwayland: Decouple GBM from glamor

2018-04-24 Thread Daniel Stone
Hi,

On 20 April 2018 at 19:38, Adam Jackson  wrote:
> This takes all of the gbm related code in wayland-glamor.c and moves it
> into it's own EGL backend for Xwayland, xwayland-glamor-gbm.c.
> Additionally, we add the egl_backend struct into xwl_screen in order to
> provide hooks for alternative EGL backends such as nvidia's EGLStreams.

I do think the end result of this commit is better; there are a lot of
good cleanups in here. It would be much easier to review next time
though, if this was broken into a few separate commits. There is mass
code motion, resequencing of functions, reordering of struct members,
minor changes of struct declarations (e.g. void * -> EGLImage in
xwl_pixmap), a lot of formatting changes, and other cleanups like
moving variable declarations into child blocks. It's taken until now
to review it because I've got four panes open with new and old code
side by side, with quite a lot of back and forth.

> +_X_EXPORT Bool
> +glamor_get_formats(ScreenPtr screen,
> +   CARD32 *num_formats, CARD32 **formats)
> +{
> +struct xwl_screen *xwl_screen = xwl_screen_get(screen);
> +struct xwl_gbm_private *xwl_gbm = xwl_gbm_get(xwl_screen);
> +int i;
> +
> +if (!xwl_gbm->dmabuf_capable || !xwl_gbm->dmabuf)
> +return FALSE;
> +
> +if (xwl_screen->num_formats == 0) {
> +   *num_formats = 0;
> +   return TRUE;
> +}

Changes from ac48724639e0a6a9e421b3b4e545d8506fd6bf5dost in rebase.

> +_X_EXPORT Bool
> +glamor_get_modifiers(ScreenPtr screen, CARD32 format,
> + CARD32 *num_modifiers, uint64_t **modifiers)
> +{
> +struct xwl_screen *xwl_screen = xwl_screen_get(screen);
> +struct xwl_gbm_private *xwl_gbm = xwl_gbm_get(xwl_screen);
> +struct xwl_format *xwl_format = NULL;
> +int i;
> +
> +if (!xwl_gbm->dmabuf_capable || !xwl_gbm->dmabuf)
> +return FALSE;
> +
> +/* Explicitly zero the count as the caller may ignore the return value */
> +*num_modifiers = 0;

Changes from b36a14c0b0e7e38406622eb5ff0666a8b8bc50f4 misplaced in rebase.

> +static void
> +xwl_drm_handle_device(void *data, struct wl_drm *drm, const char *device)
> +{
> +   struct xwl_screen *xwl_screen = data;
> +   struct xwl_gbm_private *xwl_gbm = xwl_gbm_get(xwl_screen);
> +   drm_magic_t magic;
> +
> +   xwl_gbm->device_name = strdup(device);
> +   if (!xwl_gbm->device_name) {
> +   xwl_glamor_gbm_cleanup(xwl_screen);
> +   return;
> +   }
> +
> +   xwl_gbm->drm_fd = open(xwl_gbm->device_name, O_RDWR | O_CLOEXEC);
> +   if (xwl_gbm->drm_fd == -1) {
> +   ErrorF("wayland-egl: could not open %s (%s)\n",
> +  xwl_gbm->device_name, strerror(errno));
> +   xwl_glamor_gbm_cleanup(xwl_screen);
> +   return;
> +   }
> +
> +   if (is_fd_render_node(xwl_gbm->drm_fd)) {
> +   xwl_gbm->fd_render_node = 1;
> +   xwl_screen->expecting_event--;
> +   } else {
> +   drmGetMagic(xwl_gbm->drm_fd, );
> +   wl_drm_authenticate(xwl_gbm->drm, magic);
> +   }
> +}

e.g. here, the change to expecting_event is unnecessary; the previous
code explicitly decremented and re-incremented to make it clear which
event was which, and the change meant I had to double back and read
through the whole init flow again. The current code is still correct,
and I don't care enough to ask for it to be made back the way it was,
but in future please try to keep these kinds of subtle changes
separate from mass code motion.

The rest is:
Reviewed-by: Daniel Stone 

Cheers,
Daniel
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Re: [PATCH xserver 1/3] xwayland: Decouple GBM from glamor

2018-04-23 Thread Adam Jackson
On Fri, 2018-04-20 at 17:23 -0400, Lyude Paul wrote:
> lgtm! for the whole series:
> 
> Reviewed-by: Lyude Paul 

Thanks. I've found at least one interaction between this and the
present window flip code (which assumes gbm, but merely checks whether
->glamor is set...). I'll merge this and the fixes for that tomorrow
unless I get any additional feedback, and call that RC5 and hopefully
that'll be the last one.

- ajax
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Re: [PATCH xserver 1/3] xwayland: Decouple GBM from glamor

2018-04-20 Thread Lyude Paul
lgtm! for the whole series:

Reviewed-by: Lyude Paul 

On Fri, 2018-04-20 at 14:38 -0400, Adam Jackson wrote:
> From: Lyude Paul 
> 
> This takes all of the gbm related code in wayland-glamor.c and moves it
> into it's own EGL backend for Xwayland, xwayland-glamor-gbm.c.
> Additionally, we add the egl_backend struct into xwl_screen in order to
> provide hooks for alternative EGL backends such as nvidia's EGLStreams.
> 
> Signed-off-by: Lyude Paul 
> ---
>  hw/xwayland/Makefile.am   |   1 +
>  hw/xwayland/meson.build   |   6 +-
>  hw/xwayland/xwayland-glamor-gbm.c | 892 ++
>  hw/xwayland/xwayland-glamor.c | 760 +
>  hw/xwayland/xwayland.c|  17 +-
>  hw/xwayland/xwayland.h|  58 +-
>  6 files changed, 976 insertions(+), 758 deletions(-)
>  create mode 100644 hw/xwayland/xwayland-glamor-gbm.c
> 
> diff --git a/hw/xwayland/Makefile.am b/hw/xwayland/Makefile.am
> index 80d3a1f199..3fd980d0ee 100644
> --- a/hw/xwayland/Makefile.am
> +++ b/hw/xwayland/Makefile.am
> @@ -35,6 +35,7 @@ Xwayland_built_sources =
>  if GLAMOR_EGL
>  Xwayland_SOURCES +=  \
>   xwayland-glamor.c   \
> + xwayland-glamor-gbm.c   \
>   xwayland-present.c
>  if XV
>  Xwayland_SOURCES +=  \
> diff --git a/hw/xwayland/meson.build b/hw/xwayland/meson.build
> index 8d178825e7..ef4379aab0 100644
> --- a/hw/xwayland/meson.build
> +++ b/hw/xwayland/meson.build
> @@ -52,7 +52,11 @@ srcs += code.process(dmabuf_xml)
>  
>  xwayland_glamor = []
>  if gbm_dep.found()
> -srcs += [ 'xwayland-glamor.c', 'xwayland-present.c' ]
> +srcs += [
> +'xwayland-glamor.c',
> +'xwayland-glamor-gbm.c',
> +'xwayland-present.c',
> +]
>  if build_xv
>  srcs += 'xwayland-glamor-xv.c'
>  endif
> diff --git a/hw/xwayland/xwayland-glamor-gbm.c b/hw/xwayland/xwayland-
> glamor-gbm.c
> new file mode 100644
> index 00..7be1437e86
> --- /dev/null
> +++ b/hw/xwayland/xwayland-glamor-gbm.c
> @@ -0,0 +1,892 @@
> +/*
> + * Copyright © 2011-2014 Intel Corporation
> + * Copyright © 2017 Red Hat Inc.
> + *
> + * 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 (including
> + * the next paragraph) 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.
> + *
> + * Authors:
> + *Lyude Paul 
> + *
> + */
> +
> +#include "xwayland.h"
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define MESA_EGL_NO_X11_HEADERS
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include "drm-client-protocol.h"
> +
> +struct xwl_gbm_private {
> +char *device_name;
> +struct gbm_device *gbm;
> +struct wl_drm *drm;
> +struct zwp_linux_dmabuf_v1 *dmabuf;
> +int drm_fd;
> +int fd_render_node;
> +Bool drm_authenticated;
> +uint32_t capabilities;
> +int dmabuf_capable;
> +};
> +
> +struct xwl_pixmap {
> +struct wl_buffer *buffer;
> +EGLImage image;
> +unsigned int texture;
> +struct gbm_bo *bo;
> +};
> +
> +static DevPrivateKeyRec xwl_gbm_private_key;
> +static DevPrivateKeyRec xwl_auth_state_private_key;
> +
> +static inline struct xwl_gbm_private *
> +xwl_gbm_get(struct xwl_screen *xwl_screen)
> +{
> +return dixLookupPrivate(_screen->screen->devPrivates,
> +_gbm_private_key);
> +}
> +
> +static uint32_t
> +gbm_format_for_depth(int depth)
> +{
> +switch (depth) {
> +case 16:
> +return GBM_FORMAT_RGB565;
> +case 24:
> +return GBM_FORMAT_XRGB;
> +case 30:
> +return GBM_FORMAT_ARGB2101010;
> +default:
> +ErrorF("unexpected depth: %d\n", depth);
> +case 32:
> +return GBM_FORMAT_ARGB;
> +}
> +}
> +
> +static uint32_t
> +wl_drm_format_for_depth(int depth)
> +{
> +switch (depth) {
> +case 15:

[PATCH xserver 1/3] xwayland: Decouple GBM from glamor

2018-04-20 Thread Adam Jackson
From: Lyude Paul 

This takes all of the gbm related code in wayland-glamor.c and moves it
into it's own EGL backend for Xwayland, xwayland-glamor-gbm.c.
Additionally, we add the egl_backend struct into xwl_screen in order to
provide hooks for alternative EGL backends such as nvidia's EGLStreams.

Signed-off-by: Lyude Paul 
---
 hw/xwayland/Makefile.am   |   1 +
 hw/xwayland/meson.build   |   6 +-
 hw/xwayland/xwayland-glamor-gbm.c | 892 ++
 hw/xwayland/xwayland-glamor.c | 760 +
 hw/xwayland/xwayland.c|  17 +-
 hw/xwayland/xwayland.h|  58 +-
 6 files changed, 976 insertions(+), 758 deletions(-)
 create mode 100644 hw/xwayland/xwayland-glamor-gbm.c

diff --git a/hw/xwayland/Makefile.am b/hw/xwayland/Makefile.am
index 80d3a1f199..3fd980d0ee 100644
--- a/hw/xwayland/Makefile.am
+++ b/hw/xwayland/Makefile.am
@@ -35,6 +35,7 @@ Xwayland_built_sources =
 if GLAMOR_EGL
 Xwayland_SOURCES +=\
xwayland-glamor.c   \
+   xwayland-glamor-gbm.c   \
xwayland-present.c
 if XV
 Xwayland_SOURCES +=\
diff --git a/hw/xwayland/meson.build b/hw/xwayland/meson.build
index 8d178825e7..ef4379aab0 100644
--- a/hw/xwayland/meson.build
+++ b/hw/xwayland/meson.build
@@ -52,7 +52,11 @@ srcs += code.process(dmabuf_xml)
 
 xwayland_glamor = []
 if gbm_dep.found()
-srcs += [ 'xwayland-glamor.c', 'xwayland-present.c' ]
+srcs += [
+'xwayland-glamor.c',
+'xwayland-glamor-gbm.c',
+'xwayland-present.c',
+]
 if build_xv
 srcs += 'xwayland-glamor-xv.c'
 endif
diff --git a/hw/xwayland/xwayland-glamor-gbm.c 
b/hw/xwayland/xwayland-glamor-gbm.c
new file mode 100644
index 00..7be1437e86
--- /dev/null
+++ b/hw/xwayland/xwayland-glamor-gbm.c
@@ -0,0 +1,892 @@
+/*
+ * Copyright © 2011-2014 Intel Corporation
+ * Copyright © 2017 Red Hat Inc.
+ *
+ * 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 (including
+ * the next paragraph) 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.
+ *
+ * Authors:
+ *Lyude Paul 
+ *
+ */
+
+#include "xwayland.h"
+
+#include 
+#include 
+#include 
+#include 
+
+#define MESA_EGL_NO_X11_HEADERS
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include "drm-client-protocol.h"
+
+struct xwl_gbm_private {
+char *device_name;
+struct gbm_device *gbm;
+struct wl_drm *drm;
+struct zwp_linux_dmabuf_v1 *dmabuf;
+int drm_fd;
+int fd_render_node;
+Bool drm_authenticated;
+uint32_t capabilities;
+int dmabuf_capable;
+};
+
+struct xwl_pixmap {
+struct wl_buffer *buffer;
+EGLImage image;
+unsigned int texture;
+struct gbm_bo *bo;
+};
+
+static DevPrivateKeyRec xwl_gbm_private_key;
+static DevPrivateKeyRec xwl_auth_state_private_key;
+
+static inline struct xwl_gbm_private *
+xwl_gbm_get(struct xwl_screen *xwl_screen)
+{
+return dixLookupPrivate(_screen->screen->devPrivates,
+_gbm_private_key);
+}
+
+static uint32_t
+gbm_format_for_depth(int depth)
+{
+switch (depth) {
+case 16:
+return GBM_FORMAT_RGB565;
+case 24:
+return GBM_FORMAT_XRGB;
+case 30:
+return GBM_FORMAT_ARGB2101010;
+default:
+ErrorF("unexpected depth: %d\n", depth);
+case 32:
+return GBM_FORMAT_ARGB;
+}
+}
+
+static uint32_t
+wl_drm_format_for_depth(int depth)
+{
+switch (depth) {
+case 15:
+return WL_DRM_FORMAT_XRGB1555;
+case 16:
+return WL_DRM_FORMAT_RGB565;
+case 24:
+return WL_DRM_FORMAT_XRGB;
+case 30:
+return WL_DRM_FORMAT_ARGB2101010;
+default:
+ErrorF("unexpected depth: %d\n", depth);
+case 32:
+return WL_DRM_FORMAT_ARGB;
+}
+}
+
+static char
+is_fd_render_node(int fd)
+{
+struct stat render;
+
+if 

[PATCH xserver 1/3] xwayland: Decouple GBM from glamor

2018-03-07 Thread Adam Jackson
From: Lyude Paul 

This takes all of the gbm related code in wayland-glamor.c and moves it
into it's own EGL backend for Xwayland, xwayland-glamor-gbm.c.
Additionally, we add the egl_backend struct into xwl_screen in order to
provide hooks for alternative EGL backends such as nvidia's EGLStreams.

Signed-off-by: Lyude Paul 
---
 hw/xwayland/Makefile.am   |   3 +-
 hw/xwayland/meson.build   |   1 +
 hw/xwayland/xwayland-glamor-gbm.c | 887 ++
 hw/xwayland/xwayland-glamor.c | 751 +---
 hw/xwayland/xwayland.c|  13 +
 hw/xwayland/xwayland.h|  55 ++-
 6 files changed, 965 insertions(+), 745 deletions(-)
 create mode 100644 hw/xwayland/xwayland-glamor-gbm.c

diff --git a/hw/xwayland/Makefile.am b/hw/xwayland/Makefile.am
index f44a7ded3..14c90456a 100644
--- a/hw/xwayland/Makefile.am
+++ b/hw/xwayland/Makefile.am
@@ -34,7 +34,8 @@ Xwayland_built_sources =
 
 if GLAMOR_EGL
 Xwayland_SOURCES +=\
-   xwayland-glamor.c
+   xwayland-glamor.c   \
+   xwayland-glamor-gbm.c
 if XV
 Xwayland_SOURCES +=\
xwayland-glamor-xv.c
diff --git a/hw/xwayland/meson.build b/hw/xwayland/meson.build
index 7e24c5d63..dd696d456 100644
--- a/hw/xwayland/meson.build
+++ b/hw/xwayland/meson.build
@@ -46,6 +46,7 @@ srcs += code.process(dmabuf_xml)
 xwayland_glamor = []
 if gbm_dep.found()
 srcs += 'xwayland-glamor.c'
+srcs += 'xwayland-glamor-gbm.c'
 if build_xv
 srcs += 'xwayland-glamor-xv.c'
 endif
diff --git a/hw/xwayland/xwayland-glamor-gbm.c 
b/hw/xwayland/xwayland-glamor-gbm.c
new file mode 100644
index 0..618c218e9
--- /dev/null
+++ b/hw/xwayland/xwayland-glamor-gbm.c
@@ -0,0 +1,887 @@
+/*
+ * Copyright © 2011-2014 Intel Corporation
+ * Copyright © 2017 Red Hat Inc.
+ *
+ * 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 (including
+ * the next paragraph) 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.
+ *
+ * Authors:
+ *Lyude Paul 
+ *
+ */
+
+#include "xwayland.h"
+
+#include 
+#include 
+#include 
+#include 
+
+#define MESA_EGL_NO_X11_HEADERS
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include "drm-client-protocol.h"
+
+struct xwl_gbm_private {
+char *device_name;
+struct gbm_device *gbm;
+struct wl_drm *drm;
+struct zwp_linux_dmabuf_v1 *dmabuf;
+int drm_fd;
+int fd_render_node;
+Bool drm_authenticated;
+uint32_t capabilities;
+int dmabuf_capable;
+};
+
+struct xwl_pixmap {
+struct wl_buffer *buffer;
+EGLImage image;
+unsigned int texture;
+struct gbm_bo *bo;
+};
+
+static DevPrivateKeyRec xwl_gbm_private_key;
+static DevPrivateKeyRec xwl_auth_state_private_key;
+
+static inline struct xwl_gbm_private *
+xwl_gbm_get(struct xwl_screen *xwl_screen)
+{
+return dixLookupPrivate(_screen->screen->devPrivates,
+_gbm_private_key);
+}
+
+static uint32_t
+gbm_format_for_depth(int depth)
+{
+switch (depth) {
+case 16:
+return GBM_FORMAT_RGB565;
+case 24:
+return GBM_FORMAT_XRGB;
+default:
+ErrorF("unexpected depth: %d\n", depth);
+case 32:
+return GBM_FORMAT_ARGB;
+}
+}
+
+static uint32_t
+wl_drm_format_for_depth(int depth)
+{
+switch (depth) {
+case 15:
+return WL_DRM_FORMAT_XRGB1555;
+case 16:
+return WL_DRM_FORMAT_RGB565;
+case 24:
+return WL_DRM_FORMAT_XRGB;
+default:
+ErrorF("unexpected depth: %d\n", depth);
+case 32:
+return WL_DRM_FORMAT_ARGB;
+}
+}
+
+static char
+is_fd_render_node(int fd)
+{
+struct stat render;
+
+if (fstat(fd, ))
+return 0;
+if (!S_ISCHR(render.st_mode))
+return 0;
+if (render.st_rdev & 0x80)
+return 1;
+
+return 0;
+}
+
+static PixmapPtr