#include <dlfcn.h>
#include <errno.h>
#include <unistd.h>
+#include <fcntl.h>
+#include <xf86drm.h>
#include "egl_dri2.h"
dri2_surf->base.Width = dri2_surf->wl_pix->width;
dri2_surf->base.Height = dri2_surf->wl_pix->height;
- if (dri2_surf->wl_pix->name > 0) {
+ if (dri2_surf->wl_pix->driver_private) {
dri2_buf = dri2_surf->wl_pix->driver_private;
dri2_surf->dri_buffers[__DRI_BUFFER_FRONT_LEFT] = dri2_buf->dri_buffer;
}
egl_pixmap->driver_private = NULL;
egl_pixmap->destroy = NULL;
- egl_pixmap->name = 0;
}
static void
dri2_buf->dri_buffer = dri2_surf->dri_buffers[__DRI_BUFFER_FRONT_LEFT];
dri2_buf->dri2_dpy = dri2_dpy;
- dri2_surf->wl_pix->name = dri2_buf->dri_buffer->name;
- dri2_surf->wl_pix->stride = dri2_buf->dri_buffer->pitch;
dri2_surf->wl_pix->driver_private = dri2_buf;
dri2_surf->wl_pix->destroy = dri2_wl_egl_pixmap_destroy;
break;
switch (i) {
case __DRI_BUFFER_FRONT_LEFT:
if (dri2_surf->pending_buffer)
- force_roundtrip(dri2_dpy->wl_dpy->display);
+ force_roundtrip(dri2_dpy->wl_dpy);
dri2_surf->pending_buffer = dri2_surf->dri_buffers[i];
- wl_display_sync_callback(dri2_dpy->wl_dpy->display,
+ wl_display_sync_callback(dri2_dpy->wl_dpy,
dri2_release_pending_buffer, dri2_surf);
break;
default:
struct dri2_egl_display *dri2_dpy =
dri2_egl_display(dri2_surf->base.Resource.Display);
- return wl_drm_create_buffer(dri2_dpy->wl_dpy->drm, buffer->name,
+ return wl_drm_create_buffer(dri2_dpy->wl_drm, buffer->name,
dri2_surf->base.Width, dri2_surf->base.Height,
buffer->pitch, dri2_surf->wl_win->visual);
}
struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv);
while (dri2_surf->block_swap_buffers)
- wl_display_iterate(dri2_dpy->wl_dpy->display, WL_DISPLAY_READABLE);
+ wl_display_iterate(dri2_dpy->wl_dpy, WL_DISPLAY_READABLE);
dri2_surf->block_swap_buffers = EGL_TRUE;
- wl_display_frame_callback(dri2_dpy->wl_dpy->display,
+ wl_display_frame_callback(dri2_dpy->wl_dpy,
dri2_surf->wl_win->surface,
wayland_frame_callback, dri2_surf);
wl_egl_pixmap->width,
wl_egl_pixmap->height);
- wl_egl_pixmap->name = dri2_buf->dri_buffer->name;
- wl_egl_pixmap->stride = dri2_buf->dri_buffer->pitch;
wl_egl_pixmap->destroy = dri2_wl_egl_pixmap_destroy;
wl_egl_pixmap->driver_private = dri2_buf;
+ wl_egl_pixmap->buffer =
+ wl_drm_create_buffer(dri2_dpy->wl_drm,
+ dri2_buf->dri_buffer->name,
+ wl_egl_pixmap->width,
+ wl_egl_pixmap->height,
+ dri2_buf->dri_buffer->pitch,
+ wl_egl_pixmap->visual);
+
wl_attr_list[1] = wl_egl_pixmap->width;
wl_attr_list[3] = wl_egl_pixmap->height;
- wl_attr_list[5] = wl_egl_pixmap->stride / 4;
-
+ wl_attr_list[5] = dri2_buf->dri_buffer->pitch / 4;
return dri2_create_image_khr(disp->Driver, disp, ctx, EGL_DRM_BUFFER_MESA,
- (EGLClientBuffer)(intptr_t) wl_egl_pixmap->name, wl_attr_list);
+ (EGLClientBuffer)(intptr_t) dri2_buf->dri_buffer->name, wl_attr_list);
}
static _EGLImage *
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
int ret = 0;
- dri2_dpy->wl_dpy->authenticated = false;
+ dri2_dpy->authenticated = false;
- wl_drm_authenticate(dri2_dpy->wl_dpy->drm, id);
- force_roundtrip(dri2_dpy->wl_dpy->display);
+ wl_drm_authenticate(dri2_dpy->wl_drm, id);
+ force_roundtrip(dri2_dpy->wl_dpy);
- if (!dri2_dpy->wl_dpy->authenticated)
+ if (!dri2_dpy->authenticated)
ret = -1;
/* reset authenticated */
- dri2_dpy->wl_dpy->authenticated = true;
+ dri2_dpy->authenticated = true;
return ret;
}
return EGL_TRUE;
}
+static void
+drm_handle_device(void *data, struct wl_drm *drm, const char *device)
+{
+ struct dri2_egl_display *dri2_dpy = data;
+ drm_magic_t magic;
+
+ dri2_dpy->device_name = strdup(device);
+ if (!dri2_dpy->device_name)
+ return;
+
+ dri2_dpy->fd = open(dri2_dpy->device_name, O_RDWR);
+ if (dri2_dpy->fd == -1) {
+ _eglLog(_EGL_WARNING, "wayland-egl: could not open %s (%s)",
+ dri2_dpy->device_name, strerror(errno));
+ return;
+ }
+
+ drmGetMagic(dri2_dpy->fd, &magic);
+ wl_drm_authenticate(dri2_dpy->wl_drm, magic);
+}
+
+static void
+drm_handle_authenticated(void *data, struct wl_drm *drm)
+{
+ struct dri2_egl_display *dri2_dpy = data;
+
+ dri2_dpy->authenticated = true;
+}
+
+static const struct wl_drm_listener drm_listener = {
+ drm_handle_device,
+ drm_handle_authenticated
+};
+
EGLBoolean
dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp)
{
struct dri2_egl_display *dri2_dpy;
+ uint32_t id;
int i;
drv->API.CreateWindowSurface = dri2_create_window_surface;
disp->DriverData = (void *) dri2_dpy;
dri2_dpy->wl_dpy = disp->PlatformDisplay;
- if (dri2_dpy->wl_dpy->fd == -1)
- force_roundtrip(dri2_dpy->wl_dpy->display);
- if (dri2_dpy->wl_dpy->fd == -1)
+ id = wl_display_get_global(dri2_dpy->wl_dpy, "drm", 1);
+ if (id == 0)
+ wl_display_iterate(dri2_dpy->wl_dpy, WL_DISPLAY_READABLE);
+ id = wl_display_get_global(dri2_dpy->wl_dpy, "drm", 1);
+ if (id == 0)
goto cleanup_dpy;
-
- dri2_dpy->fd = dup(dri2_dpy->wl_dpy->fd);
- if (dri2_dpy->fd < 0) {
- _eglError(EGL_BAD_ALLOC, "DRI2: failed to dup fd");
+ dri2_dpy->wl_drm = wl_drm_create(dri2_dpy->wl_dpy, id, 1);
+ if (!dri2_dpy->wl_drm)
goto cleanup_dpy;
- }
+ wl_drm_add_listener(dri2_dpy->wl_drm, &drm_listener, dri2_dpy);
+ force_roundtrip(dri2_dpy->wl_dpy);
+ if (dri2_dpy->fd == -1)
+ goto cleanup_drm;
- if (!dri2_dpy->wl_dpy->authenticated)
- force_roundtrip(dri2_dpy->wl_dpy->display);
- if (!dri2_dpy->wl_dpy->authenticated)
- goto cleanup_dpy;
+ force_roundtrip(dri2_dpy->wl_dpy);
+ if (!dri2_dpy->authenticated)
+ goto cleanup_fd;
dri2_dpy->driver_name = dri2_get_driver_for_fd(dri2_dpy->fd);
if (dri2_dpy->driver_name == NULL) {
goto cleanup_fd;
}
- dri2_dpy->device_name = strdup(dri2_dpy->wl_dpy->device_name);
- if (dri2_dpy->device_name == NULL) {
- _eglError(EGL_BAD_ALLOC, "DRI2: failed to get device name");
- goto cleanup_driver_name;
- }
-
if (!dri2_load_driver(disp))
- goto cleanup_device_name;
+ goto cleanup_driver_name;
dri2_dpy->dri2_loader_extension.base.name = __DRI_DRI2_LOADER;
dri2_dpy->dri2_loader_extension.base.version = 3;
cleanup_driver:
dlclose(dri2_dpy->driver);
- cleanup_device_name:
- free(dri2_dpy->device_name);
cleanup_driver_name:
free(dri2_dpy->driver_name);
cleanup_fd:
close(dri2_dpy->fd);
+ cleanup_drm:
+ free(dri2_dpy->device_name);
+ wl_drm_destroy(dri2_dpy->wl_drm);
cleanup_dpy:
free(dri2_dpy);
#include "wayland-drm-client-protocol.h"
#include <xf86drm.h>
-static void
-drm_handle_device(void *data, struct wl_drm *drm, const char *device)
-{
- struct wl_egl_display *egl_display = data;
- drm_magic_t magic;
-
- egl_display->device_name = strdup(device);
-
- egl_display->fd = open(egl_display->device_name, O_RDWR);
-
- if (egl_display->fd == -1) {
- fprintf(stderr, "wayland-egl: could not open %s (%s)",
- egl_display->device_name, strerror(errno));
- return;
- }
- drmGetMagic(egl_display->fd, &magic);
- wl_drm_authenticate(egl_display->drm, magic);
-}
-
-static void
-drm_handle_authenticated(void *data, struct wl_drm *drm)
-{
- struct wl_egl_display *egl_display = data;
-
- egl_display->authenticated = true;
-}
-
-static const struct wl_drm_listener drm_listener = {
- drm_handle_device,
- drm_handle_authenticated
-};
-
-static void
-wl_display_handle_global(struct wl_display *display, uint32_t id,
- const char *interface, uint32_t version, void *data)
-{
- struct wl_egl_display *egl_display = data;
-
- if (strcmp(interface, "drm") == 0) {
- egl_display->drm = wl_drm_create(display, id);
- wl_drm_add_listener(egl_display->drm, &drm_listener,
- egl_display);
- }
-}
-
-/* stolen from egl_dri2:dri2_load() */
-static void *
-get_flush_address() {
- void *handle;
- void *(*get_proc_address)(const char *procname);
-
- handle = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL);
- if (handle) {
- get_proc_address = (void* (*)(const char *))
- dlsym(handle, "_glapi_get_proc_address");
- /* no need to keep a reference */
- dlclose(handle);
- }
-
- /*
- * If glapi is not available, loading DRI drivers will fail. Ideally, we
- * should load one of libGL, libGLESv1_CM, or libGLESv2 and go on. But if
- * the app has loaded another one of them with RTLD_LOCAL, there may be
- * unexpected behaviors later because there will be two copies of glapi
- * (with global variables of the same names!) in the memory.
- */
- if (!get_proc_address) {
- fprintf(stderr, "failed to find _glapi_get_proc_address");
- return NULL;
- }
-
- return get_proc_address("glFlush");
-}
-
-WL_EGL_EXPORT struct wl_egl_display *
-wl_egl_display_create(struct wl_display *display)
-{
- struct wl_egl_display *egl_display;
-
- egl_display = malloc(sizeof *egl_display);
- if (!egl_display)
- return NULL;
-
- egl_display->display = display;
- egl_display->drm = NULL;
- egl_display->fd = -1;
- egl_display->device_name = NULL;
- egl_display->authenticated = false;
-
- egl_display->glFlush = (void (*)(void)) get_flush_address();
-
- wl_display_add_global_listener(display, wl_display_handle_global,
- egl_display);
-
- return egl_display;
-}
-
-WL_EGL_EXPORT void
-wl_egl_display_destroy(struct wl_egl_display *egl_display)
-{
-
- free(egl_display->device_name);
- close(egl_display->fd);
-
- wl_drm_destroy(egl_display->drm);
-
- free(egl_display);
-}
-
WL_EGL_EXPORT void
wl_egl_window_resize(struct wl_egl_window *egl_window,
int width, int height,
}
WL_EGL_EXPORT struct wl_egl_window *
-wl_egl_window_create(struct wl_egl_display *egl_display,
- struct wl_surface *surface,
+wl_egl_window_create(struct wl_surface *surface,
int width, int height,
struct wl_visual *visual)
{
}
WL_EGL_EXPORT struct wl_egl_pixmap *
-wl_egl_pixmap_create(struct wl_egl_display *egl_display,
- int width, int height,
+wl_egl_pixmap_create(int width, int height,
struct wl_visual *visual, uint32_t flags)
{
struct wl_egl_pixmap *egl_pixmap;
if (egl_pixmap == NULL)
return NULL;
- egl_pixmap->display = egl_display;
egl_pixmap->width = width;
egl_pixmap->height = height;
egl_pixmap->visual = visual;
- egl_pixmap->name = 0;
- egl_pixmap->stride = 0;
egl_pixmap->destroy = NULL;
}
WL_EGL_EXPORT struct wl_buffer *
-wl_egl_pixmap_create_buffer(struct wl_egl_display *egl_display,
- struct wl_egl_pixmap *egl_pixmap)
-{
- if (egl_pixmap->name == 0)
- return NULL;
-
- return wl_drm_create_buffer(egl_display->drm, egl_pixmap->name,
- egl_pixmap->width, egl_pixmap->height,
- egl_pixmap->stride, egl_pixmap->visual);
-}
-
-WL_EGL_EXPORT void
-wl_egl_pixmap_flush(struct wl_egl_display *egl_display,
- struct wl_egl_pixmap *egl_pixmap)
+wl_egl_pixmap_create_buffer(struct wl_egl_pixmap *egl_pixmap)
{
- if (egl_display->glFlush)
- egl_display->glFlush();
+ return egl_pixmap->buffer;
}