[PATCH 13/19] Xephyr: move ephyrdri over to xcb
Julien Cristau
jcristau at debian.org
Wed Oct 20 10:11:55 PDT 2010
Require new xcb-xf86dri to get fixed GetDrawableInfo.
Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>
Signed-off-by: Julien Cristau <jcristau at debian.org>
---
configure.ac | 2 +-
hw/kdrive/ephyr/ephyrdri.c | 205 +++++++++++++++++++++++++++++++-------------
2 files changed, 145 insertions(+), 62 deletions(-)
diff --git a/configure.ac b/configure.ac
index 0cce083..2a0c80a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2066,7 +2066,7 @@ if test "$KDRIVE" = yes; then
XEPHYR_REQUIRED_LIBS="$XEPHYR_REQUIRED_LIBS xcb-xv"
fi
if test "x$DRI" = xyes && test "x$GLX" = xyes; then
- XEPHYR_REQUIRED_LIBS="$XEPHYR_REQUIRED_LIBS $LIBGL libdrm xcb-glx xcb-xf86dri"
+ XEPHYR_REQUIRED_LIBS="$XEPHYR_REQUIRED_LIBS $LIBGL libdrm xcb-glx xcb-xf86dri > 1.6"
fi
PKG_CHECK_MODULES(XEPHYR, $XEPHYR_REQUIRED_LIBS, [xephyr="yes"], [xephyr="no"])
diff --git a/hw/kdrive/ephyr/ephyrdri.c b/hw/kdrive/ephyr/ephyrdri.c
index 932e468..8f9d0d2 100644
--- a/hw/kdrive/ephyr/ephyrdri.c
+++ b/hw/kdrive/ephyr/ephyrdri.c
@@ -29,10 +29,8 @@
#include <kdrive-config.h>
#endif
-#include <X11/Xutil.h>
-#include <X11/Xlibint.h>
-#include <GL/glx.h>
-#include "xf86dri.h"
+#include <X11/Xdefs.h>
+#include <xcb/xf86dri.h>
#include "hostx.h"
#include "ephyrdri.h"
#define _HAVE_XALLOC_DECLS
@@ -51,13 +49,21 @@
Bool
ephyrDRIQueryDirectRenderingCapable (int a_screen, Bool *a_is_capable)
{
- Display *dpy=hostx_get_display () ;
+ xcb_connection_t *conn = hostx_get_xcbconn();
Bool is_ok=FALSE ;
+ xcb_xf86dri_query_direct_rendering_capable_cookie_t cookie;
+ xcb_xf86dri_query_direct_rendering_capable_reply_t *reply;
EPHYR_RETURN_VAL_IF_FAIL (a_is_capable, FALSE) ;
EPHYR_LOG ("enter\n") ;
- is_ok = XF86DRIQueryDirectRenderingCapable (dpy, DefaultScreen (dpy),
- a_is_capable) ;
+ cookie = xcb_xf86dri_query_direct_rendering_capable(conn,
+ hostx_get_screen());
+ reply = xcb_xf86dri_query_direct_rendering_capable_reply(conn, cookie, NULL);
+ if (reply) {
+ is_ok = TRUE;
+ *a_is_capable = reply->is_capable;
+ }
+ free(reply);
EPHYR_LOG ("leave. is_capable:%d, is_ok=%d\n", *a_is_capable, is_ok) ;
return is_ok ;
@@ -68,32 +74,49 @@ ephyrDRIOpenConnection (int a_screen,
drm_handle_t *a_sarea,
char **a_bus_id_string)
{
- Display *dpy = hostx_get_display () ;
+ xcb_connection_t *conn = hostx_get_xcbconn();
Bool is_ok=FALSE ;
+ xcb_xf86dri_open_connection_cookie_t cookie;
+ xcb_xf86dri_open_connection_reply_t *reply;
EPHYR_RETURN_VAL_IF_FAIL (a_bus_id_string, FALSE) ;
EPHYR_LOG ("enter. screen:%d\n", a_screen) ;
- is_ok = XF86DRIOpenConnection (dpy, DefaultScreen (dpy),
- a_sarea,
- a_bus_id_string) ;
- if (*a_bus_id_string) {
- EPHYR_LOG ("leave. bus_id_string:%s, is_ok:%d\n",
- *a_bus_id_string, is_ok) ;
- } else {
- EPHYR_LOG ("leave. bus_id_string:null, is_ok:%d\n",
- is_ok) ;
+ cookie = xcb_xf86dri_open_connection(conn, hostx_get_screen());
+ reply = xcb_xf86dri_open_connection_reply(conn, cookie, NULL);
+ if (!reply)
+ goto out;
+ *a_sarea = reply->sarea_handle_low;
+ if (sizeof(drm_handle_t) == 8) {
+ int shift = 32;
+ *a_sarea |= ((drm_handle_t) reply->sarea_handle_high) << shift;
}
+ *a_bus_id_string = malloc(reply->bus_id_len + 1);
+ if (!*a_bus_id_string)
+ goto out;
+ memcpy(*a_bus_id_string, xcb_xf86dri_open_connection_bus_id(reply), reply->bus_id_len);
+ *a_bus_id_string[reply->bus_id_len] = '\0';
+ is_ok = TRUE;
+out:
+ free(reply);
+ EPHYR_LOG ("leave. bus_id_string:%s, is_ok:%d\n",
+ *a_bus_id_string, is_ok) ;
return is_ok ;
}
Bool
ephyrDRIAuthConnection (int a_screen, drm_magic_t a_magic)
{
- Display *dpy = hostx_get_display () ;
+ xcb_connection_t *conn = hostx_get_xcbconn () ;
+ int screen = hostx_get_screen();
+ xcb_xf86dri_auth_connection_cookie_t cookie;
+ xcb_xf86dri_auth_connection_reply_t *reply;
Bool is_ok=FALSE ;
EPHYR_LOG ("enter\n") ;
- is_ok = XF86DRIAuthConnection (dpy, DefaultScreen (dpy), a_magic) ;
+ cookie = xcb_xf86dri_auth_connection(conn, screen, a_magic);
+ reply = xcb_xf86dri_auth_connection_reply(conn, cookie, NULL);
+ is_ok = reply->authenticated;
+ free(reply);
EPHYR_LOG ("leave. is_ok:%d\n", is_ok) ;
return is_ok ;
}
@@ -101,13 +124,13 @@ ephyrDRIAuthConnection (int a_screen, drm_magic_t a_magic)
Bool
ephyrDRICloseConnection (int a_screen)
{
- Display *dpy = hostx_get_display () ;
- Bool is_ok=FALSE ;
+ xcb_connection_t *conn = hostx_get_xcbconn () ;
+ int screen = hostx_get_screen();
EPHYR_LOG ("enter\n") ;
- is_ok = XF86DRICloseConnection (dpy, DefaultScreen (dpy)) ;
+ xcb_xf86dri_close_connection(conn, screen);
EPHYR_LOG ("leave\n") ;
- return is_ok ;
+ return TRUE;
}
Bool
@@ -117,7 +140,10 @@ ephyrDRIGetClientDriverName (int a_screen,
int *a_ddx_driver_patch_version,
char ** a_client_driver_name)
{
- Display *dpy = hostx_get_display () ;
+ xcb_connection_t *conn = hostx_get_xcbconn () ;
+ int screen = hostx_get_screen();
+ xcb_xf86dri_get_client_driver_name_cookie_t cookie;
+ xcb_xf86dri_get_client_driver_name_reply_t *reply;
Bool is_ok=FALSE ;
EPHYR_RETURN_VAL_IF_FAIL (a_ddx_driver_major_version
@@ -126,16 +152,28 @@ ephyrDRIGetClientDriverName (int a_screen,
&& a_client_driver_name,
FALSE);
EPHYR_LOG ("enter\n") ;
- is_ok = XF86DRIGetClientDriverName (dpy, DefaultScreen (dpy),
- a_ddx_driver_major_version,
- a_ddx_driver_minor_version,
- a_ddx_driver_patch_version,
- a_client_driver_name) ;
+ cookie = xcb_xf86dri_get_client_driver_name(conn, screen);
+ reply = xcb_xf86dri_get_client_driver_name_reply(conn, cookie, NULL);
+ if (!reply)
+ goto out;
+ *a_ddx_driver_major_version = reply->client_driver_major_version;
+ *a_ddx_driver_minor_version = reply->client_driver_minor_version;
+ *a_ddx_driver_patch_version = reply->client_driver_patch_version;
+ *a_client_driver_name = malloc(reply->client_driver_name_len + 1);
+ if (!*a_client_driver_name)
+ goto out;
+ memcpy(*a_client_driver_name,
+ xcb_xf86dri_get_client_driver_name_client_driver_name(reply),
+ reply->client_driver_name_len);
+ (*a_client_driver_name)[reply->client_driver_name_len] = '\0';
+ is_ok = TRUE;
EPHYR_LOG ("major:%d, minor:%d, patch:%d, name:%s\n",
*a_ddx_driver_major_version,
*a_ddx_driver_minor_version,
*a_ddx_driver_patch_version,
*a_client_driver_name) ;
+out:
+ free(reply);
EPHYR_LOG ("leave:%d\n", is_ok) ;
return is_ok ;
}
@@ -146,18 +184,23 @@ ephyrDRICreateContext (int a_screen,
XID *a_returned_ctxt_id,
drm_context_t *a_hw_ctxt)
{
- Display *dpy = hostx_get_display () ;
+ xcb_connection_t *conn = hostx_get_xcbconn () ;
+ int screen = hostx_get_screen();
Bool is_ok=FALSE ;
- Visual v;
+ xcb_xf86dri_create_context_cookie_t cookie;
+ xcb_xf86dri_create_context_reply_t *reply;
+
+ *a_returned_ctxt_id = xcb_generate_id(conn);
EPHYR_LOG ("enter. screen:%d, visual:%d\n", a_screen, a_visual_id) ;
- memset (&v, 0, sizeof (v)) ;
- v.visualid = a_visual_id ;
- is_ok = XF86DRICreateContext (dpy,
- DefaultScreen (dpy),
- &v,
- a_returned_ctxt_id,
- a_hw_ctxt) ;
+ cookie = xcb_xf86dri_create_context(conn, screen, a_visual_id, *a_returned_ctxt_id);
+ reply = xcb_xf86dri_create_context_reply(conn, cookie, NULL);
+ if (!reply)
+ goto out;
+ *a_hw_ctxt = reply->hw_context;
+ is_ok = TRUE;
+out:
+ free(reply);
EPHYR_LOG ("leave:%d\n", is_ok) ;
return is_ok ;
}
@@ -166,13 +209,13 @@ Bool
ephyrDRIDestroyContext (int a_screen,
int a_context_id)
{
- Display *dpy = hostx_get_display () ;
- Bool is_ok=FALSE ;
+ xcb_connection_t *conn = hostx_get_xcbconn () ;
+ int screen = hostx_get_screen();
EPHYR_LOG ("enter\n") ;
- is_ok = XF86DRIDestroyContext (dpy, DefaultScreen (dpy), a_context_id) ;
- EPHYR_LOG ("leave:%d\n", is_ok) ;
- return is_ok ;
+ xcb_xf86dri_destroy_context(conn, screen, a_context_id);
+ EPHYR_LOG ("leave\n") ;
+ return TRUE;
}
Bool
@@ -181,11 +224,20 @@ ephyrDRICreateDrawable (int a_screen,
drm_drawable_t *a_hw_drawable)
{
Bool is_ok=FALSE;
- Display *dpy=hostx_get_display () ;
+ xcb_connection_t *conn=hostx_get_xcbconn () ;
+ int screen = hostx_get_screen();
+ xcb_xf86dri_create_drawable_cookie_t cookie;
+ xcb_xf86dri_create_drawable_reply_t *reply;
EPHYR_LOG ("enter\n") ;
- is_ok = XF86DRICreateDrawable (dpy, DefaultScreen (dpy),
- a_drawable, a_hw_drawable) ;
+ cookie = xcb_xf86dri_create_drawable(conn, screen, a_drawable);
+ reply = xcb_xf86dri_create_drawable_reply(conn, cookie, NULL);
+ if (!reply)
+ goto out;
+ *a_hw_drawable = reply->hw_drawable_handle;
+ is_ok = TRUE;
+out:
+ free(reply);
EPHYR_LOG ("leave. is_ok:%d\n", is_ok) ;
return is_ok ;
}
@@ -216,7 +268,10 @@ ephyrDRIGetDrawableInfo (int a_screen,
drm_clip_rect_t **a_back_clip_rects)
{
Bool is_ok=FALSE;
- Display *dpy=hostx_get_display () ;
+ xcb_connection_t *conn=hostx_get_xcbconn () ;
+ int screen = hostx_get_screen();
+ xcb_xf86dri_get_drawable_info_cookie_t cookie;
+ xcb_xf86dri_get_drawable_info_reply_t *reply = NULL;
EphyrHostWindowAttributes attrs ;
EPHYR_RETURN_VAL_IF_FAIL (a_x && a_y && a_w && a_h
@@ -224,25 +279,30 @@ ephyrDRIGetDrawableInfo (int a_screen,
FALSE) ;
EPHYR_LOG ("enter\n") ;
+ goto out;
memset (&attrs, 0, sizeof (attrs)) ;
if (!hostx_get_window_attributes (a_drawable, &attrs)) {
EPHYR_LOG_ERROR ("failed to query host window attributes\n") ;
goto out;
}
- if (!XF86DRIGetDrawableInfo (dpy, DefaultScreen (dpy), a_drawable,
- a_index, a_stamp,
- a_x, a_y,
- a_w, a_h,
- a_num_clip_rects, a_clip_rects,
- a_back_x, a_back_y,
- a_num_back_clip_rects,
- a_back_clip_rects)) {
+ cookie = xcb_xf86dri_get_drawable_info(conn, screen, a_drawable);
+ reply = xcb_xf86dri_get_drawable_info_reply(conn, cookie, NULL);
+ if (!reply) {
EPHYR_LOG_ERROR ("XF86DRIGetDrawableInfo ()\n") ;
goto out ;
}
+ *a_index = reply->drawable_table_index;
+ *a_stamp = reply->drawable_table_stamp;
+ *a_x = reply->drawable_origin_X;
+ *a_y = reply->drawable_origin_Y;
+ *a_w = reply->drawable_size_W;
+ *a_h = reply->drawable_size_H;
+ *a_num_clip_rects = reply->num_clip_rects;
+ *a_clip_rects = calloc(*a_num_clip_rects, sizeof(drm_clip_rect_t));
+ memcpy(*a_clip_rects, xcb_xf86dri_get_drawable_info_clip_rects(reply),
+ *a_num_clip_rects * sizeof(drm_clip_rect_t));
EPHYR_LOG ("host x,y,w,h: (%d,%d,%d,%d)\n", *a_x, *a_y, *a_w, *a_h) ;
if (*a_num_clip_rects) {
- free (*a_back_clip_rects) ;
*a_back_clip_rects = calloc (*a_num_clip_rects,
sizeof (drm_clip_rect_t)) ;
memmove (*a_back_clip_rects,
@@ -259,6 +319,7 @@ ephyrDRIGetDrawableInfo (int a_screen,
is_ok = TRUE ;
out:
+ free(reply);
EPHYR_LOG ("leave. index:%d, stamp:%d, x,y:(%d,%d), w,y:(%d,%d)\n",
*a_index, *a_stamp, *a_x, *a_y, *a_w, *a_h) ;
return is_ok ;
@@ -274,13 +335,35 @@ ephyrDRIGetDeviceInfo (int a_screen,
void **a_dev_private)
{
Bool is_ok = FALSE ;
- Display *dpy = hostx_get_display () ;
+ xcb_connection_t *conn = hostx_get_xcbconn () ;
+ int screen = hostx_get_screen();
+ xcb_xf86dri_get_device_info_cookie_t cookie;
+ xcb_xf86dri_get_device_info_reply_t *reply;
- EPHYR_RETURN_VAL_IF_FAIL (dpy, FALSE) ;
+ EPHYR_RETURN_VAL_IF_FAIL (conn, FALSE) ;
EPHYR_LOG ("enter\n") ;
- is_ok = XF86DRIGetDeviceInfo (dpy, DefaultScreen (dpy), a_frame_buffer,
- a_fb_origin, a_fb_size, a_fb_stride,
- a_dev_private_size, a_dev_private) ;
+ cookie = xcb_xf86dri_get_device_info(conn, screen);
+ reply = xcb_xf86dri_get_device_info_reply(conn, cookie, NULL);
+ if (!reply)
+ goto out;
+ *a_frame_buffer = reply->framebuffer_handle_low;
+ if (sizeof(drm_handle_t) == 8) {
+ int shift = 32;
+ *a_frame_buffer |= ((drm_handle_t)reply->framebuffer_handle_high) << shift;
+ }
+ *a_fb_origin = reply->framebuffer_origin_offset;
+ *a_fb_size = reply->framebuffer_size;
+ *a_fb_stride = reply->framebuffer_stride;
+ *a_dev_private_size = reply->device_private_size;
+ *a_dev_private = calloc(reply->device_private_size, 1);
+ if (!*a_dev_private)
+ goto out;
+ memcpy(*a_dev_private,
+ xcb_xf86dri_get_device_info_device_private(reply),
+ reply->device_private_size);
+ is_ok = TRUE;
+out:
+ free(reply);
EPHYR_LOG ("leave:%d\n", is_ok) ;
return is_ok ;
}
--
1.7.1
More information about the xorg-devel
mailing list