summaryrefslogtreecommitdiffstats
path: root/src/egl/drivers/dri2
diff options
context:
space:
mode:
authorChristian König <[email protected]>2011-04-23 14:27:40 +0200
committerChristian König <[email protected]>2011-04-23 14:27:40 +0200
commitfa31b1095eeea97695125ad5770239805bed37da (patch)
tree6c421666719a9a1afc419de33d06f4e66584a8a1 /src/egl/drivers/dri2
parent24d76d2966a5c666c9627034e6751621b17024c8 (diff)
parent15eaf8297ecb39337109b95480e61f37a6b20f0a (diff)
Merge remote branch 'origin/master' into pipe-video
Conflicts: configs/linux-dri src/gallium/drivers/r600/r600_pipe.c src/gallium/drivers/r600/r600_state.c src/gallium/include/pipe/p_format.h src/gallium/tests/graw/fragment-shader/frag-abs.sh src/gallium/tests/graw/fragment-shader/frag-add.sh src/gallium/tests/graw/fragment-shader/frag-cb-1d.sh src/gallium/tests/graw/fragment-shader/frag-cb-2d.sh src/gallium/tests/graw/fragment-shader/frag-dp3.sh src/gallium/tests/graw/fragment-shader/frag-dp4.sh src/gallium/tests/graw/fragment-shader/frag-dst.sh src/gallium/tests/graw/fragment-shader/frag-ex2.sh src/gallium/tests/graw/fragment-shader/frag-face.sh src/gallium/tests/graw/fragment-shader/frag-flr.sh src/gallium/tests/graw/fragment-shader/frag-frc.sh src/gallium/tests/graw/fragment-shader/frag-kil.sh src/gallium/tests/graw/fragment-shader/frag-lg2.sh src/gallium/tests/graw/fragment-shader/frag-lit.sh src/gallium/tests/graw/fragment-shader/frag-lrp.sh src/gallium/tests/graw/fragment-shader/frag-mad-immx.sh src/gallium/tests/graw/fragment-shader/frag-mad.sh src/gallium/tests/graw/fragment-shader/frag-max.sh src/gallium/tests/graw/fragment-shader/frag-min.sh src/gallium/tests/graw/fragment-shader/frag-mov.sh src/gallium/tests/graw/fragment-shader/frag-mul.sh src/gallium/tests/graw/fragment-shader/frag-rcp.sh src/gallium/tests/graw/fragment-shader/frag-rsq.sh src/gallium/tests/graw/fragment-shader/frag-sge.sh src/gallium/tests/graw/fragment-shader/frag-slt.sh src/gallium/tests/graw/fragment-shader/frag-srcmod-abs.sh src/gallium/tests/graw/fragment-shader/frag-srcmod-absneg.sh src/gallium/tests/graw/fragment-shader/frag-srcmod-neg.sh src/gallium/tests/graw/fragment-shader/frag-srcmod-swz.sh src/gallium/tests/graw/fragment-shader/frag-sub.sh src/gallium/tests/graw/fragment-shader/frag-tempx.sh src/gallium/tests/graw/fragment-shader/frag-xpd.sh src/gallium/tests/graw/vertex-shader/vert-abs.sh src/gallium/tests/graw/vertex-shader/vert-add.sh src/gallium/tests/graw/vertex-shader/vert-arl.sh src/gallium/tests/graw/vertex-shader/vert-arr.sh src/gallium/tests/graw/vertex-shader/vert-cb-1d.sh src/gallium/tests/graw/vertex-shader/vert-cb-2d.sh src/gallium/tests/graw/vertex-shader/vert-dp3.sh src/gallium/tests/graw/vertex-shader/vert-dp4.sh src/gallium/tests/graw/vertex-shader/vert-dst.sh src/gallium/tests/graw/vertex-shader/vert-ex2.sh src/gallium/tests/graw/vertex-shader/vert-flr.sh src/gallium/tests/graw/vertex-shader/vert-frc.sh src/gallium/tests/graw/vertex-shader/vert-lg2.sh src/gallium/tests/graw/vertex-shader/vert-lit.sh src/gallium/tests/graw/vertex-shader/vert-lrp.sh src/gallium/tests/graw/vertex-shader/vert-mad.sh src/gallium/tests/graw/vertex-shader/vert-max.sh src/gallium/tests/graw/vertex-shader/vert-min.sh src/gallium/tests/graw/vertex-shader/vert-mov.sh src/gallium/tests/graw/vertex-shader/vert-mul.sh src/gallium/tests/graw/vertex-shader/vert-rcp.sh src/gallium/tests/graw/vertex-shader/vert-rsq.sh src/gallium/tests/graw/vertex-shader/vert-sge.sh src/gallium/tests/graw/vertex-shader/vert-slt.sh src/gallium/tests/graw/vertex-shader/vert-srcmod-abs.sh src/gallium/tests/graw/vertex-shader/vert-srcmod-absneg.sh src/gallium/tests/graw/vertex-shader/vert-srcmod-neg.sh src/gallium/tests/graw/vertex-shader/vert-srcmod-swz.sh src/gallium/tests/graw/vertex-shader/vert-sub.sh src/gallium/tests/graw/vertex-shader/vert-xpd.sh src/gallium/tools/trace/dump.py src/gallium/tools/trace/format.py src/gallium/tools/trace/model.py src/gallium/tools/trace/parse.py
Diffstat (limited to 'src/egl/drivers/dri2')
-rw-r--r--src/egl/drivers/dri2/egl_dri2.c6
-rw-r--r--src/egl/drivers/dri2/egl_dri2.h4
-rw-r--r--src/egl/drivers/dri2/platform_drm.c5
-rw-r--r--src/egl/drivers/dri2/platform_wayland.c158
-rw-r--r--src/egl/drivers/dri2/platform_x11.c8
5 files changed, 112 insertions, 69 deletions
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index f7e063b3524..5e47fbe126a 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -462,6 +462,12 @@ dri2_create_screen(_EGLDisplay *disp)
}
}
+ if (dri2_dpy->image) {
+ disp->Extensions.MESA_drm_image = EGL_TRUE;
+ disp->Extensions.KHR_image_base = EGL_TRUE;
+ disp->Extensions.KHR_gl_renderbuffer_image = EGL_TRUE;
+ }
+
return EGL_TRUE;
cleanup_dri_screen:
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index cb1de2681f1..99f990ac688 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -85,8 +85,10 @@ struct dri2_egl_display
__DRIswrastLoaderExtension swrast_loader_extension;
const __DRIextension *extensions[3];
#ifdef HAVE_WAYLAND_PLATFORM
- struct wl_egl_display *wl_dpy;
+ struct wl_display *wl_dpy;
struct wl_drm *wl_server_drm;
+ struct wl_drm *wl_drm;
+ int authenticated;
#endif
int (*authenticate) (_EGLDisplay *disp, uint32_t id);
diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c
index bd4fa80af59..9c6d3ddac22 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -708,11 +708,6 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
for (i = 0; dri2_dpy->driver_configs[i]; i++)
dri2_add_config(disp, dri2_dpy->driver_configs[i], i + 1, 0, 0, NULL);
- disp->Extensions.MESA_drm_image = EGL_TRUE;
- disp->Extensions.KHR_image_base = EGL_TRUE;
- disp->Extensions.KHR_gl_renderbuffer_image = EGL_TRUE;
- disp->Extensions.KHR_gl_texture_2D_image = EGL_TRUE;
-
#ifdef HAVE_WAYLAND_PLATFORM
disp->Extensions.WL_bind_wayland_display = EGL_TRUE;
#endif
diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c
index 6ae3f6554b1..030c68777af 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -32,6 +32,8 @@
#include <dlfcn.h>
#include <errno.h>
#include <unistd.h>
+#include <fcntl.h>
+#include <xf86drm.h>
#include "egl_dri2.h"
@@ -107,7 +109,7 @@ dri2_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
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;
}
@@ -204,7 +206,19 @@ dri2_wl_egl_pixmap_destroy(struct wl_egl_pixmap *egl_pixmap)
egl_pixmap->driver_private = NULL;
egl_pixmap->destroy = NULL;
- egl_pixmap->name = 0;
+}
+
+static struct wl_buffer *
+wayland_create_buffer(struct dri2_egl_surface *dri2_surf,
+ __DRIbuffer *buffer,
+ struct wl_visual *visual)
+{
+ struct dri2_egl_display *dri2_dpy =
+ dri2_egl_display(dri2_surf->base.Resource.Display);
+
+ return wl_drm_create_buffer(dri2_dpy->wl_drm, buffer->name,
+ dri2_surf->base.Width, dri2_surf->base.Height,
+ buffer->pitch, visual);
}
static void
@@ -244,8 +258,6 @@ dri2_process_front_buffer(struct dri2_egl_surface *dri2_surf, unsigned format)
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;
@@ -282,9 +294,9 @@ dri2_release_buffers(struct dri2_egl_surface *dri2_surf)
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:
@@ -357,6 +369,12 @@ dri2_get_buffers_with_format(__DRIdrawable * driDrawable,
assert(dri2_surf->type == DRI2_PIXMAP_SURFACE ||
dri2_surf->dri_buffers[__DRI_BUFFER_BACK_LEFT]);
+ if (dri2_surf->type == DRI2_PIXMAP_SURFACE && !dri2_surf->wl_pix->buffer)
+ dri2_surf->wl_pix->buffer =
+ wayland_create_buffer(dri2_surf,
+ dri2_surf->dri_buffers[__DRI_BUFFER_FRONT_LEFT],
+ dri2_surf->wl_pix->visual);
+
*out_count = dri2_surf->buffer_count;
if (dri2_surf->buffer_count == 0)
return NULL;
@@ -417,19 +435,8 @@ dri2_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate)
#endif
}
-static struct wl_buffer *
-wayland_create_buffer(struct dri2_egl_surface *dri2_surf, __DRIbuffer *buffer)
-{
- 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,
- dri2_surf->base.Width, dri2_surf->base.Height,
- buffer->pitch, dri2_surf->wl_win->visual);
-}
-
static void
-wayland_frame_callback(void *data, uint32_t time)
+wayland_frame_callback(struct wl_surface *surface, void *data, uint32_t time)
{
struct dri2_egl_surface *dri2_surf = data;
@@ -455,11 +462,12 @@ dri2_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw)
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,
- wayland_frame_callback, dri2_surf);
+ wl_display_frame_callback(dri2_dpy->wl_dpy,
+ dri2_surf->wl_win->surface,
+ wayland_frame_callback, dri2_surf);
if (dri2_surf->type == DRI2_WINDOW_SURFACE) {
pointer_swap(
@@ -477,8 +485,11 @@ dri2_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw)
if (!dri2_surf->wl_drm_buffer[WL_BUFFER_FRONT])
dri2_surf->wl_drm_buffer[WL_BUFFER_FRONT] =
wayland_create_buffer(dri2_surf,
- dri2_surf->dri_buffers[__DRI_BUFFER_FRONT_LEFT]);
+ dri2_surf->dri_buffers[__DRI_BUFFER_FRONT_LEFT],
+ dri2_surf->wl_win->visual);
+ wl_buffer_damage(dri2_surf->wl_drm_buffer[WL_BUFFER_FRONT], 0, 0,
+ dri2_surf->base.Width, dri2_surf->base.Height);
wl_surface_attach(dri2_surf->wl_win->surface,
dri2_surf->wl_drm_buffer[WL_BUFFER_FRONT],
dri2_surf->dx, dri2_surf->dy);
@@ -535,18 +546,23 @@ dri2_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx,
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 *
@@ -570,16 +586,16 @@ dri2_wayland_authenticate(_EGLDisplay *disp, uint32_t id)
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;
}
@@ -605,10 +621,45 @@ dri2_terminate(_EGLDriver *drv, _EGLDisplay *disp)
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;
@@ -627,21 +678,23 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp)
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, "wl_drm", 1);
+ if (id == 0)
+ wl_display_iterate(dri2_dpy->wl_dpy, WL_DISPLAY_READABLE);
+ id = wl_display_get_global(dri2_dpy->wl_dpy, "wl_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) {
@@ -649,14 +702,8 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp)
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;
@@ -677,11 +724,7 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp)
EGL_WINDOW_BIT | EGL_PIXMAP_BIT, NULL);
- disp->Extensions.MESA_drm_image = EGL_TRUE;
- disp->Extensions.KHR_image_base = EGL_TRUE;
disp->Extensions.KHR_image_pixmap = EGL_TRUE;
- disp->Extensions.KHR_gl_renderbuffer_image = EGL_TRUE;
- disp->Extensions.KHR_gl_texture_2D_image = EGL_TRUE;
disp->Extensions.WL_bind_wayland_display = EGL_TRUE;
dri2_dpy->authenticate = dri2_wayland_authenticate;
@@ -694,12 +737,13 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp)
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);
diff --git a/src/egl/drivers/dri2/platform_x11.c b/src/egl/drivers/dri2/platform_x11.c
index b3e60b8a115..5d4ac6ae948 100644
--- a/src/egl/drivers/dri2/platform_x11.c
+++ b/src/egl/drivers/dri2/platform_x11.c
@@ -231,7 +231,7 @@ dri2_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
if (dri2_dpy->dri2) {
xcb_dri2_create_drawable (dri2_dpy->conn, dri2_surf->drawable);
} else {
- swrastCreateDrawable(dri2_dpy, dri2_surf, _eglGetConfigKey(conf, EGL_DEPTH_SIZE));
+ swrastCreateDrawable(dri2_dpy, dri2_surf, _eglGetConfigKey(conf, EGL_BUFFER_SIZE));
}
if (type != EGL_PBUFFER_BIT) {
@@ -990,7 +990,7 @@ dri2_initialize_x11_dri2(_EGLDriver *drv, _EGLDisplay *disp)
if (!dri2_load_driver(disp))
goto cleanup_conn;
- dri2_dpy->fd = open(dri2_dpy->device_name, O_RDWR);
+ dri2_dpy->fd = open(dri2_dpy->device_name, O_RDWR | O_CLOEXEC);
if (dri2_dpy->fd == -1) {
_eglLog(_EGL_WARNING,
"DRI2: could not open %s (%s)", dri2_dpy->device_name,
@@ -1030,11 +1030,7 @@ dri2_initialize_x11_dri2(_EGLDriver *drv, _EGLDisplay *disp)
goto cleanup_configs;
}
- disp->Extensions.MESA_drm_image = EGL_TRUE;
- disp->Extensions.KHR_image_base = EGL_TRUE;
disp->Extensions.KHR_image_pixmap = EGL_TRUE;
- disp->Extensions.KHR_gl_renderbuffer_image = EGL_TRUE;
- disp->Extensions.KHR_gl_texture_2D_image = EGL_TRUE;
disp->Extensions.NOK_swap_region = EGL_TRUE;
disp->Extensions.NOK_texture_from_pixmap = EGL_TRUE;