EGL_DRIVERS_DIRS="glx"
fi
+ PKG_CHECK_MODULES([LIBUDEV], [libudev > 150],
+ [have_libudev=yes],[have_libudev=no])
if test "$mesa_driver" = dri; then
# build egl_dri2 when xcb-dri2 is available
PKG_CHECK_MODULES([XCB_DRI2], [x11-xcb xcb-dri2 xcb-xfixes],
[have_xcb_dri2=yes],[have_xcb_dri2=no])
- PKG_CHECK_MODULES([LIBUDEV], [libudev > 150],
- [have_libudev=yes],[have_libudev=no])
if test "$have_xcb_dri2" = yes; then
EGL_DRIVER_DRI2=dri2
-I$(TOP)/src/gallium/include \
-I$(TOP)/src/gallium/auxiliary \
-I$(TOP)/src/egl/main \
+ -I$(TOP)/src/egl/wayland/wayland-drm/ \
-I$(TOP)/include
common_SOURCES = $(wildcard common/*.c)
ifneq ($(findstring wayland, $(EGL_PLATFORMS)),)
EGL_OBJECTS += $(wayland_OBJECTS)
EGL_CPPFLAGS += -DHAVE_WAYLAND_BACKEND
+DEFINES += -DHAVE_WAYLAND_BACKEND
endif
ifneq ($(findstring drm, $(EGL_PLATFORMS)),)
EGL_OBJECTS += $(drm_OBJECTS)
if (dpy->Platform == _EGL_PLATFORM_WAYLAND && gdpy->native->buffer)
dpy->Extensions.MESA_drm_image = EGL_TRUE;
+#ifdef EGL_WL_bind_wayland_display
+ if (gdpy->native->wayland_bufmgr)
+ dpy->Extensions.WL_bind_wayland_display = EGL_TRUE;
+#endif
+
if (egl_g3d_add_configs(drv, dpy, 1) == 1) {
_eglError(EGL_NOT_INITIALIZED, "eglInitialize(unable to add configs)");
goto fail;
#endif /* EGL_MESA_screen_surface */
+#ifdef EGL_WL_bind_wayland_display
+
+static EGLBoolean
+egl_g3d_bind_wayland_display_wl(_EGLDriver *drv, _EGLDisplay *dpy,
+ struct wl_display *wl_dpy)
+{
+ struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
+
+ if (!gdpy->native->wayland_bufmgr)
+ return EGL_FALSE;
+
+ return gdpy->native->wayland_bufmgr->bind_display(gdpy->native, wl_dpy);
+}
+
+static EGLBoolean
+egl_g3d_unbind_wayland_display_wl(_EGLDriver *drv, _EGLDisplay *dpy,
+ struct wl_display *wl_dpy)
+{
+ struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
+
+ if (!gdpy->native->wayland_bufmgr)
+ return EGL_FALSE;
+
+ return gdpy->native->wayland_bufmgr->unbind_display(gdpy->native, wl_dpy);
+}
+
+#endif /* EGL_WL_bind_wayland_display */
+
void
egl_g3d_init_driver_api(_EGLDriver *drv)
{
drv->API.CreateDRMImageMESA = egl_g3d_create_drm_image;
drv->API.ExportDRMImageMESA = egl_g3d_export_drm_image;
#endif
+#ifdef EGL_WL_bind_wayland_display
+ drv->API.BindWaylandDisplayWL = egl_g3d_bind_wayland_display_wl;
+ drv->API.UnbindWaylandDisplayWL = egl_g3d_unbind_wayland_display_wl;
+
+#endif
#ifdef EGL_KHR_reusable_sync
drv->API.CreateSyncKHR = egl_g3d_create_sync;
#endif /* EGL_MESA_drm_image */
+#ifdef EGL_WL_bind_wayland_display
+
+static struct pipe_resource *
+egl_g3d_reference_wl_buffer(_EGLDisplay *dpy, struct wl_buffer *buffer,
+ _EGLImage *img, const EGLint *attribs)
+{
+ struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
+ struct pipe_resource *resource = NULL, *tmp = NULL;
+
+ if (!gdpy->native->wayland_bufmgr)
+ return NULL;
+
+ tmp = gdpy->native->wayland_bufmgr->buffer_get_resource(gdpy->native, buffer);
+
+ pipe_resource_reference(&resource, tmp);
+
+ return resource;
+}
+
+#endif /* EGL_WL_bind_wayland_display */
+
_EGLImage *
egl_g3d_create_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx,
EGLenum target, EGLClientBuffer buffer,
ptex = egl_g3d_reference_drm_buffer(dpy,
(EGLint) buffer, &gimg->base, attribs);
break;
+#endif
+#ifdef EGL_WL_bind_wayland_display
+ case EGL_WAYLAND_BUFFER_WL:
+ ptex = egl_g3d_reference_wl_buffer(dpy,
+ (struct wl_buffer *) buffer, &gimg->base, attribs);
+ break;
#endif
default:
ptex = NULL;
#include "native_buffer.h"
#include "native_modeset.h"
+#include "native_wayland_bufmgr.h"
/**
* Only color buffers are listed. The others are allocated privately through,
const struct native_display_buffer *buffer;
const struct native_display_modeset *modeset;
+ const struct native_display_wayland_bufmgr *wayland_bufmgr;
};
/**
--- /dev/null
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.11
+ *
+ * Copyright (C) 2011 Benjamin Franzke <benjaminfranzke@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_BUFMGR_H_
+#define _NATIVE_WAYLAND_BUFMGR_H_
+
+struct native_display;
+struct wl_display;
+struct wl_buffer;
+struct pipe_resource;
+
+struct native_display_wayland_bufmgr {
+ boolean (*bind_display)(struct native_display *ndpy,
+ struct wl_display *wl_dpy);
+
+ boolean (*unbind_display)(struct native_display *ndpy,
+ struct wl_display *wl_dpy);
+
+ struct pipe_resource *(*buffer_get_resource)(struct native_display *ndpy,
+ struct wl_buffer *buffer);
+
+};
+
+#endif /* _NATIVE_WAYLAND_BUFMGR_H_ */
--- /dev/null
+#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,
+ int32_t width, int32_t height,
+ uint32_t stride,
+ struct wl_visual *visual)
+{
+ struct native_display *ndpy = user_data;
+ struct pipe_resource templ;
+ struct winsys_handle wsh;
+ enum pipe_format format = PIPE_FORMAT_B8G8R8A8_UNORM;
+
+ memset(&templ, 0, sizeof(templ));
+ templ.target = PIPE_TEXTURE_2D;
+ templ.format = format;
+ templ.bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
+ templ.width0 = width;
+ templ.height0 = height;
+ templ.depth0 = 1;
+ templ.array_size = 1;
+
+ memset(&wsh, 0, sizeof(wsh));
+ wsh.handle = name;
+ wsh.stride = stride;
+
+ return ndpy->screen->resource_from_handle(ndpy->screen, &templ, &wsh);
+}
+
+void
+egl_g3d_wl_drm_helper_unreference_buffer(void *user_data, void *buffer)
+{
+ struct pipe_resource *resource = 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);
+}
+
+#endif
--- /dev/null
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.11
+ *
+ * Copyright (C) 2011 Benjamin Franzke <benjaminfranzke@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,
+ int32_t width, int32_t height,
+ uint32_t stride,
+ struct wl_visual *visual);
+
+void
+egl_g3d_wl_drm_helper_unreference_buffer(void *user_data, void *buffer);
+
+struct pipe_resource *
+egl_g3d_wl_drm_common_wl_buffer_get_resource(struct native_display *ndpy,
+ struct wl_buffer *buffer);
+
+#endif /* _NATIVE_WAYLAND_DRM_BUFMGR_HELPER_H_ */
* DEALINGS IN THE SOFTWARE.
*/
+#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <radeon_drm.h>
#include "radeon/drm/radeon_drm_public.h"
+#ifdef HAVE_LIBUDEV
+#include <libudev.h>
+#endif
+
static boolean
drm_display_is_format_supported(struct native_display *ndpy,
enum pipe_format fmt, boolean is_color)
ndpy_uninit(ndpy);
+ if (drmdpy->device_name)
+ FREE(drmdpy->device_name);
+
if (drmdpy->fd >= 0)
close(drmdpy->fd);
drm_display_export_buffer
};
+static int
+drm_display_authenticate(void *user_data, uint32_t magic)
+{
+ struct native_display *ndpy = user_data;
+ struct drm_display *drmdpy = drm_display(ndpy);
+
+ return drmAuthMagic(drmdpy->fd, magic);
+}
+
+static char *
+drm_get_device_name(int fd)
+{
+ char *device_name = NULL;
+#ifdef HAVE_LIBUDEV
+ struct udev *udev;
+ struct udev_device *device;
+ struct stat buf;
+ const char *tmp;
+
+ udev = udev_new();
+ if (fstat(fd, &buf) < 0) {
+ _eglLog(_EGL_WARNING, "failed to stat fd %d", fd);
+ goto out;
+ }
+
+ device = udev_device_new_from_devnum(udev, 'c', buf.st_rdev);
+ if (device == NULL) {
+ _eglLog(_EGL_WARNING,
+ "could not create udev device for fd %d", fd);
+ goto out;
+ }
+
+ tmp = udev_device_get_devnode(device);
+ if (!tmp)
+ goto out;
+ device_name = strdup(tmp);
+
+out:
+ udev_device_unref(device);
+ udev_unref(udev);
+
+#endif
+ return device_name;
+}
+
+#ifdef HAVE_WAYLAND_BACKEND
+
+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);
+
+ 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
+};
+
+#endif /* HAVE_WAYLAND_BACKEND */
+
static struct native_display *
drm_create_display(int fd, struct native_event_handler *event_handler,
void *user_data)
return NULL;
drmdpy->fd = fd;
+ drmdpy->device_name = drm_get_device_name(fd);
drmdpy->event_handler = event_handler;
drmdpy->base.user_data = user_data;
drmdpy->base.get_configs = drm_display_get_configs;
drmdpy->base.buffer = &drm_display_buffer;
+#ifdef HAVE_WAYLAND_BACKEND
+ if (drmdpy->device_name)
+ drmdpy->base.wayland_bufmgr = &drm_display_wayland_bufmgr;
+#endif
drm_display_init_modeset(&drmdpy->base);
return &drmdpy->base;
#include "common/native.h"
#include "common/native_helper.h"
+#ifdef HAVE_WAYLAND_BACKEND
+#include "common/native_wayland_drm_bufmgr_helper.h"
+#endif
+
struct drm_config;
struct drm_crtc;
struct drm_connector;
struct native_event_handler *event_handler;
int fd;
+ char *device_name;
struct drm_config *config;
/* for modesetting */
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 {
#include "wayland-drm-client-protocol.h"
#include "wayland-egl-priv.h"
+#include "common/native_wayland_drm_bufmgr_helper.h"
+
#include <xf86drm.h>
#include <sys/types.h>
#include <sys/stat.h>
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;
wayland_drm_display_export_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);
+ force_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);
+
+ 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
+};
+
+
struct wayland_display *
wayland_create_drm_display(struct wl_display *dpy,
struct native_event_handler *event_handler,
}
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;
#include "native_x11.h"
#include "x11_screen.h"
+#ifdef HAVE_WAYLAND_BACKEND
+#include "common/native_wayland_drm_bufmgr_helper.h"
+#endif
+
#ifdef GLX_DIRECT_RENDERING
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 {
return ((char *) key1 - (char *) key2);
}
+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);
+}
+
+#ifdef HAVE_WAYLAND_BACKEND
+
+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);
+
+ 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
+};
+
+#endif /* HAVE_WAYLAND_BACKEND */
+
struct native_display *
x11_create_dri2_display(Display *dpy,
struct native_event_handler *event_handler,
dri2dpy->base.is_pixmap_supported = dri2_display_is_pixmap_supported;
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;
}
return xscr->dri_fd;
}
+char *
+x11_screen_get_device_name(struct x11_screen *xscr)
+{
+ return xscr->dri_device;
+}
+
+int
+x11_screen_authenticate(struct x11_screen *xscr, uint32_t id)
+{
+ boolean authenticated;
+
+ authenticated = DRI2Authenticate(xscr->dpy,
+ RootWindow(xscr->dpy, xscr->number), id);
+
+ return authenticated ? 0 : -1;
+}
+
/**
* Create/Destroy the DRI drawable.
*/
x11_drawable_invalidate_buffers invalidate_buffers,
void *user_data);
+char *
+x11_screen_get_device_name(struct x11_screen *xscr);
+
+int
+x11_screen_authenticate(struct x11_screen *xscr, uint32_t id);
+
void
x11_drawable_enable_dri2(struct x11_screen *xscr,
Drawable drawable, boolean on);
ifneq ($(findstring wayland, $(EGL_PLATFORMS)),)
egl_SYS += $(WAYLAND_LIBS) $(LIBDRM_LIB)
egl_LIBS += $(TOP)/src/gallium/winsys/sw/wayland/libws_wayland.a
+egl_LIBS += $(TOP)/src/egl/wayland/wayland-drm/libwayland-drm.a
endif
ifneq ($(findstring drm, $(EGL_PLATFORMS)),)
egl_SYS += $(LIBDRM_LIB)