xserver: Branch 'master' - 41 commits

Keith Packard keithp at kemper.freedesktop.org
Fri Oct 4 14:07:14 PDT 2013


 configure.ac                     |    6 
 hw/kdrive/ephyr/Makefile.am      |   91 +-
 hw/kdrive/ephyr/XF86dri.c        |  654 --------------------
 hw/kdrive/ephyr/ephyr.c          |  439 ++++++++++---
 hw/kdrive/ephyr/ephyr.h          |   20 
 hw/kdrive/ephyr/ephyrdri.c       |  201 ++++--
 hw/kdrive/ephyr/ephyrdriext.c    |    7 
 hw/kdrive/ephyr/ephyrglxext.c    |   14 
 hw/kdrive/ephyr/ephyrhostglx.c   |  677 ++++++---------------
 hw/kdrive/ephyr/ephyrhostglx.h   |   11 
 hw/kdrive/ephyr/ephyrhostproxy.c |   91 --
 hw/kdrive/ephyr/ephyrhostproxy.h |   51 -
 hw/kdrive/ephyr/ephyrhostvideo.c |  975 ------------------------------
 hw/kdrive/ephyr/ephyrhostvideo.h |  231 -------
 hw/kdrive/ephyr/ephyrinit.c      |   29 
 hw/kdrive/ephyr/ephyrproxyext.c  |  115 ---
 hw/kdrive/ephyr/ephyrproxyext.h  |   33 -
 hw/kdrive/ephyr/ephyrvideo.c     |  746 +++++++++++++----------
 hw/kdrive/ephyr/hostx.c          | 1228 +++++++++++++++------------------------
 hw/kdrive/ephyr/hostx.h          |  104 ---
 hw/kdrive/ephyr/xf86dri.h        |  124 ---
 21 files changed, 1685 insertions(+), 4162 deletions(-)

New commits:
commit f3b529bf25db2700addbafc7aa4fc5b126ba9929
Merge: 4399bd3 abc2bfc
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Oct 4 14:04:48 2013 -0700

    Merge remote-tracking branch 'anholt/ephyr-fixes'

commit abc2bfca16adcd1e5657d4ce54f4e1335d5ed53f
Author: Sebastien Bacher <seb128 at ubuntu.com>
Date:   Fri Aug 23 21:21:44 2013 +0200

    kdrive: initialize GLX for xephyr
    
    Like commit ac1a60e7b6f06fd075cc5bf55d6bc67206a01d29, re-add
    initialization of GLX after it was accidentally dropped from non-Xorg
    servers in 5f5bbbe543f65c48ecbb5cce80116a86ca3fbe86.
    
    Signed-off-by: Sebastien Bacher <seb128 at ubuntu.com>
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=62346
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/hw/kdrive/ephyr/ephyrinit.c b/hw/kdrive/ephyr/ephyrinit.c
index 966e321..cf8bc90 100644
--- a/hw/kdrive/ephyr/ephyrinit.c
+++ b/hw/kdrive/ephyr/ephyrinit.c
@@ -28,6 +28,7 @@
 #endif
 #include "ephyr.h"
 #include "ephyrlog.h"
+#include "glx_extinit.h"
 
 extern Window EphyrPreExistingHostWin;
 extern Bool EphyrWantGrayScale;
@@ -54,9 +55,28 @@ InitCard(char *name)
     KdCardInfoAdd(&ephyrFuncs, 0);
 }
 
+static const ExtensionModule ephyrExtensions[] = {
+#ifdef GLXEXT
+ { GlxExtensionInit, "GLX", &noGlxExtension },
+#endif
+};
+
+static
+void ephyrExtensionInit(void)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(ephyrExtensions); i++)
+ LoadExtension(&ephyrExtensions[i], TRUE);
+}
+
+
 void
 InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
 {
+    if (serverGeneration == 1)
+        ephyrExtensionInit();
+
     KdInitOutput(pScreenInfo, argc, argv);
 }
 
commit aa5534ec6931ffcc81cca76b98785d57de8e0e52
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Aug 23 11:23:00 2013 -0700

    ephyr: Do grab/ungrab for ctrl+shift, not just shift+ctrl.
    
    Given that the window title says "ctrl+shift", having pressing those
    keys in that order not ungrab you is fairly mean.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index 932327d..d8573e0 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -1033,9 +1033,12 @@ ephyrProcessKeyRelease(xcb_generic_event_t *xev)
     if (!keysyms)
         keysyms = xcb_key_symbols_alloc(conn);
 
-    if ((xcb_key_symbols_get_keysym(keysyms, key->detail, 0) == XK_Shift_L
-         || xcb_key_symbols_get_keysym(keysyms, key->detail, 0) == XK_Shift_R)
-        && (key->state & XCB_MOD_MASK_CONTROL)) {
+    if (((xcb_key_symbols_get_keysym(keysyms, key->detail, 0) == XK_Shift_L
+          || xcb_key_symbols_get_keysym(keysyms, key->detail, 0) == XK_Shift_R)
+         && (key->state & XCB_MOD_MASK_CONTROL)) ||
+        ((xcb_key_symbols_get_keysym(keysyms, key->detail, 0) == XK_Control_L
+          || xcb_key_symbols_get_keysym(keysyms, key->detail, 0) == XK_Control_R)
+         && (key->state & XCB_MOD_MASK_SHIFT))) {
         KdScreenInfo *screen = screen_from_window(key->event);
         EphyrScrPriv *scrpriv = screen->driver;
 
commit 5cc15e1c427bacd73db7381df3474a23f7616624
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Aug 23 11:19:17 2013 -0700

    ephyr: Flush the X connection when updating the window title.
    
    Otherwise when you're doing the ctrl-shift mouse grab thing, you
    don't know what state you're in until the next rendering occurs.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index a8a2448..d985571 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -174,6 +174,7 @@ hostx_set_win_title(KdScreenInfo *screen, const char *extra_text)
                               8,
                               strlen(buf),
                               buf);
+        xcb_flush(HostX.conn);
     }
 }
 
commit ba387cf21f7d95987211f75d8024601e7d64e322
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Aug 23 11:17:14 2013 -0700

    ephyr: Use host (HW) cursors by default.
    
    Unless you're working on the sw cursor rendering code, you surely want
    to have real hardware cursors.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/ephyrinit.c b/hw/kdrive/ephyr/ephyrinit.c
index 7812dbe..966e321 100644
--- a/hw/kdrive/ephyr/ephyrinit.c
+++ b/hw/kdrive/ephyr/ephyrinit.c
@@ -114,7 +114,7 @@ ddxUseMsg(void)
 
     ErrorF("\nXephyr Option Usage:\n");
     ErrorF("-parent <XID>        Use existing window as Xephyr root win\n");
-    ErrorF("-host-cursor         Re-use exisiting X host server cursor\n");
+    ErrorF("-sw-cursor           Render cursors in software in Xephyr\n");
     ErrorF("-fullscreen          Attempt to run Xephyr fullscreen\n");
     ErrorF("-grayscale           Simulate 8bit grayscale\n");
     ErrorF("-resizeable          Make Xephyr windows resizeable\n");
@@ -203,8 +203,12 @@ ddxProcessArgument(int argc, char **argv, int i)
         UseMsg();
         exit(1);
     }
+    else if (!strcmp(argv[i], "-sw-cursor")) {
+        hostx_use_sw_cursor();
+        return 1;
+    }
     else if (!strcmp(argv[i], "-host-cursor")) {
-        hostx_use_host_cursor();
+        /* Compatibility with the old command line argument, now the default. */
         return 1;
     }
     else if (!strcmp(argv[i], "-fullscreen")) {
diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index 084bd64..a8a2448 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -64,7 +64,7 @@ struct EphyrHostXVars {
     Window winroot;
     xcb_gcontext_t  gc;
     int depth;
-    Bool use_host_cursor;
+    Bool use_sw_cursor;
     Bool use_fullscreen;
     Bool have_shm;
 
@@ -180,13 +180,13 @@ hostx_set_win_title(KdScreenInfo *screen, const char *extra_text)
 int
 hostx_want_host_cursor(void)
 {
-    return HostX.use_host_cursor;
+    return !HostX.use_sw_cursor;
 }
 
 void
-hostx_use_host_cursor(void)
+hostx_use_sw_cursor(void)
 {
-    HostX.use_host_cursor = TRUE;
+    HostX.use_sw_cursor = TRUE;
 }
 
 int
diff --git a/hw/kdrive/ephyr/hostx.h b/hw/kdrive/ephyr/hostx.h
index 20df7be..e83323a 100644
--- a/hw/kdrive/ephyr/hostx.h
+++ b/hw/kdrive/ephyr/hostx.h
@@ -80,7 +80,7 @@ int
  hostx_want_host_cursor(void);
 
 void
- hostx_use_host_cursor(void);
+ hostx_use_sw_cursor(void);
 
 void
  hostx_use_fullscreen(void);
commit 0f5a2f13dc284dd5f0f28e2c4323b2e08d253a7d
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Aug 23 11:04:22 2013 -0700

    ephyr: Garbage collect some DOA host window clipping code.
    
    Introduced in 79782726617d4b5a4f9b376f21936d035fc870e1 but never used.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index b189ebd..084bd64 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -1092,46 +1092,6 @@ out:
     return is_ok;
 }
 
-int
-hostx_set_window_clipping_rectangles(int a_window,
-                                     EphyrRect * a_rects, int a_num_rects)
-{
-    Bool is_ok = FALSE;
-    int i = 0;
-    xcb_rectangle_t *rects = NULL;
-
-    EPHYR_RETURN_VAL_IF_FAIL(a_rects, FALSE);
-
-    EPHYR_LOG("enter. num rects:%d\n", a_num_rects);
-
-    rects = calloc(a_num_rects, sizeof (xcb_rectangle_t));
-    if (!rects)
-        goto out;
-    for (i = 0; i < a_num_rects; i++) {
-        rects[i].x = a_rects[i].x1;
-        rects[i].y = a_rects[i].y1;
-        rects[i].width = abs(a_rects[i].x2 - a_rects[i].x1);
-        rects[i].height = abs(a_rects[i].y2 - a_rects[i].y1);
-        EPHYR_LOG("clipped to rect[x:%d,y:%d,w:%d,h:%d]\n",
-                  rects[i].x, rects[i].y, rects[i].width, rects[i].height);
-    }
-    xcb_shape_rectangles(HostX.conn,
-                         XCB_SHAPE_SO_SET,
-                         XCB_SHAPE_SK_CLIP,
-                         XCB_CLIP_ORDERING_YX_BANDED,
-                         a_window,
-                         0, 0,
-                         a_num_rects,
-                         rects);
-    is_ok = TRUE;
-
-out:
-    free(rects);
-    rects = NULL;
-    EPHYR_LOG("leave\n");
-    return is_ok;
-}
-
 #ifdef XF86DRI
 typedef struct {
     int is_valid;
diff --git a/hw/kdrive/ephyr/hostx.h b/hw/kdrive/ephyr/hostx.h
index 0323b33..20df7be 100644
--- a/hw/kdrive/ephyr/hostx.h
+++ b/hw/kdrive/ephyr/hostx.h
@@ -172,9 +172,6 @@ int hostx_set_window_geometry(int a_win, EphyrBox * a_geo);
 int hostx_set_window_bounding_rectangles(int a_window,
                                          EphyrRect * a_rects, int a_num_rects);
 
-int hostx_set_window_clipping_rectangles(int a_window,
-                                         EphyrRect * a_rects, int a_num_rects);
-
 int host_has_extension(xcb_extension_t *extension);
 
 #ifdef XF86DRI
commit 090de17d361dc9828203a2562565d6499998db46
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Aug 23 10:56:22 2013 -0700

    ephyr: Garbage collect some dead XV clipping code.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/ephyrvideo.c b/hw/kdrive/ephyr/ephyrvideo.c
index f4fcf72..4a05721 100644
--- a/hw/kdrive/ephyr/ephyrvideo.c
+++ b/hw/kdrive/ephyr/ephyrvideo.c
@@ -60,8 +60,6 @@ struct _EphyrPortPriv {
 };
 typedef struct _EphyrPortPriv EphyrPortPriv;
 
-static Bool DoSimpleClip(BoxPtr a_dst_drw, BoxPtr a_clipper, BoxPtr a_result);
-
 static Bool ephyrLocalAtomToHost(int a_local_atom, int *a_host_atom);
 
 static EphyrXVPriv *ephyrXVPrivNew(void);
@@ -178,49 +176,6 @@ adaptor_has_flags(const xcb_xv_adaptor_info_t *adaptor, uint32_t flags)
 }
 
 static Bool
-DoSimpleClip(BoxPtr a_dst_box, BoxPtr a_clipper, BoxPtr a_result)
-{
-    BoxRec dstClippedBox;
-
-    EPHYR_RETURN_VAL_IF_FAIL(a_dst_box && a_clipper && a_result, FALSE);
-
-    /*
-     * setup the clipbox inside the destination.
-     */
-    dstClippedBox.x1 = a_dst_box->x1;
-    dstClippedBox.x2 = a_dst_box->x2;
-    dstClippedBox.y1 = a_dst_box->y1;
-    dstClippedBox.y2 = a_dst_box->y2;
-
-    /*
-     * if the cliper leftmost edge is inside
-     * the destination area then the leftmost edge of the resulting
-     * clipped box is the leftmost edge of the cliper.
-     */
-    if (a_clipper->x1 > dstClippedBox.x1)
-        dstClippedBox.x1 = a_clipper->x1;
-
-    /*
-     * if the cliper top edge is inside the destination area
-     * then the bottom horizontal edge of the resulting clipped box
-     * is the bottom edge of the cliper
-     */
-    if (a_clipper->y1 > dstClippedBox.y1)
-        dstClippedBox.y1 = a_clipper->y1;
-
-    /*ditto for right edge */
-    if (a_clipper->x2 < dstClippedBox.x2)
-        dstClippedBox.x2 = a_clipper->x2;
-
-    /*ditto for bottom edge */
-    if (a_clipper->y2 < dstClippedBox.y2)
-        dstClippedBox.y2 = a_clipper->y2;
-
-    memcpy(a_result, &dstClippedBox, sizeof(dstClippedBox));
-    return TRUE;
-}
-
-static Bool
 ephyrLocalAtomToHost(int a_local_atom, int *a_host_atom)
 {
     xcb_connection_t *conn = hostx_get_xcbconn();
@@ -1158,25 +1113,12 @@ ephyrPutVideo(KdScreenInfo * a_info,
     xcb_connection_t *conn = hostx_get_xcbconn();
     xcb_gcontext_t gc;
     EphyrPortPriv *port_priv = a_port_priv;
-    BoxRec clipped_area, dst_box;
-    int result = BadImplementation;
 
     EPHYR_RETURN_VAL_IF_FAIL(a_info->pScreen, BadValue);
     EPHYR_RETURN_VAL_IF_FAIL(a_drawable && port_priv, BadValue);
 
     EPHYR_LOG("enter\n");
 
-    dst_box.x1 = a_drw_x;
-    dst_box.x2 = a_drw_x + a_drw_w;
-    dst_box.y1 = a_drw_y;
-    dst_box.y2 = a_drw_y + a_drw_h;
-
-    if (!DoSimpleClip(&dst_box,
-                      RegionExtents(a_clipping_region), &clipped_area)) {
-        EPHYR_LOG_ERROR("failed to simple clip\n");
-        goto out;
-    }
-
     gc = xcb_generate_id(conn);
     xcb_create_gc(conn, gc, scrpriv->win, 0, NULL);
     xcb_xv_put_video(conn, port_priv->port_number,
@@ -1185,11 +1127,8 @@ ephyrPutVideo(KdScreenInfo * a_info,
                      a_drw_x, a_drw_y, a_drw_w, a_drw_h);
     xcb_free_gc(conn, gc);
 
-    result = Success;
-
- out:
     EPHYR_LOG("leave\n");
-    return result;
+    return Success;
 }
 
 static int
@@ -1205,25 +1144,12 @@ ephyrGetVideo(KdScreenInfo * a_info,
     xcb_connection_t *conn = hostx_get_xcbconn();
     xcb_gcontext_t gc;
     EphyrPortPriv *port_priv = a_port_priv;
-    BoxRec clipped_area, dst_box;
-    int result = BadImplementation;
 
     EPHYR_RETURN_VAL_IF_FAIL(a_info && a_info->pScreen, BadValue);
     EPHYR_RETURN_VAL_IF_FAIL(a_drawable && port_priv, BadValue);
 
     EPHYR_LOG("enter\n");
 
-    dst_box.x1 = a_drw_x;
-    dst_box.x2 = a_drw_x + a_drw_w;
-    dst_box.y1 = a_drw_y;
-    dst_box.y2 = a_drw_y + a_drw_h;
-
-    if (!DoSimpleClip(&dst_box,
-                      RegionExtents(a_clipping_region), &clipped_area)) {
-        EPHYR_LOG_ERROR("failed to simple clip\n");
-        goto out;
-    }
-
     gc = xcb_generate_id(conn);
     xcb_create_gc(conn, gc, scrpriv->win, 0, NULL);
     xcb_xv_get_video(conn, port_priv->port_number,
@@ -1233,11 +1159,8 @@ ephyrGetVideo(KdScreenInfo * a_info,
 
     xcb_free_gc(conn, gc);
 
-    result = Success;
-
- out:
     EPHYR_LOG("leave\n");
-    return result;
+    return Success;
 }
 
 static int
@@ -1253,25 +1176,12 @@ ephyrPutStill(KdScreenInfo * a_info,
     xcb_connection_t *conn = hostx_get_xcbconn();
     xcb_gcontext_t gc;
     EphyrPortPriv *port_priv = a_port_priv;
-    BoxRec clipped_area, dst_box;
-    int result = BadImplementation;
 
     EPHYR_RETURN_VAL_IF_FAIL(a_info && a_info->pScreen, BadValue);
     EPHYR_RETURN_VAL_IF_FAIL(a_drawable && port_priv, BadValue);
 
     EPHYR_LOG("enter\n");
 
-    dst_box.x1 = a_drw_x;
-    dst_box.x2 = a_drw_x + a_drw_w;
-    dst_box.y1 = a_drw_y;
-    dst_box.y2 = a_drw_y + a_drw_h;
-
-    if (!DoSimpleClip(&dst_box,
-                      RegionExtents(a_clipping_region), &clipped_area)) {
-        EPHYR_LOG_ERROR("failed to simple clip\n");
-        goto out;
-    }
-
     gc = xcb_generate_id(conn);
     xcb_create_gc(conn, gc, scrpriv->win, 0, NULL);
     xcb_xv_put_still(conn, port_priv->port_number,
@@ -1280,11 +1190,8 @@ ephyrPutStill(KdScreenInfo * a_info,
                      a_drw_x, a_drw_y, a_drw_w, a_drw_h);
     xcb_free_gc(conn, gc);
 
-    result = Success;
-
- out:
     EPHYR_LOG("leave\n");
-    return result;
+    return Success;
 }
 
 static int
@@ -1300,25 +1207,12 @@ ephyrGetStill(KdScreenInfo * a_info,
     xcb_connection_t *conn = hostx_get_xcbconn();
     xcb_gcontext_t gc;
     EphyrPortPriv *port_priv = a_port_priv;
-    BoxRec clipped_area, dst_box;
-    int result = BadImplementation;
 
     EPHYR_RETURN_VAL_IF_FAIL(a_info && a_info->pScreen, BadValue);
     EPHYR_RETURN_VAL_IF_FAIL(a_drawable && port_priv, BadValue);
 
     EPHYR_LOG("enter\n");
 
-    dst_box.x1 = a_drw_x;
-    dst_box.x2 = a_drw_x + a_drw_w;
-    dst_box.y1 = a_drw_y;
-    dst_box.y2 = a_drw_y + a_drw_h;
-
-    if (!DoSimpleClip(&dst_box,
-                      RegionExtents(a_clipping_region), &clipped_area)) {
-        EPHYR_LOG_ERROR("failed to simple clip\n");
-        goto out;
-    }
-
     gc = xcb_generate_id(conn);
     xcb_create_gc(conn, gc, scrpriv->win, 0, NULL);
     xcb_xv_get_still(conn, port_priv->port_number,
@@ -1327,11 +1221,8 @@ ephyrGetStill(KdScreenInfo * a_info,
                      a_drw_x, a_drw_y, a_drw_w, a_drw_h);
     xcb_free_gc(conn, gc);
 
-    result = Success;
-
- out:
     EPHYR_LOG("leave\n");
-    return result;
+    return Success;
 }
 
 static int
commit 347d0fa6961c2b3dc4efd4e7cca8ef98cd3ea06e
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Aug 23 10:44:23 2013 -0700

    ephyr: Remove the helper libs for each of the optional components.
    
    Note that EXTRA_DIST was always unnecessary, because automake notices
    conditional compile of source files and includes them.
    
    Copyright header is added because git noted that this was a 61%
    rewrite.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/Makefile.am b/hw/kdrive/ephyr/Makefile.am
index 805b3b7..6b790fd 100644
--- a/hw/kdrive/ephyr/Makefile.am
+++ b/hw/kdrive/ephyr/Makefile.am
@@ -1,3 +1,24 @@
+# Copyright © 2013 Intel Corporation
+#
+# 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.
+
 SUBDIRS = man
 
 AM_CPPFLAGS = 			\
@@ -9,25 +30,11 @@ AM_CPPFLAGS = 			\
 	-I$(top_srcdir)/exa
 
 if XV
-LIBXEPHYR_HOSTXV=libxephyr-hostxv.la
+XV_SRCS = ephyrvideo.c
 endif
 
 if DRI
-LIBXEPHYR_HOSTDRI=libxephyr-hostdri.la
-endif
-
-noinst_LTLIBRARIES = libxephyr-hostx.la $(LIBXEPHYR_HOSTXV) $(LIBXEPHYR_HOSTDRI) libxephyr.la
-
-bin_PROGRAMS = Xephyr
-
-HOSTX_SRCS =			\
-	hostx.c			\
-	hostx.h
-
-HOSTVIDEO_SRCS =		\
-	ephyrvideo.c
-
-HOSTDRI_SRCS =			\
+DRI_SRCS =			\
 	ephyrdriext.c		\
 	ephyrdriext.h		\
 	ephyrdri.c		\
@@ -35,51 +42,33 @@ HOSTDRI_SRCS =			\
 	ephyrglxext.c		\
 	ephyrglxext.h		\
 	ephyrhostglx.c		\
-	ephyrhostglx.h
-
-XEPHYR_SRCS =			\
-	ephyr.c			\
-	ephyr.h			\
-	ephyrlog.h		\
-	ephyr_draw.c		\
-	os.c
-
-libxephyr_hostx_la_SOURCES = $(HOSTX_SRCS)
-
-if XV
-libxephyr_hostxv_la_SOURCES = $(HOSTVIDEO_SRCS)
-endif
-
-if DRI
-libxephyr_hostdri_la_SOURCES = $(HOSTDRI_SRCS)
+	ephyrhostglx.h		\
+	$()
 endif
 
-libxephyr_la_SOURCES = $(XEPHYR_SRCS)
+bin_PROGRAMS = Xephyr
 
 Xephyr_SOURCES = \
-	ephyrinit.c
+	ephyr.c \
+	ephyr.h \
+	ephyrlog.h \
+	ephyr_draw.c \
+	os.c \
+	ephyrinit.c \
+	hostx.c \
+	hostx.h \
+	$(XV_SRCS) \
+	$(DRI_SRCS) \
+	$()
 
 Xephyr_LDADD = 						\
-	libxephyr.la					\
-	libxephyr-hostx.la				\
-	$(LIBXEPHYR_HOSTXV)				\
-	$(LIBXEPHYR_HOSTDRI)				\
 	$(top_builddir)/exa/libexa.la			\
 	@KDRIVE_LIBS@					\
 	@XEPHYR_LIBS@
 
-Xephyr_DEPENDENCIES =	\
-	libxephyr.la					\
-	libxephyr-hostx.la				\
-	$(LIBXEPHYR_HOSTXV)				\
-	$(LIBXEPHYR_HOSTDRI)				\
-	@KDRIVE_LOCAL_LIBS@
+Xephyr_DEPENDENCIES = @KDRIVE_LOCAL_LIBS@
 
 Xephyr_LDFLAGS = $(LD_EXPORT_SYMBOLS_FLAG)
 
 relink:
 	$(AM_V_at)rm -f $(bin_PROGRAMS) && $(MAKE) $(bin_PROGRAMS)
-
-EXTRA_DIST = \
-	$(HOSTVIDEO_SRCS) \
-	$(HOSTDRI_SRCS)
commit 74dff87790dbb3dcb23634f1e8cd54018e5ddc9d
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Aug 23 10:40:52 2013 -0700

    ephyr: Remove the remaining bits of host/server XV split.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/Makefile.am b/hw/kdrive/ephyr/Makefile.am
index 7648e14..805b3b7 100644
--- a/hw/kdrive/ephyr/Makefile.am
+++ b/hw/kdrive/ephyr/Makefile.am
@@ -25,9 +25,7 @@ HOSTX_SRCS =			\
 	hostx.h
 
 HOSTVIDEO_SRCS =		\
-	ephyrvideo.c		\
-	ephyrhostvideo.c	\
-	ephyrhostvideo.h
+	ephyrvideo.c
 
 HOSTDRI_SRCS =			\
 	ephyrdriext.c		\
diff --git a/hw/kdrive/ephyr/ephyrhostvideo.c b/hw/kdrive/ephyr/ephyrhostvideo.c
deleted file mode 100644
index a26c31c..0000000
--- a/hw/kdrive/ephyr/ephyrhostvideo.c
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Xephyr - A kdrive X server thats runs in a host X window.
- *          Authored by Matthew Allum <mallum at openedhand.com>
- * 
- * Copyright © 2007 OpenedHand Ltd 
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of OpenedHand Ltd not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission. OpenedHand Ltd makes no
- * representations about the suitability of this software for any purpose.  It
- * is provided "as is" without express or implied warranty.
- *
- * OpenedHand Ltd DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL OpenedHand Ltd BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- *
- * Authors:
- *    Dodji Seketeli <dodji at openedhand.com>
- */
-#ifdef HAVE_CONFIG_H
-#include <kdrive-config.h>
-#endif
-#include <xcb/xv.h>
-#include <xcb/xcb_aux.h>
-#define _HAVE_XALLOC_DECLS
-
-#include "hostx.h"
-#include "ephyrhostvideo.h"
-#include "ephyrlog.h"
-
-#ifndef TRUE
-#define TRUE 1
-#endif /*TRUE*/
-#ifndef FALSE
-#define FALSE 0
-#endif /*FALSE*/
-
-Bool
-ephyrHostXVQueryBestSize(int a_port_id,
-                         Bool a_motion,
-                         unsigned int a_frame_w,
-                         unsigned int a_frame_h,
-                         unsigned int a_drw_w,
-                         unsigned int a_drw_h,
-                         unsigned int *a_actual_w, unsigned int *a_actual_h)
-{
-    Bool is_ok = FALSE;
-    xcb_xv_query_best_size_cookie_t cookie;
-    xcb_xv_query_best_size_reply_t *reply;
-
-    EPHYR_RETURN_VAL_IF_FAIL(a_actual_w && a_actual_h, FALSE);
-
-    EPHYR_LOG("enter: frame (%dx%d), drw (%dx%d)\n",
-              a_frame_w, a_frame_h, a_drw_w, a_drw_h);
-
-    cookie = xcb_xv_query_best_size(hostx_get_xcbconn(),
-                                    a_port_id,
-                                    a_frame_w, a_frame_h,
-                                    a_drw_w, a_drw_h,
-                                    a_motion);
-    reply = xcb_xv_query_best_size_reply(hostx_get_xcbconn(), cookie, NULL);
-    if (!reply) {
-        EPHYR_LOG_ERROR ("XvQueryBestSize() failed\n");
-        goto out;
-    }
-    *a_actual_w = reply->actual_width;
-    *a_actual_h = reply->actual_height;
-    free(reply);
-
-    EPHYR_LOG("actual (%dx%d)\n", *a_actual_w, *a_actual_h);
-    is_ok = TRUE;
-
-out:
-    free(reply);
-    EPHYR_LOG("leave\n");
-    return is_ok;
-}
-
-Bool
-ephyrHostGetAtom(const char *a_name, Bool a_create_if_not_exists, int *a_atom)
-{
-    xcb_connection_t *conn = hostx_get_xcbconn();
-    xcb_intern_atom_cookie_t cookie;
-    xcb_intern_atom_reply_t *reply;
-
-    EPHYR_RETURN_VAL_IF_FAIL(a_atom, FALSE);
-
-    cookie = xcb_intern_atom(conn,
-                             a_create_if_not_exists,
-                             strlen(a_name),
-                             a_name);
-    reply = xcb_intern_atom_reply(conn, cookie, NULL);
-    if (!reply || reply->atom == None) {
-        free(reply);
-        return FALSE;
-    }
-    *a_atom = reply->atom;
-    free(reply);
-    return TRUE;
-}
-
-char *
-ephyrHostGetAtomName(int a_atom)
-{
-    xcb_connection_t *conn = hostx_get_xcbconn();
-    xcb_get_atom_name_cookie_t cookie;
-    xcb_get_atom_name_reply_t *reply;
-    char *ret;
-
-    cookie = xcb_get_atom_name(conn, a_atom);
-    reply = xcb_get_atom_name_reply(conn, cookie, NULL);
-    if (!reply)
-        return NULL;
-    ret = malloc(xcb_get_atom_name_name_length(reply) + 1);
-    if (ret) {
-        memcpy(ret, xcb_get_atom_name_name(reply),
-               xcb_get_atom_name_name_length(reply));
-        ret[xcb_get_atom_name_name_length(reply)] = '\0';
-    }
-    free(reply);
-    return ret;
-}
diff --git a/hw/kdrive/ephyr/ephyrhostvideo.h b/hw/kdrive/ephyr/ephyrhostvideo.h
deleted file mode 100644
index 9c2cd5a..0000000
--- a/hw/kdrive/ephyr/ephyrhostvideo.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Xephyr - A kdrive X server thats runs in a host X window.
- *          Authored by Matthew Allum <mallum at openedhand.com>
- * 
- * Copyright © 2007 OpenedHand Ltd 
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of OpenedHand Ltd not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission. OpenedHand Ltd makes no
- * representations about the suitability of this software for any purpose.  It
- * is provided "as is" without express or implied warranty.
- *
- * OpenedHand Ltd DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL OpenedHand Ltd BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- *
- * Authors:
- *    Dodji Seketeli <dodji at openedhand.com>
- */
-#ifndef __EPHYRHOSTVIDEO_H__
-#define __EPHYRHOSTVIDEO_H__
-
-#include <xcb/xv.h>
-#include <X11/Xdefs.h>
-
-/*
- *size query
- */
-Bool ephyrHostXVQueryBestSize(int a_port_id,
-                              Bool a_motion,
-                              unsigned int a_frame_w,
-                              unsigned int a_frame_h,
-                              unsigned int a_drw_w,
-                              unsigned int a_drw_h,
-                              unsigned int *a_actual_w,
-                              unsigned int *a_actual_h);
-
-/*
- * atom
- */
-Bool ephyrHostGetAtom(const char *a_name,
-                      Bool a_create_if_not_exists, int *a_atom);
-char *ephyrHostGetAtomName(int a_atom);
-
-#endif /*__EPHYRHOSTVIDEO_H__*/
diff --git a/hw/kdrive/ephyr/ephyrvideo.c b/hw/kdrive/ephyr/ephyrvideo.c
index dde58b4..f4fcf72 100644
--- a/hw/kdrive/ephyr/ephyrvideo.c
+++ b/hw/kdrive/ephyr/ephyrvideo.c
@@ -33,12 +33,12 @@
 #include <X11/extensions/Xv.h>
 #include <xcb/xcb.h>
 #include <xcb/xcb_aux.h>
+#include <xcb/xv.h>
 #include "ephyrlog.h"
 #include "kdrive.h"
 #include "kxv.h"
 #include "ephyr.h"
 #include "hostx.h"
-#include "ephyrhostvideo.h"
 
 struct _EphyrXVPriv {
     xcb_xv_query_adaptors_reply_t *host_adaptors;
@@ -223,8 +223,10 @@ DoSimpleClip(BoxPtr a_dst_box, BoxPtr a_clipper, BoxPtr a_result)
 static Bool
 ephyrLocalAtomToHost(int a_local_atom, int *a_host_atom)
 {
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    xcb_intern_atom_cookie_t cookie;
+    xcb_intern_atom_reply_t *reply;
     const char *atom_name = NULL;
-    int host_atom = None;
 
     EPHYR_RETURN_VAL_IF_FAIL(a_host_atom, FALSE);
 
@@ -236,11 +238,16 @@ ephyrLocalAtomToHost(int a_local_atom, int *a_host_atom)
     if (!atom_name)
         return FALSE;
 
-    if (!ephyrHostGetAtom(atom_name, FALSE, &host_atom) || host_atom == None) {
+    cookie = xcb_intern_atom(conn, FALSE, strlen(atom_name), atom_name);
+    reply = xcb_intern_atom_reply(conn, cookie, NULL);
+    if (!reply || reply->atom == None) {
         EPHYR_LOG_ERROR("no atom for string %s defined in host X\n", atom_name);
         return FALSE;
     }
-    *a_host_atom = host_atom;
+
+    *a_host_atom = reply->atom;
+    free(reply);
+
     return TRUE;
 }
 
@@ -902,20 +909,29 @@ ephyrQueryBestSize(KdScreenInfo * a_info,
                    unsigned int *a_prefered_w,
                    unsigned int *a_prefered_h, pointer a_port_priv)
 {
-    int res = 0;
+    xcb_connection_t *conn = hostx_get_xcbconn();
     EphyrPortPriv *port_priv = a_port_priv;
-
-    EPHYR_RETURN_IF_FAIL(port_priv);
-
-    EPHYR_LOG("enter\n");
-    res = ephyrHostXVQueryBestSize(port_priv->port_number,
-                                   a_motion,
-                                   a_src_w, a_src_h,
-                                   a_drw_w, a_drw_h,
-                                   a_prefered_w, a_prefered_h);
-    if (!res) {
-        EPHYR_LOG_ERROR("Failed to query best size\n");
+    xcb_xv_query_best_size_cookie_t cookie =
+        xcb_xv_query_best_size(conn,
+                               port_priv->port_number,
+                               a_src_w, a_src_h,
+                               a_drw_w, a_drw_h,
+                               a_motion);
+    xcb_xv_query_best_size_reply_t *reply =
+        xcb_xv_query_best_size_reply(conn, cookie, NULL);
+
+    EPHYR_LOG("enter: frame (%dx%d), drw (%dx%d)\n",
+              a_src_w, a_src_h, a_drw_w, a_drw_h);
+
+    if (!reply) {
+        EPHYR_LOG_ERROR ("XvQueryBestSize() failed\n");
+        return;
     }
+    *a_prefered_w = reply->actual_width;
+    *a_prefered_h = reply->actual_height;
+    EPHYR_LOG("actual (%dx%d)\n", *a_prefered_w, *a_prefered_h);
+    free(reply);
+
     EPHYR_LOG("leave\n");
 }
 
commit 2f994dfe9d1add9ea8cb9c88ddb0d15843854788
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Aug 23 10:14:36 2013 -0700

    ephyr: Remove the host/server split of the actual XV video operations.
    
    I suspect there's more cleanup possible in ephyrHostXVPutImage() by
    sticking a bunch of the args in the port priv earlier.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/ephyrhostvideo.c b/hw/kdrive/ephyr/ephyrhostvideo.c
index 3735f72..a26c31c 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.c
+++ b/hw/kdrive/ephyr/ephyrhostvideo.c
@@ -128,192 +128,3 @@ ephyrHostGetAtomName(int a_atom)
     free(reply);
     return ret;
 }
-
-Bool
-ephyrHostXVPutImage(int a_screen_num,
-                    int a_port_id,
-                    int a_image_id,
-                    int a_drw_x,
-                    int a_drw_y,
-                    int a_drw_w,
-                    int a_drw_h,
-                    int a_src_x,
-                    int a_src_y,
-                    int a_src_w,
-                    int a_src_h,
-                    int a_image_width,
-                    int a_image_height,
-                    unsigned char *a_buf,
-                    EphyrHostBox * a_clip_rects, int a_clip_rect_nums)
-{
-    Bool is_ok = TRUE;
-    xcb_connection_t *conn = hostx_get_xcbconn ();
-    xcb_gcontext_t gc;
-    xcb_rectangle_t *rects = NULL;
-    int data_len, width, height;
-    xcb_xv_query_image_attributes_cookie_t image_attr_cookie;
-    xcb_xv_query_image_attributes_reply_t *image_attr_reply;
-
-    EPHYR_RETURN_VAL_IF_FAIL(a_buf, FALSE);
-
-    EPHYR_LOG("enter, num_clip_rects: %d\n", a_clip_rect_nums);
-
-    gc = xcb_generate_id(conn);
-    xcb_create_gc(conn, gc, hostx_get_window(a_screen_num), 0, NULL);
-
-    image_attr_cookie = xcb_xv_query_image_attributes(conn,
-                                                      a_port_id,
-                                                      a_image_id,
-                                                      a_image_width,
-                                                      a_image_height);
-    image_attr_reply = xcb_xv_query_image_attributes_reply(conn,
-                                                           image_attr_cookie,
-                                                           NULL);
-    if (!image_attr_reply)
-        goto out;
-    data_len = image_attr_reply->data_size;
-    width = image_attr_reply->width;
-    height = image_attr_reply->height;
-    free(image_attr_reply);
-
-    if (a_clip_rect_nums) {
-        int i = 0;
-        rects = calloc(a_clip_rect_nums, sizeof(xcb_rectangle_t));
-        for (i=0; i < a_clip_rect_nums; i++) {
-            rects[i].x = a_clip_rects[i].x1;
-            rects[i].y = a_clip_rects[i].y1;
-            rects[i].width = a_clip_rects[i].x2 - a_clip_rects[i].x1;
-            rects[i].height = a_clip_rects[i].y2 - a_clip_rects[i].y1;
-            EPHYR_LOG("(x,y,w,h): (%d,%d,%d,%d)\n",
-                      rects[i].x, rects[i].y, rects[i].width, rects[i].height);
-        }
-        xcb_set_clip_rectangles(conn,
-                                XCB_CLIP_ORDERING_YX_BANDED,
-                                gc,
-                                0,
-                                0,
-                                a_clip_rect_nums,
-                                rects);
-	free(rects);
-    }
-    xcb_xv_put_image(conn,
-                     a_port_id,
-                     hostx_get_window (a_screen_num),
-                     gc,
-                     a_image_id,
-                     a_src_x, a_src_y, a_src_w, a_src_h,
-                     a_drw_x, a_drw_y, a_drw_w, a_drw_h,
-                     width, height,
-                     data_len, a_buf);
-    is_ok = TRUE;
-
-out:
-    xcb_free_gc(conn, gc);
-    EPHYR_LOG("leave\n");
-    return is_ok;
-}
-
-Bool
-ephyrHostXVPutVideo(int a_screen_num, int a_port_id,
-                    int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h,
-                    int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h)
-{
-    Bool is_ok = FALSE;
-    xcb_gcontext_t gc;
-    xcb_connection_t *conn = hostx_get_xcbconn();
-
-    EPHYR_RETURN_VAL_IF_FAIL(conn, FALSE);
-
-    gc = xcb_generate_id(conn);
-    xcb_create_gc(conn, gc, hostx_get_window (a_screen_num), 0, NULL);
-    xcb_xv_put_video(conn,
-                     a_port_id,
-                     hostx_get_window (a_screen_num), gc,
-                     a_vid_x, a_vid_y, a_vid_w, a_vid_h,
-                     a_drw_x, a_drw_y, a_drw_w, a_drw_h);
-    is_ok = TRUE;
-
-    xcb_free_gc(conn, gc);
-
-    return is_ok;
-}
-
-Bool
-ephyrHostXVGetVideo(int a_screen_num, int a_port_id,
-                    int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h,
-                    int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h)
-{
-    xcb_gcontext_t gc;
-    xcb_connection_t *conn = hostx_get_xcbconn();
-
-    EPHYR_RETURN_VAL_IF_FAIL(conn, FALSE);
-
-    gc = xcb_generate_id(conn);
-    xcb_create_gc(conn,
-                  gc,
-                  hostx_get_window (a_screen_num),
-                  0, NULL);
-    xcb_xv_get_video(conn,
-                     a_port_id,
-                     hostx_get_window (a_screen_num),
-                     gc,
-                     a_vid_x, a_vid_y, a_vid_w, a_vid_h,
-                     a_drw_x, a_drw_y, a_drw_w, a_drw_h);
-
-    xcb_free_gc(conn, gc);
-
-    return TRUE;
-}
-
-Bool
-ephyrHostXVPutStill(int a_screen_num, int a_port_id,
-                    int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h,
-                    int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h)
-{
-    xcb_connection_t *conn = hostx_get_xcbconn();
-    xcb_gcontext_t gc;
-
-    EPHYR_RETURN_VAL_IF_FAIL(conn, FALSE);
-
-    gc = xcb_generate_id(conn);
-    xcb_create_gc(conn,
-                  gc,
-                  hostx_get_window (a_screen_num),
-                  0, NULL);
-    xcb_xv_put_still(conn,
-                     a_port_id,
-                     hostx_get_window (a_screen_num),
-                     gc,
-                     a_vid_x, a_vid_y, a_vid_w, a_vid_h,
-                     a_drw_x, a_drw_y, a_drw_w, a_drw_h);
-
-    xcb_free_gc(conn, gc);
-
-    return TRUE;
-}
-
-Bool
-ephyrHostXVGetStill(int a_screen_num, int a_port_id,
-                    int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h,
-                    int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h)
-{
-    xcb_gcontext_t gc;
-    xcb_connection_t *conn = hostx_get_xcbconn();
-
-    EPHYR_RETURN_VAL_IF_FAIL(conn, FALSE);
-
-    gc = xcb_generate_id(conn);
-    xcb_create_gc(conn,
-                  gc,
-                  hostx_get_window (a_screen_num),
-                  0, NULL);
-    xcb_xv_get_still(conn,
-                     a_port_id,
-                     hostx_get_window (a_screen_num),
-                     gc,
-                     a_vid_x, a_vid_y, a_vid_w, a_vid_h,
-                     a_drw_x, a_drw_y, a_drw_w, a_drw_h);
-    xcb_free_gc(conn, gc);
-
-    return TRUE;
-}
diff --git a/hw/kdrive/ephyr/ephyrhostvideo.h b/hw/kdrive/ephyr/ephyrhostvideo.h
index 080caa8..9c2cd5a 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.h
+++ b/hw/kdrive/ephyr/ephyrhostvideo.h
@@ -31,10 +31,6 @@
 #include <xcb/xv.h>
 #include <X11/Xdefs.h>
 
-typedef struct {
-    unsigned short x1, y1, x2, y2;
-} EphyrHostBox;
-
 /*
  *size query
  */
@@ -54,47 +50,4 @@ Bool ephyrHostGetAtom(const char *a_name,
                       Bool a_create_if_not_exists, int *a_atom);
 char *ephyrHostGetAtomName(int a_atom);
 
-/*
- *PutImage
- * (ignore clipping for now)
- */
-Bool ephyrHostXVPutImage(int a_screen_num,
-                         int a_port_id,
-                         int a_image_id,
-                         int a_drw_x,
-                         int a_drw_y,
-                         int a_drw_w,
-                         int a_drw_h,
-                         int a_src_x,
-                         int a_src_y,
-                         int a_src_w,
-                         int a_src_h,
-                         int a_image_width,
-                         int a_image_height,
-                         unsigned char *a_buf,
-                         EphyrHostBox * a_clip_rects, int a_clip_rect_nums);
-
-/*
- * Putvideo/PutStill/GetVideo
- */
-Bool ephyrHostXVPutVideo(int a_screen_num,
-                         int a_port_id,
-                         int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h,
-                         int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h);
-
-Bool ephyrHostXVGetVideo(int a_screen_num,
-                         int a_port_id,
-                         int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h,
-                         int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h);
-
-Bool ephyrHostXVPutStill(int a_screen_num,
-                         int a_port_id,
-                         int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h,
-                         int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h);
-
-Bool ephyrHostXVGetStill(int a_screen_num,
-                         int a_port_id,
-                         int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h,
-                         int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h);
-
 #endif /*__EPHYRHOSTVIDEO_H__*/
diff --git a/hw/kdrive/ephyr/ephyrvideo.c b/hw/kdrive/ephyr/ephyrvideo.c
index 46a0ca3..dde58b4 100644
--- a/hw/kdrive/ephyr/ephyrvideo.c
+++ b/hw/kdrive/ephyr/ephyrvideo.c
@@ -919,6 +919,93 @@ ephyrQueryBestSize(KdScreenInfo * a_info,
     EPHYR_LOG("leave\n");
 }
 
+
+static Bool
+ephyrHostXVPutImage(KdScreenInfo * a_info,
+                    EphyrPortPriv *port_priv,
+                    int a_image_id,
+                    int a_drw_x,
+                    int a_drw_y,
+                    int a_drw_w,
+                    int a_drw_h,
+                    int a_src_x,
+                    int a_src_y,
+                    int a_src_w,
+                    int a_src_h,
+                    int a_image_width,
+                    int a_image_height,
+                    unsigned char *a_buf,
+                    BoxPtr a_clip_rects, int a_clip_rect_nums)
+{
+    EphyrScrPriv *scrpriv = a_info->driver;
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    xcb_gcontext_t gc;
+    Bool is_ok = TRUE;
+    xcb_rectangle_t *rects = NULL;
+    int data_len, width, height;
+    xcb_xv_query_image_attributes_cookie_t image_attr_cookie;
+    xcb_xv_query_image_attributes_reply_t *image_attr_reply;
+
+    EPHYR_RETURN_VAL_IF_FAIL(a_buf, FALSE);
+
+    EPHYR_LOG("enter, num_clip_rects: %d\n", a_clip_rect_nums);
+
+    image_attr_cookie = xcb_xv_query_image_attributes(conn,
+                                                      port_priv->port_number,
+                                                      a_image_id,
+                                                      a_image_width,
+                                                      a_image_height);
+    image_attr_reply = xcb_xv_query_image_attributes_reply(conn,
+                                                           image_attr_cookie,
+                                                           NULL);
+    if (!image_attr_reply)
+        goto out;
+    data_len = image_attr_reply->data_size;
+    width = image_attr_reply->width;
+    height = image_attr_reply->height;
+    free(image_attr_reply);
+
+    gc = xcb_generate_id(conn);
+    xcb_create_gc(conn, gc, scrpriv->win, 0, NULL);
+
+    if (a_clip_rect_nums) {
+        int i = 0;
+        rects = calloc(a_clip_rect_nums, sizeof(xcb_rectangle_t));
+        for (i=0; i < a_clip_rect_nums; i++) {
+            rects[i].x = a_clip_rects[i].x1;
+            rects[i].y = a_clip_rects[i].y1;
+            rects[i].width = a_clip_rects[i].x2 - a_clip_rects[i].x1;
+            rects[i].height = a_clip_rects[i].y2 - a_clip_rects[i].y1;
+            EPHYR_LOG("(x,y,w,h): (%d,%d,%d,%d)\n",
+                      rects[i].x, rects[i].y, rects[i].width, rects[i].height);
+        }
+        xcb_set_clip_rectangles(conn,
+                                XCB_CLIP_ORDERING_YX_BANDED,
+                                gc,
+                                0,
+                                0,
+                                a_clip_rect_nums,
+                                rects);
+	free(rects);
+    }
+    xcb_xv_put_image(conn,
+                     port_priv->port_number,
+                     scrpriv->win,
+                     gc,
+                     a_image_id,
+                     a_src_x, a_src_y, a_src_w, a_src_h,
+                     a_drw_x, a_drw_y, a_drw_w, a_drw_h,
+                     width, height,
+                     data_len, a_buf);
+    xcb_free_gc(conn, gc);
+
+    is_ok = TRUE;
+
+out:
+    EPHYR_LOG("leave\n");
+    return is_ok;
+}
+
 static int
 ephyrPutImage(KdScreenInfo * a_info,
               DrawablePtr a_drawable,
@@ -945,13 +1032,12 @@ ephyrPutImage(KdScreenInfo * a_info,
 
     EPHYR_LOG("enter\n");
 
-    if (!ephyrHostXVPutImage(a_info->pScreen->myNum,
-                             port_priv->port_number,
+    if (!ephyrHostXVPutImage(a_info, port_priv,
                              a_id,
                              a_drw_x, a_drw_y, a_drw_w, a_drw_h,
                              a_src_x, a_src_y, a_src_w, a_src_h,
                              a_width, a_height, a_buf,
-                             (EphyrHostBox *) RegionRects(a_clipping_region),
+                             RegionRects(a_clipping_region),
                              RegionNumRects(a_clipping_region))) {
         EPHYR_LOG_ERROR("EphyrHostXVPutImage() failed\n");
         goto out;
@@ -1021,8 +1107,8 @@ ephyrReputImage(KdScreenInfo * a_info,
         EPHYR_LOG_ERROR("has null image buf in cache\n");
         goto out;
     }
-    if (!ephyrHostXVPutImage(a_info->pScreen->myNum,
-                             port_priv->port_number,
+    if (!ephyrHostXVPutImage(a_info,
+                             port_priv,
                              port_priv->image_id,
                              a_drw_x, a_drw_y,
                              port_priv->drw_w, port_priv->drw_h,
@@ -1030,7 +1116,7 @@ ephyrReputImage(KdScreenInfo * a_info,
                              port_priv->src_w, port_priv->src_h,
                              port_priv->image_width, port_priv->image_height,
                              port_priv->image_buf,
-                             (EphyrHostBox *) RegionRects(a_clipping_region),
+                             RegionRects(a_clipping_region),
                              RegionNumRects(a_clipping_region))) {
         EPHYR_LOG_ERROR("ephyrHostXVPutImage() failed\n");
         goto out;
@@ -1052,6 +1138,9 @@ ephyrPutVideo(KdScreenInfo * a_info,
               short a_drw_w, short a_drw_h,
               RegionPtr a_clipping_region, pointer a_port_priv)
 {
+    EphyrScrPriv *scrpriv = a_info->driver;
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    xcb_gcontext_t gc;
     EphyrPortPriv *port_priv = a_port_priv;
     BoxRec clipped_area, dst_box;
     int result = BadImplementation;
@@ -1072,13 +1161,14 @@ ephyrPutVideo(KdScreenInfo * a_info,
         goto out;
     }
 
-    if (!ephyrHostXVPutVideo(a_info->pScreen->myNum,
-                             port_priv->port_number,
-                             a_vid_x, a_vid_y, a_vid_w, a_vid_h,
-                             a_drw_x, a_drw_y, a_drw_w, a_drw_h)) {
-        EPHYR_LOG_ERROR("ephyrHostXVPutVideo() failed\n");
-        goto out;
-    }
+    gc = xcb_generate_id(conn);
+    xcb_create_gc(conn, gc, scrpriv->win, 0, NULL);
+    xcb_xv_put_video(conn, port_priv->port_number,
+                     scrpriv->win, gc,
+                     a_vid_x, a_vid_y, a_vid_w, a_vid_h,
+                     a_drw_x, a_drw_y, a_drw_w, a_drw_h);
+    xcb_free_gc(conn, gc);
+
     result = Success;
 
  out:
@@ -1095,6 +1185,9 @@ ephyrGetVideo(KdScreenInfo * a_info,
               short a_drw_w, short a_drw_h,
               RegionPtr a_clipping_region, pointer a_port_priv)
 {
+    EphyrScrPriv *scrpriv = a_info->driver;
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    xcb_gcontext_t gc;
     EphyrPortPriv *port_priv = a_port_priv;
     BoxRec clipped_area, dst_box;
     int result = BadImplementation;
@@ -1115,13 +1208,15 @@ ephyrGetVideo(KdScreenInfo * a_info,
         goto out;
     }
 
-    if (!ephyrHostXVGetVideo(a_info->pScreen->myNum,
-                             port_priv->port_number,
-                             a_vid_x, a_vid_y, a_vid_w, a_vid_h,
-                             a_drw_x, a_drw_y, a_drw_w, a_drw_h)) {
-        EPHYR_LOG_ERROR("ephyrHostXVGetVideo() failed\n");
-        goto out;
-    }
+    gc = xcb_generate_id(conn);
+    xcb_create_gc(conn, gc, scrpriv->win, 0, NULL);
+    xcb_xv_get_video(conn, port_priv->port_number,
+                     scrpriv->win, gc,
+                     a_vid_x, a_vid_y, a_vid_w, a_vid_h,
+                     a_drw_x, a_drw_y, a_drw_w, a_drw_h);
+
+    xcb_free_gc(conn, gc);
+
     result = Success;
 
  out:
@@ -1138,6 +1233,9 @@ ephyrPutStill(KdScreenInfo * a_info,
               short a_drw_w, short a_drw_h,
               RegionPtr a_clipping_region, pointer a_port_priv)
 {
+    EphyrScrPriv *scrpriv = a_info->driver;
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    xcb_gcontext_t gc;
     EphyrPortPriv *port_priv = a_port_priv;
     BoxRec clipped_area, dst_box;
     int result = BadImplementation;
@@ -1158,13 +1256,14 @@ ephyrPutStill(KdScreenInfo * a_info,
         goto out;
     }
 
-    if (!ephyrHostXVPutStill(a_info->pScreen->myNum,
-                             port_priv->port_number,
-                             a_vid_x, a_vid_y, a_vid_w, a_vid_h,
-                             a_drw_x, a_drw_y, a_drw_w, a_drw_h)) {
-        EPHYR_LOG_ERROR("ephyrHostXVPutStill() failed\n");
-        goto out;
-    }
+    gc = xcb_generate_id(conn);
+    xcb_create_gc(conn, gc, scrpriv->win, 0, NULL);
+    xcb_xv_put_still(conn, port_priv->port_number,
+                     scrpriv->win, gc,
+                     a_vid_x, a_vid_y, a_vid_w, a_vid_h,
+                     a_drw_x, a_drw_y, a_drw_w, a_drw_h);
+    xcb_free_gc(conn, gc);
+
     result = Success;
 
  out:
@@ -1181,6 +1280,9 @@ ephyrGetStill(KdScreenInfo * a_info,
               short a_drw_w, short a_drw_h,
               RegionPtr a_clipping_region, pointer a_port_priv)
 {
+    EphyrScrPriv *scrpriv = a_info->driver;
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    xcb_gcontext_t gc;
     EphyrPortPriv *port_priv = a_port_priv;
     BoxRec clipped_area, dst_box;
     int result = BadImplementation;
@@ -1201,13 +1303,14 @@ ephyrGetStill(KdScreenInfo * a_info,
         goto out;
     }
 
-    if (!ephyrHostXVGetStill(a_info->pScreen->myNum,
-                             port_priv->port_number,
-                             a_vid_x, a_vid_y, a_vid_w, a_vid_h,
-                             a_drw_x, a_drw_y, a_drw_w, a_drw_h)) {
-        EPHYR_LOG_ERROR("ephyrHostXVGetStill() failed\n");
-        goto out;
-    }
+    gc = xcb_generate_id(conn);
+    xcb_create_gc(conn, gc, scrpriv->win, 0, NULL);
+    xcb_xv_get_still(conn, port_priv->port_number,
+                     scrpriv->win, gc,
+                     a_vid_x, a_vid_y, a_vid_w, a_vid_h,
+                     a_drw_x, a_drw_y, a_drw_w, a_drw_h);
+    xcb_free_gc(conn, gc);
+
     result = Success;
 
  out:
commit 0b7ce74315213ccd31802847e5a83e67090ded14
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Aug 23 10:01:23 2013 -0700

    ephyr: Remove another host/server split for XV image formats.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/ephyrhostvideo.c b/hw/kdrive/ephyr/ephyrhostvideo.c
index e91cb25..3735f72 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.c
+++ b/hw/kdrive/ephyr/ephyrhostvideo.c
@@ -44,61 +44,6 @@
 #endif /*FALSE*/
 
 Bool
-ephyrHostXVQueryImageFormats(int a_port_id,
-                             EphyrHostImageFormat ** a_formats,
-                             int *a_num_format)
-{
-    xcb_connection_t *conn = hostx_get_xcbconn();
-    xcb_xv_list_image_formats_cookie_t cookie;
-    xcb_xv_list_image_formats_reply_t *reply;
-    xcb_xv_image_format_info_t *format;
-    EphyrHostImageFormat *ephyrFormats;
-    int i;
-
-    EPHYR_RETURN_VAL_IF_FAIL(a_formats && a_num_format, FALSE);
-
-    cookie = xcb_xv_list_image_formats(conn, a_port_id);
-    reply = xcb_xv_list_image_formats_reply(conn, cookie, NULL);
-    if (!reply)
-        return FALSE;
-    *a_num_format = reply->num_formats;
-    ephyrFormats = calloc(reply->num_formats, sizeof(EphyrHostImageFormat));
-    if (!ephyrFormats) {
-        free(reply);
-        return FALSE;
-    }
-    format = xcb_xv_list_image_formats_format(reply);
-    for (i = 0; i < reply->num_formats; i++) {
-        ephyrFormats[i].id = format[i].id;
-        ephyrFormats[i].type = format[i].type;
-        ephyrFormats[i].byte_order = format[i].byte_order;
-        memcpy(ephyrFormats[i].guid, format[i].guid, 16);
-        ephyrFormats[i].bits_per_pixel = format[i].bpp;
-        ephyrFormats[i].format = format[i].format;
-        ephyrFormats[i].num_planes = format[i].num_planes;
-        ephyrFormats[i].depth = format[i].depth;
-        ephyrFormats[i].red_mask = format[i].red_mask;
-        ephyrFormats[i].green_mask = format[i].green_mask;
-        ephyrFormats[i].blue_mask = format[i].blue_mask;
-        ephyrFormats[i].y_sample_bits = format[i].y_sample_bits;
-        ephyrFormats[i].u_sample_bits = format[i].u_sample_bits;
-        ephyrFormats[i].v_sample_bits = format[i].v_sample_bits;
-        ephyrFormats[i].horz_y_period = format[i].vhorz_y_period;
-        ephyrFormats[i].horz_u_period = format[i].vhorz_u_period;
-        ephyrFormats[i].horz_v_period = format[i].vhorz_v_period;
-        ephyrFormats[i].vert_y_period = format[i].vvert_y_period;
-        ephyrFormats[i].vert_u_period = format[i].vvert_u_period;
-        ephyrFormats[i].vert_v_period = format[i].vvert_v_period;
-        memcpy(ephyrFormats[i].component_order, format[i].vcomp_order, 32);
-        ephyrFormats[i].scanline_order = format[i].vscanline_order;
-    }
-    *a_formats = ephyrFormats;
-
-    free(reply);
-    return TRUE;
-}
-
-Bool
 ephyrHostXVQueryBestSize(int a_port_id,
                          Bool a_motion,
                          unsigned int a_frame_w,
diff --git a/hw/kdrive/ephyr/ephyrhostvideo.h b/hw/kdrive/ephyr/ephyrhostvideo.h
index 0c1f1da..080caa8 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.h
+++ b/hw/kdrive/ephyr/ephyrhostvideo.h
@@ -31,48 +31,11 @@
 #include <xcb/xv.h>
 #include <X11/Xdefs.h>
 
-typedef struct _EphyrHostImageFormat {
-    int id;                     /* Unique descriptor for the format */
-    int type;                   /* XvRGB, XvYUV */
-    int byte_order;             /* LSBFirst, MSBFirst */
-    char guid[16];              /* Globally Unique IDentifier */
-    int bits_per_pixel;
-    int format;                 /* XvPacked, XvPlanar */
-    int num_planes;
-
-    /* for RGB formats only */
-    int depth;
-    unsigned int red_mask;
-    unsigned int green_mask;
-    unsigned int blue_mask;
-
-    /* for YUV formats only */
-    unsigned int y_sample_bits;
-    unsigned int u_sample_bits;
-    unsigned int v_sample_bits;
-    unsigned int horz_y_period;
-    unsigned int horz_u_period;
-    unsigned int horz_v_period;
-    unsigned int vert_y_period;
-    unsigned int vert_u_period;
-    unsigned int vert_v_period;
-    char component_order[32];   /* eg. UYVY */
-    int scanline_order;         /* XvTopToBottom, XvBottomToTop */
-} EphyrHostImageFormat;
-
 typedef struct {
     unsigned short x1, y1, x2, y2;
 } EphyrHostBox;
 
 /*
- * image format
- */
-
-Bool ephyrHostXVQueryImageFormats(int a_port_id,
-                                  EphyrHostImageFormat ** a_formats,
-                                  int *a_num_format);
-
-/*
  *size query
  */
 Bool ephyrHostXVQueryBestSize(int a_port_id,
diff --git a/hw/kdrive/ephyr/ephyrvideo.c b/hw/kdrive/ephyr/ephyrvideo.c
index eeddc4f..46a0ca3 100644
--- a/hw/kdrive/ephyr/ephyrvideo.c
+++ b/hw/kdrive/ephyr/ephyrvideo.c
@@ -420,13 +420,65 @@ translate_xv_attributes(KdVideoAdaptorPtr adaptor,
 }
 
 static Bool
+translate_xv_image_formats(KdVideoAdaptorPtr adaptor,
+                           xcb_xv_adaptor_info_t *host_adaptor)
+{
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    int i = 0;
+    xcb_xv_list_image_formats_cookie_t cookie =
+        xcb_xv_list_image_formats(conn, host_adaptor->base_id);
+    xcb_xv_list_image_formats_reply_t *reply =
+        xcb_xv_list_image_formats_reply(conn, cookie, NULL);
+    xcb_xv_image_format_info_t *formats;
+
+    if (!reply)
+        return FALSE;
+
+    adaptor->nImages = reply->num_formats;
+    adaptor->pImages = calloc(reply->num_formats, sizeof(KdImageRec));
+    if (!adaptor->pImages) {
+        free(reply);
+        return FALSE;
+    }
+
+    formats = xcb_xv_list_image_formats_format(reply);
+    for (i = 0; i < reply->num_formats; i++) {
+        KdImagePtr image = &adaptor->pImages[i];
+
+        image->id = formats[i].id;
+        image->type = formats[i].type;
+        image->byte_order = formats[i].byte_order;
+        memcpy(image->guid, formats[i].guid, 16);
+        image->bits_per_pixel = formats[i].bpp;
+        image->format = formats[i].format;
+        image->num_planes = formats[i].num_planes;
+        image->depth = formats[i].depth;
+        image->red_mask = formats[i].red_mask;
+        image->green_mask = formats[i].green_mask;
+        image->blue_mask = formats[i].blue_mask;
+        image->y_sample_bits = formats[i].y_sample_bits;
+        image->u_sample_bits = formats[i].u_sample_bits;
+        image->v_sample_bits = formats[i].v_sample_bits;
+        image->horz_y_period = formats[i].vhorz_y_period;
+        image->horz_u_period = formats[i].vhorz_u_period;
+        image->horz_v_period = formats[i].vhorz_v_period;
+        image->vert_y_period = formats[i].vvert_y_period;
+        image->vert_u_period = formats[i].vvert_u_period;
+        image->vert_v_period = formats[i].vvert_v_period;
+        memcpy(image->component_order, formats[i].vcomp_order, 32);
+        image->scanline_order = formats[i].vscanline_order;
+    }
+
+    free(reply);
+    return TRUE;
+}
+
+static Bool
 ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this)
 {
     xcb_connection_t *conn = hostx_get_xcbconn();
     xcb_screen_t *xscreen = xcb_aux_get_screen(conn, hostx_get_screen());
-    EphyrHostImageFormat *image_formats = NULL;
-    int base_port_id = 0,
-        num_formats = 0, i = 0, port_priv_offset = 0;
+    int base_port_id = 0, i = 0, port_priv_offset = 0;
     Bool is_ok = FALSE;
     xcb_generic_error_t *e = NULL;
     xcb_xv_adaptor_info_iterator_t it;
@@ -535,14 +587,11 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this)
         }
         }
 
-        if (!ephyrHostXVQueryImageFormats(base_port_id,
-                                          &image_formats, &num_formats)) {
+        if (!translate_xv_image_formats(&a_this->adaptors[i], cur_host_adaptor)) {
             EPHYR_LOG_ERROR("failed to get image formats "
                             "for adaptor %d\n", i);
             continue;
         }
-        a_this->adaptors[i].pImages = (KdImagePtr) image_formats;
-        a_this->adaptors[i].nImages = num_formats;
 
         xcb_xv_adaptor_info_next(&it);
     }
commit 1dcc28bcb402d7286d18b41b469062a5c176d7eb
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Aug 22 17:00:41 2013 -0700

    ephyr: Remove the host/server split for video encodings.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/ephyrhostvideo.c b/hw/kdrive/ephyr/ephyrhostvideo.c
index 82a40a0..e91cb25 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.c
+++ b/hw/kdrive/ephyr/ephyrhostvideo.c
@@ -44,58 +44,6 @@
 #endif /*FALSE*/
 
 Bool
-ephyrHostXVQueryEncodings(int a_port_id,
-                          EphyrHostEncoding ** a_encodings,
-                          unsigned int *a_num_encodings)
-{
-    EphyrHostEncoding *encodings = NULL;
-    xcb_xv_encoding_info_iterator_t encoding_info;
-    xcb_xv_query_encodings_cookie_t cookie;
-    xcb_xv_query_encodings_reply_t *reply;
-    unsigned int num_encodings = 0, i;
-
-    EPHYR_RETURN_VAL_IF_FAIL(a_encodings && a_num_encodings, FALSE);
-
-    cookie = xcb_xv_query_encodings(hostx_get_xcbconn(), a_port_id);
-    reply = xcb_xv_query_encodings_reply(hostx_get_xcbconn(), cookie, NULL);
-    if (!reply)
-        return FALSE;
-    num_encodings = reply->num_encodings;
-    encoding_info = xcb_xv_query_encodings_info_iterator(reply);
-    if (num_encodings) {
-        encodings = calloc(num_encodings, sizeof (EphyrHostEncoding));
-        for (i=0; i<num_encodings; i++, xcb_xv_encoding_info_next(&encoding_info)) {
-            encodings[i].id = encoding_info.data->encoding;
-            encodings[i].name = malloc(encoding_info.data->name_size + 1);
-	    memcpy(encodings[i].name, xcb_xv_encoding_info_name(encoding_info.data), encoding_info.data->name_size);
-	    encodings[i].name[encoding_info.data->name_size] = '\0';
-            encodings[i].width = encoding_info.data->width;
-            encodings[i].height = encoding_info.data->height;
-            encodings[i].rate.numerator = encoding_info.data->rate.numerator;
-            encodings[i].rate.denominator = encoding_info.data->rate.denominator;
-        }
-    }
-    free(reply);
-    *a_encodings = encodings;
-    *a_num_encodings = num_encodings;
-
-    return TRUE;
-}
-
-void
-ephyrHostEncodingsDelete(EphyrHostEncoding * a_encodings, int a_num_encodings)
-{
-    int i = 0;
-
-    if (!a_encodings)
-        return;
-    for (i = 0; i < a_num_encodings; i++) {
-        free(a_encodings[i].name);
-        a_encodings[i].name = NULL;
-    }
-    free(a_encodings);
-}
-Bool
 ephyrHostXVQueryImageFormats(int a_port_id,
                              EphyrHostImageFormat ** a_formats,
                              int *a_num_format)
diff --git a/hw/kdrive/ephyr/ephyrhostvideo.h b/hw/kdrive/ephyr/ephyrhostvideo.h
index d37af00..0c1f1da 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.h
+++ b/hw/kdrive/ephyr/ephyrhostvideo.h
@@ -31,18 +31,6 @@
 #include <xcb/xv.h>
 #include <X11/Xdefs.h>
 
-typedef struct _EphyrHostRational {
-    int numerator;
-    int denominator;
-} EphyrHostRational;
-
-typedef struct _EphyrHostEncoding {
-    int id;
-    char *name;
-    unsigned short width, height;
-    EphyrHostRational rate;
-} EphyrHostEncoding;
-
 typedef struct _EphyrHostImageFormat {
     int id;                     /* Unique descriptor for the format */
     int type;                   /* XvRGB, XvYUV */
@@ -77,16 +65,6 @@ typedef struct {
 } EphyrHostBox;
 
 /*
- * encoding
- */
-Bool ephyrHostXVQueryEncodings(int a_port_id,
-                               EphyrHostEncoding ** a_encodings,
-                               unsigned int *a_num_encodings);
-
-void ephyrHostEncodingsDelete(EphyrHostEncoding * a_encodings,
-                              int a_num_encodings);
-
-/*
  * image format
  */
 
diff --git a/hw/kdrive/ephyr/ephyrvideo.c b/hw/kdrive/ephyr/ephyrvideo.c
index 2b37674..eeddc4f 100644
--- a/hw/kdrive/ephyr/ephyrvideo.c
+++ b/hw/kdrive/ephyr/ephyrvideo.c
@@ -332,24 +332,47 @@ ephyrXVPrivDelete(EphyrXVPriv * a_this)
     EPHYR_LOG("leave\n");
 }
 
-static KdVideoEncodingPtr
-videoEncodingDup(EphyrHostEncoding * a_encodings, int a_num_encodings)
+static Bool
+translate_video_encodings(KdVideoAdaptorPtr adaptor,
+                          xcb_xv_adaptor_info_t *host_adaptor)
 {
-    KdVideoEncodingPtr result = NULL;
-    int i = 0;
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    int i;
+    xcb_xv_query_encodings_cookie_t cookie;
+    xcb_xv_query_encodings_reply_t *reply;
+    xcb_xv_encoding_info_iterator_t encoding_it;
 
-    EPHYR_RETURN_VAL_IF_FAIL(a_encodings && a_num_encodings, NULL);
+    cookie = xcb_xv_query_encodings(conn, host_adaptor->base_id);
+    reply = xcb_xv_query_encodings_reply(conn, cookie, NULL);
+    if (!reply)
+        return FALSE;
 
-    result = calloc(a_num_encodings, sizeof(KdVideoEncodingRec));
-    for (i = 0; i < a_num_encodings; i++) {
-        result[i].id = a_encodings[i].id;
-        result[i].name = strdup(a_encodings[i].name);
-        result[i].width = a_encodings[i].width;
-        result[i].height = a_encodings[i].height;
-        result[i].rate.numerator = a_encodings[i].rate.numerator;
-        result[i].rate.denominator = a_encodings[i].rate.denominator;
+    adaptor->nEncodings = reply->num_encodings;
+    adaptor->pEncodings = calloc(adaptor->nEncodings,
+                                  sizeof(*adaptor->pEncodings));
+    if (!adaptor->pEncodings) {
+        free(reply);
+        return FALSE;
     }
-    return result;
+
+    encoding_it = xcb_xv_query_encodings_info_iterator(reply);
+    for (i = 0; i < adaptor->nEncodings; i++) {
+        xcb_xv_encoding_info_t *encoding_info = encoding_it.data;
+        KdVideoEncodingPtr encoding = &adaptor->pEncodings[i];
+
+        encoding->id = encoding_info->encoding;
+        encoding->name = strndup(xcb_xv_encoding_info_name(encoding_info),
+                                 encoding_info->name_size);
+        encoding->width = encoding_info->width;
+        encoding->height = encoding_info->height;
+        encoding->rate.numerator = encoding_info->rate.numerator;
+        encoding->rate.denominator = encoding_info->rate.denominator;
+
+        xcb_xv_encoding_info_next(&encoding_it);
+    }
+
+    free(reply);
+    return TRUE;
 }
 
 static Bool
@@ -401,11 +424,9 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this)
 {
     xcb_connection_t *conn = hostx_get_xcbconn();
     xcb_screen_t *xscreen = xcb_aux_get_screen(conn, hostx_get_screen());
-    EphyrHostEncoding *encodings = NULL;
     EphyrHostImageFormat *image_formats = NULL;
     int base_port_id = 0,
         num_formats = 0, i = 0, port_priv_offset = 0;
-    unsigned num_encodings = 0;
     Bool is_ok = FALSE;
     xcb_generic_error_t *e = NULL;
     xcb_xv_adaptor_info_iterator_t it;
@@ -472,15 +493,12 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this)
         if (!s_base_port_id)
             s_base_port_id = base_port_id;
 
-        if (!ephyrHostXVQueryEncodings(base_port_id,
-                                       &encodings, &num_encodings)) {
+        if (!translate_video_encodings(&a_this->adaptors[i],
+                                       cur_host_adaptor)) {
             EPHYR_LOG_ERROR("failed to get encodings for port port id %d,"
                             " adaptors %d\n", base_port_id, i);
             continue;
         }
-        a_this->adaptors[i].nEncodings = num_encodings;
-        a_this->adaptors[i].pEncodings =
-            videoEncodingDup(encodings, num_encodings);
 
         a_this->adaptors[i].nFormats = cur_host_adaptor->num_formats;
         a_this->adaptors[i].pFormats =
@@ -531,10 +549,6 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this)
     is_ok = TRUE;
 
  out:
-    if (encodings) {
-        ephyrHostEncodingsDelete(encodings, num_encodings);
-        encodings = NULL;
-    }
     EPHYR_LOG("leave\n");
     return is_ok;
 }
commit 28a37757e11068b4594f4128a0d64c6bc9a53ee0
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Aug 22 17:26:21 2013 -0700

    ephyr: Remove the host/server split for XV formats.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/ephyrhostvideo.c b/hw/kdrive/ephyr/ephyrhostvideo.c
index c1b7a97..82a40a0 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.c
+++ b/hw/kdrive/ephyr/ephyrhostvideo.c
@@ -43,31 +43,6 @@
 #define FALSE 0
 #endif /*FALSE*/
 
-EphyrHostVideoFormat*
-ephyrHostXVAdaptorGetVideoFormats (const xcb_xv_adaptor_info_t *a_this,
-                                   int *a_nb_formats)
-{
-    EphyrHostVideoFormat *formats = NULL;
-    int nb_formats = 0, i = 0;
-    xcb_xv_format_t *format = xcb_xv_adaptor_info_formats(a_this);
-
-    EPHYR_RETURN_VAL_IF_FAIL(a_this, NULL);
-
-    nb_formats = a_this->num_formats;
-    formats = calloc(nb_formats, sizeof(EphyrHostVideoFormat));
-    for (i = 0; i < nb_formats; i++) {
-        xcb_visualtype_t *visual =
-            xcb_aux_find_visual_by_id(
-                    xcb_aux_get_screen(hostx_get_xcbconn(), hostx_get_screen()),
-                    format[i].visual);
-        formats[i].depth = format[i].depth;
-        formats[i].visual_class = visual->_class;
-    }
-    if (a_nb_formats)
-        *a_nb_formats = nb_formats;
-    return formats;
-}
-
 Bool
 ephyrHostXVQueryEncodings(int a_port_id,
                           EphyrHostEncoding ** a_encodings,
diff --git a/hw/kdrive/ephyr/ephyrhostvideo.h b/hw/kdrive/ephyr/ephyrhostvideo.h
index 6fa8f7a..d37af00 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.h
+++ b/hw/kdrive/ephyr/ephyrhostvideo.h
@@ -31,11 +31,6 @@
 #include <xcb/xv.h>
 #include <X11/Xdefs.h>
 
-typedef struct _EphyrHostVideoFormat {
-    char depth;
-    short visual_class;
-} EphyrHostVideoFormat;
-
 typedef struct _EphyrHostRational {
     int numerator;
     int denominator;
@@ -82,12 +77,6 @@ typedef struct {
 } EphyrHostBox;
 
 /*
- * host adaptor
- */
-EphyrHostVideoFormat *ephyrHostXVAdaptorGetVideoFormats
-    (const xcb_xv_adaptor_info_t *a_this, int *a_nb_formats);
-
-/*
  * encoding
  */
 Bool ephyrHostXVQueryEncodings(int a_port_id,
diff --git a/hw/kdrive/ephyr/ephyrvideo.c b/hw/kdrive/ephyr/ephyrvideo.c
index 5904265..2b37674 100644
--- a/hw/kdrive/ephyr/ephyrvideo.c
+++ b/hw/kdrive/ephyr/ephyrvideo.c
@@ -401,10 +401,9 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this)
 {
     xcb_connection_t *conn = hostx_get_xcbconn();
     xcb_screen_t *xscreen = xcb_aux_get_screen(conn, hostx_get_screen());
-    EphyrHostVideoFormat *video_formats = NULL;
     EphyrHostEncoding *encodings = NULL;
     EphyrHostImageFormat *image_formats = NULL;
-    int num_video_formats = 0, base_port_id = 0,
+    int base_port_id = 0,
         num_formats = 0, i = 0, port_priv_offset = 0;
     unsigned num_encodings = 0;
     Bool is_ok = FALSE;
@@ -425,6 +424,7 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this)
             goto out;
         }
     }
+
     if (a_this->host_adaptors)
         a_this->num_adaptors = a_this->host_adaptors->num_adaptors;
     if (a_this->num_adaptors < 0) {
@@ -447,6 +447,7 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this)
     it = xcb_xv_query_adaptors_info_iterator(a_this->host_adaptors);
     for (i = 0; i < a_this->num_adaptors; i++) {
         xcb_xv_adaptor_info_t *cur_host_adaptor = it.data;
+        xcb_xv_format_t *format = xcb_xv_adaptor_info_formats(cur_host_adaptor);
         int j = 0;
 
         a_this->adaptors[i].nPorts = cur_host_adaptor->num_ports;
@@ -480,11 +481,18 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this)
         a_this->adaptors[i].nEncodings = num_encodings;
         a_this->adaptors[i].pEncodings =
             videoEncodingDup(encodings, num_encodings);
-        video_formats = (EphyrHostVideoFormat *)
-            ephyrHostXVAdaptorGetVideoFormats(cur_host_adaptor,
-                                              &num_video_formats);
-        a_this->adaptors[i].pFormats = (KdVideoFormatPtr) video_formats;
-        a_this->adaptors[i].nFormats = num_video_formats;
+
+        a_this->adaptors[i].nFormats = cur_host_adaptor->num_formats;
+        a_this->adaptors[i].pFormats =
+            calloc(cur_host_adaptor->num_formats,
+                   sizeof(*a_this->adaptors[i].pFormats));
+        for (j = 0; j < cur_host_adaptor->num_formats; j++) {
+            xcb_visualtype_t *visual =
+                xcb_aux_find_visual_by_id(xscreen, format[j].visual);
+            a_this->adaptors[i].pFormats[j].depth = format[j].depth;
+            a_this->adaptors[i].pFormats[j].class = visual->_class;
+        }
+
         a_this->adaptors[i].pPortPrivates =
             calloc(a_this->adaptors[i].nPorts,
                    sizeof(DevUnion) + sizeof(EphyrPortPriv));
commit 41134d393a37dd5b971b018a3888fbfea0b9c736
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Aug 22 17:21:37 2013 -0700

    ephyr: Remove the host/server split for XV attributes.
    
    v2: Fix leaks of xcb replies (caught by Julien)
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/ephyrhostvideo.c b/hw/kdrive/ephyr/ephyrhostvideo.c
index 7665b25..c1b7a97 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.c
+++ b/hw/kdrive/ephyr/ephyrhostvideo.c
@@ -120,30 +120,6 @@ ephyrHostEncodingsDelete(EphyrHostEncoding * a_encodings, int a_num_encodings)
     }
     free(a_encodings);
 }
-
-void
-ephyrHostAttributesDelete(xcb_xv_query_port_attributes_reply_t *a_attributes)
-{
-    free(a_attributes);
-}
-
-Bool
-ephyrHostXVQueryPortAttributes(int a_port_id,
-                               xcb_xv_query_port_attributes_reply_t **a_attributes)
-{
-    xcb_xv_query_port_attributes_cookie_t cookie;
-    xcb_xv_query_port_attributes_reply_t *reply;
-    xcb_connection_t *conn = hostx_get_xcbconn();
-
-    EPHYR_RETURN_VAL_IF_FAIL(a_attributes, FALSE);
-
-    cookie = xcb_xv_query_port_attributes(conn, a_port_id);
-    reply = xcb_xv_query_port_attributes_reply(conn, cookie, NULL);
-    *a_attributes = reply;
-
-    return (reply != NULL);
-}
-
 Bool
 ephyrHostXVQueryImageFormats(int a_port_id,
                              EphyrHostImageFormat ** a_formats,
@@ -200,51 +176,6 @@ ephyrHostXVQueryImageFormats(int a_port_id,
 }
 
 Bool
-ephyrHostXVSetPortAttribute(int a_port_id, int a_atom, int a_attr_value)
-{
-    EPHYR_LOG("atom,value: (%d,%d)\n", a_atom, a_attr_value);
-
-    xcb_xv_set_port_attribute(hostx_get_xcbconn(),
-                              a_port_id,
-                              a_atom,
-                              a_attr_value);
-    xcb_flush(hostx_get_xcbconn());
-    EPHYR_LOG("leave\n");
-
-    return TRUE;
-}
-
-Bool
-ephyrHostXVGetPortAttribute(int a_port_id, int a_atom, int *a_attr_value)
-{
-    Bool ret = FALSE;
-    xcb_connection_t *conn = hostx_get_xcbconn();
-    xcb_xv_get_port_attribute_cookie_t cookie;
-    xcb_xv_get_port_attribute_reply_t *reply;
-    xcb_generic_error_t *e;
-
-    EPHYR_RETURN_VAL_IF_FAIL(a_attr_value, FALSE);
-
-    EPHYR_LOG("enter, a_port_id: %d, a_atomid: %d\n", a_port_id, a_atom);
-
-    cookie = xcb_xv_get_port_attribute(conn, a_port_id, a_atom);
-    reply = xcb_xv_get_port_attribute_reply(conn, cookie, &e);
-    if (e) {
-        EPHYR_LOG_ERROR ("XvGetPortAttribute() failed: %d \n", e->error_code);
-        free(e);
-        goto out;
-    }
-    *a_attr_value = reply->value;
-    EPHYR_LOG("atom,value: (%d, %d)\n", a_atom, *a_attr_value);
-
-    ret = TRUE;
-
- out:
-    EPHYR_LOG("leave\n");
-    return ret;
-}
-
-Bool
 ephyrHostXVQueryBestSize(int a_port_id,
                          Bool a_motion,
                          unsigned int a_frame_w,
@@ -286,44 +217,6 @@ out:
 }
 
 Bool
-ephyrHostXVQueryImageAttributes(int a_port_id,
-                                int a_image_id /*image fourcc code */ ,
-                                unsigned short *a_width,
-                                unsigned short *a_height,
-                                int *a_image_size,
-                                int *a_pitches, int *a_offsets)
-{
-    xcb_connection_t *conn = hostx_get_xcbconn ();
-    xcb_xv_query_image_attributes_cookie_t cookie;
-    xcb_xv_query_image_attributes_reply_t *reply;
-
-    EPHYR_RETURN_VAL_IF_FAIL(a_width, FALSE);
-    EPHYR_RETURN_VAL_IF_FAIL(a_height, FALSE);
-    EPHYR_RETURN_VAL_IF_FAIL(a_image_size, FALSE);
-
-    cookie = xcb_xv_query_image_attributes(conn,
-                                           a_port_id, a_image_id,
-                                           *a_width, *a_height);
-    reply = xcb_xv_query_image_attributes_reply(conn, cookie, NULL);
-    if (!reply)
-        return FALSE;
-    if (a_pitches && a_offsets) {
-        memcpy(a_pitches,
-               xcb_xv_query_image_attributes_pitches(reply),
-               reply->num_planes << 2);
-        memcpy(a_offsets,
-               xcb_xv_query_image_attributes_offsets(reply),
-               reply->num_planes << 2);
-    }
-    *a_width = reply->width;
-    *a_height = reply->height;
-    *a_image_size = reply->data_size;
-    free(reply);
-
-    return TRUE;
-}
-
-Bool
 ephyrHostGetAtom(const char *a_name, Bool a_create_if_not_exists, int *a_atom)
 {
     xcb_connection_t *conn = hostx_get_xcbconn();
diff --git a/hw/kdrive/ephyr/ephyrhostvideo.h b/hw/kdrive/ephyr/ephyrhostvideo.h
index 7d2dbe2..6fa8f7a 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.h
+++ b/hw/kdrive/ephyr/ephyrhostvideo.h
@@ -98,25 +98,12 @@ void ephyrHostEncodingsDelete(EphyrHostEncoding * a_encodings,
                               int a_num_encodings);
 
 /*
- * attribute
- */
-Bool ephyrHostXVQueryPortAttributes(int a_port_id,
-                                    xcb_xv_query_port_attributes_reply_t **a_attributes);
-
-void ephyrHostAttributesDelete(xcb_xv_query_port_attributes_reply_t *a_attributes);
-
-/*
  * image format
  */
 
 Bool ephyrHostXVQueryImageFormats(int a_port_id,
                                   EphyrHostImageFormat ** a_formats,
                                   int *a_num_format);
-/*
- * Port Attribute Get/Set
- */
-Bool ephyrHostXVSetPortAttribute(int a_port_id, int a_atom, int a_attr_value);
-Bool ephyrHostXVGetPortAttribute(int a_port_id, int a_atom, int *a_attr_value);
 
 /*
  *size query
@@ -130,12 +117,6 @@ Bool ephyrHostXVQueryBestSize(int a_port_id,
                               unsigned int *a_actual_w,
                               unsigned int *a_actual_h);
 
-Bool ephyrHostXVQueryImageAttributes(int a_port_id,
-                                     int a_image_id /*image fourcc code */ ,
-                                     unsigned short *a_width,
-                                     unsigned short *a_height,
-                                     int *a_image_size,
-                                     int *a_pitches, int *a_offsets);
 /*
  * atom
  */
diff --git a/hw/kdrive/ephyr/ephyrvideo.c b/hw/kdrive/ephyr/ephyrvideo.c
index be59886..5904265 100644
--- a/hw/kdrive/ephyr/ephyrvideo.c
+++ b/hw/kdrive/ephyr/ephyrvideo.c
@@ -352,32 +352,48 @@ videoEncodingDup(EphyrHostEncoding * a_encodings, int a_num_encodings)
     return result;
 }
 
-static KdAttributePtr
-portAttributesDup(const xcb_xv_query_port_attributes_reply_t *a_encodings)
+static Bool
+translate_xv_attributes(KdVideoAdaptorPtr adaptor,
+                        xcb_xv_adaptor_info_t *host_adaptor)
 {
+    xcb_connection_t *conn = hostx_get_xcbconn();
     int i = 0;
-    KdAttributePtr result = NULL;
     xcb_xv_attribute_info_iterator_t it;
+    xcb_xv_query_port_attributes_cookie_t cookie =
+        xcb_xv_query_port_attributes(conn, host_adaptor->base_id);
+    xcb_xv_query_port_attributes_reply_t *reply =
+        xcb_xv_query_port_attributes_reply(conn, cookie, NULL);
 
-    EPHYR_RETURN_VAL_IF_FAIL(a_encodings, NULL);
+    if (!reply)
+        return FALSE;
 
-    result = calloc(a_encodings->num_attributes, sizeof(KdAttributeRec));
-    if (!result) {
+    adaptor->nAttributes = reply->num_attributes;
+    adaptor->pAttributes = calloc(reply->num_attributes,
+                                  sizeof(*adaptor->pAttributes));
+    if (!adaptor->pAttributes) {
         EPHYR_LOG_ERROR("failed to allocate attributes\n");
-        return NULL;
+        free(reply);
+        return FALSE;
     }
-    it = xcb_xv_query_port_attributes_attributes_iterator(a_encodings);
-    for (i = 0;
-         i < a_encodings->num_attributes;
-         xcb_xv_attribute_info_next(&it), i++) {
-        result[i].flags = it.data->flags;
-        result[i].min_value = it.data->min;
-        result[i].max_value = it.data->max;
-        result[i].name = malloc(it.data->size + 1);
-	memcpy (result[i].name, xcb_xv_attribute_info_name(it.data), it.data->size);
-	result[i].name[it.data->size] = '\0';
+
+    it = xcb_xv_query_port_attributes_attributes_iterator(reply);
+    for (i = 0; i < reply->num_attributes; i++) {
+        KdAttributePtr attribute = &adaptor->pAttributes[i];
+
+        attribute->flags = it.data->flags;
+        attribute->min_value = it.data->min;
+        attribute->max_value = it.data->max;
+        attribute->name = strndup(xcb_xv_attribute_info_name(it.data),
+                                  it.data->size);
+
+        /* make sure atoms of attrs names are created in xephyr */
+        MakeAtom(xcb_xv_attribute_info_name(it.data), it.data->size, TRUE);
+
+        xcb_xv_attribute_info_next(&it);
     }
-    return result;
+
+    free(reply);
+    return TRUE;
 }
 
 static Bool
@@ -387,7 +403,6 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this)
     xcb_screen_t *xscreen = xcb_aux_get_screen(conn, hostx_get_screen());
     EphyrHostVideoFormat *video_formats = NULL;
     EphyrHostEncoding *encodings = NULL;
-    xcb_xv_query_port_attributes_reply_t *attributes = NULL;
     EphyrHostImageFormat *image_formats = NULL;
     int num_video_formats = 0, base_port_id = 0,
         num_formats = 0, i = 0, port_priv_offset = 0;
@@ -485,20 +500,15 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this)
             port_priv->xv_priv = a_this;
             a_this->adaptors[i].pPortPrivates[j].ptr = port_priv;
         }
-        if (!ephyrHostXVQueryPortAttributes(base_port_id, &attributes)) {
+
+        if (!translate_xv_attributes(&a_this->adaptors[i], cur_host_adaptor)) {
+        {
             EPHYR_LOG_ERROR("failed to get port attribute "
                             "for adaptor %d\n", i);
             continue;
         }
-        a_this->adaptors[i].pAttributes =
-            portAttributesDup(attributes);
-        a_this->adaptors[i].nAttributes = attributes->num_attributes;
-        /*make sure atoms of attrs names are created in xephyr */
-        for (j = 0; j < a_this->adaptors[i].nAttributes; j++) {
-            if (a_this->adaptors[i].pAttributes[j].name)
-                MakeAtom(a_this->adaptors[i].pAttributes[j].name,
-                         strlen(a_this->adaptors[i].pAttributes[j].name), TRUE);
         }
+
         if (!ephyrHostXVQueryImageFormats(base_port_id,
                                           &image_formats, &num_formats)) {
             EPHYR_LOG_ERROR("failed to get image formats "
@@ -517,10 +527,6 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this)
         ephyrHostEncodingsDelete(encodings, num_encodings);
         encodings = NULL;
     }
-    if (attributes) {
-        ephyrHostAttributesDelete(attributes);
-        attributes = NULL;
-    }
     EPHYR_LOG("leave\n");
     return is_ok;
 }
@@ -650,20 +656,27 @@ ephyrXVPrivGetImageBufSize(int a_port_id,
                            unsigned short a_width,
                            unsigned short a_height, int *a_size)
 {
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    xcb_xv_query_image_attributes_cookie_t cookie;
+    xcb_xv_query_image_attributes_reply_t *reply;
     Bool is_ok = FALSE;
-    unsigned short width = a_width, height = a_height;
 
     EPHYR_RETURN_VAL_IF_FAIL(a_size, FALSE);
 
     EPHYR_LOG("enter\n");
 
-    if (!ephyrHostXVQueryImageAttributes(a_port_id, a_image_id,
-                                         &width, &height, a_size, NULL, NULL)) {
-        EPHYR_LOG_ERROR("failed to get image attributes\n");
+    cookie = xcb_xv_query_image_attributes(conn,
+                                           a_port_id, a_image_id,
+                                           a_width, a_height);
+    reply = xcb_xv_query_image_attributes_reply(conn, cookie, NULL);
+    if (!reply)
         goto out;
-    }
+
+    *a_size = reply->data_size;
     is_ok = TRUE;
 
+    free(reply);
+
  out:
     EPHYR_LOG("leave\n");
     return is_ok;
@@ -715,6 +728,7 @@ static int
 ephyrSetPortAttribute(KdScreenInfo * a_info,
                       Atom a_attr_name, int a_attr_value, pointer a_port_priv)
 {
+    xcb_connection_t *conn = hostx_get_xcbconn();
     int res = Success, host_atom = 0;
     EphyrPortPriv *port_priv = a_port_priv;
     Bool is_attr_valid = FALSE;
@@ -755,12 +769,9 @@ ephyrSetPortAttribute(KdScreenInfo * a_info,
          */
     }
 
-    if (!ephyrHostXVSetPortAttribute(port_priv->port_number,
-                                     host_atom, a_attr_value)) {
-        EPHYR_LOG_ERROR("failed to set port attribute\n");
-        res = BadMatch;
-        goto out;
-    }
+    xcb_xv_set_port_attribute(conn, port_priv->port_number,
+                              host_atom, a_attr_value);
+    xcb_flush(conn);
 
     res = Success;
  out:
@@ -772,8 +783,12 @@ static int
 ephyrGetPortAttribute(KdScreenInfo * a_screen_info,
                       Atom a_attr_name, int *a_attr_value, pointer a_port_priv)
 {
+    xcb_connection_t *conn = hostx_get_xcbconn();
     int res = Success, host_atom = 0;
     EphyrPortPriv *port_priv = a_port_priv;
+    xcb_generic_error_t *e;
+    xcb_xv_get_port_attribute_cookie_t cookie;
+    xcb_xv_get_port_attribute_reply_t *reply;
 
     EPHYR_RETURN_VAL_IF_FAIL(port_priv, BadMatch);
     EPHYR_RETURN_VAL_IF_FAIL(ValidAtom(a_attr_name), BadMatch);
@@ -788,12 +803,17 @@ ephyrGetPortAttribute(KdScreenInfo * a_screen_info,
         goto out;
     }
 
-    if (!ephyrHostXVGetPortAttribute(port_priv->port_number,
-                                     host_atom, a_attr_value)) {
-        EPHYR_LOG_ERROR("failed to get port attribute\n");
+    cookie = xcb_xv_get_port_attribute(conn, port_priv->port_number, host_atom);
+    reply = xcb_xv_get_port_attribute_reply(conn, cookie, &e);
+    if (e) {
+        EPHYR_LOG_ERROR ("XvGetPortAttribute() failed: %d \n", e->error_code);
+        free(e);
         res = BadMatch;
         goto out;
     }
+    *a_attr_value = reply->value;
+
+    free(reply);
 
     res = Success;
  out:
@@ -1130,6 +1150,9 @@ ephyrQueryImageAttributes(KdScreenInfo * a_info,
                           unsigned short *a_w,
                           unsigned short *a_h, int *a_pitches, int *a_offsets)
 {
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    xcb_xv_query_image_attributes_cookie_t cookie;
+    xcb_xv_query_image_attributes_reply_t *reply;
     int image_size = 0;
 
     EPHYR_RETURN_VAL_IF_FAIL(a_w && a_h, FALSE);
@@ -1137,13 +1160,25 @@ ephyrQueryImageAttributes(KdScreenInfo * a_info,
     EPHYR_LOG("enter: dim (%dx%d), pitches: %p, offsets: %p\n",
               *a_w, *a_h, a_pitches, a_offsets);
 
-    if (!ephyrHostXVQueryImageAttributes(s_base_port_id,
-                                         a_id,
-                                         a_w, a_h,
-                                         &image_size, a_pitches, a_offsets)) {
-        EPHYR_LOG_ERROR("EphyrHostXVQueryImageAttributes() failed\n");
+    cookie = xcb_xv_query_image_attributes(conn,
+                                           s_base_port_id, a_id,
+                                           *a_w, *a_h);
+    reply = xcb_xv_query_image_attributes_reply(conn, cookie, NULL);
+    if (!reply)
         goto out;
+
+    *a_w = reply->width;
+    *a_h = reply->height;
+    if (a_pitches && a_offsets) {
+        memcpy(a_pitches, xcb_xv_query_image_attributes_pitches(reply),
+               reply->num_planes << 2);
+        memcpy(a_offsets, xcb_xv_query_image_attributes_offsets(reply),
+               reply->num_planes << 2);
     }
+    image_size = reply->data_size;
+
+    free(reply);
+
     EPHYR_LOG("image size: %d, dim (%dx%d)\n", image_size, *a_w, *a_h);
 
  out:
commit 1342a93c49beb6e4924534304119d57fa587ad0f
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Aug 22 17:26:08 2013 -0700

    ephyr: Remove the host/server split for XV adaptors.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/ephyrhostvideo.c b/hw/kdrive/ephyr/ephyrhostvideo.c
index 5c3eb05..7665b25 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.c
+++ b/hw/kdrive/ephyr/ephyrhostvideo.c
@@ -43,75 +43,6 @@
 #define FALSE 0
 #endif /*FALSE*/
 
-Bool
-ephyrHostXVQueryAdaptors (xcb_xv_query_adaptors_reply_t **a_adaptors)
-{
-    Bool is_ok = FALSE;
-    xcb_connection_t *conn = hostx_get_xcbconn();
-    xcb_xv_query_adaptors_cookie_t cookie;
-    xcb_xv_query_adaptors_reply_t *reply = NULL;
-    xcb_generic_error_t *e = NULL;
-
-    EPHYR_RETURN_VAL_IF_FAIL(a_adaptors, FALSE);
-
-    EPHYR_LOG("enter\n");
-
-    cookie = xcb_xv_query_adaptors(conn,
-		    xcb_aux_get_screen(conn, hostx_get_screen())->root);
-    reply = xcb_xv_query_adaptors_reply(hostx_get_xcbconn(), cookie, &e);
-    if (e) {
-        EPHYR_LOG_ERROR ("failed to query host adaptors: %d\n", e->error_code);
-        goto out;
-    }
-    *a_adaptors = reply;
-    is_ok = TRUE;
-
-out:
-    EPHYR_LOG("leave\n");
-    free(e);
-    return is_ok;
-}
-
-xcb_xv_adaptor_info_t *
-ephyrHostXVAdaptorArrayAt(const xcb_xv_query_adaptors_reply_t *a_this,
-                          int a_index)
-{
-    int i;
-    xcb_xv_adaptor_info_iterator_t it;
-    EPHYR_RETURN_VAL_IF_FAIL(a_this, NULL);
-
-    it = xcb_xv_query_adaptors_info_iterator(a_this);
-    if (a_index >= a_this->num_adaptors)
-        return NULL;
-    for (i = 0; i < a_index; i++)
-        xcb_xv_adaptor_info_next(&it);
-
-    return it.data;
-}
-
-char
-ephyrHostXVAdaptorGetType(const xcb_xv_adaptor_info_t *a_this)
-{
-    EPHYR_RETURN_VAL_IF_FAIL(a_this, -1);
-    return a_this->type;
-}
-
-char *
-ephyrHostXVAdaptorGetName(const xcb_xv_adaptor_info_t *a_this)
-{
-    char *name;
-
-    EPHYR_RETURN_VAL_IF_FAIL(a_this, NULL);
-
-    name = malloc(a_this->name_size + 1);
-    if (!name)
-        return NULL;
-    memcpy(name, xcb_xv_adaptor_info_name(a_this), a_this->name_size);
-    name[a_this->name_size] = '\0';
-
-    return name;
-}
-
 EphyrHostVideoFormat*
 ephyrHostXVAdaptorGetVideoFormats (const xcb_xv_adaptor_info_t *a_this,
                                    int *a_nb_formats)
diff --git a/hw/kdrive/ephyr/ephyrhostvideo.h b/hw/kdrive/ephyr/ephyrhostvideo.h
index 40a12ac..7d2dbe2 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.h
+++ b/hw/kdrive/ephyr/ephyrhostvideo.h
@@ -28,7 +28,6 @@
 #ifndef __EPHYRHOSTVIDEO_H__
 #define __EPHYRHOSTVIDEO_H__
 
-typedef struct _EphyrHostXVAdaptorArray EphyrHostXVAdaptorArray;
 #include <xcb/xv.h>
 #include <X11/Xdefs.h>
 
@@ -83,18 +82,8 @@ typedef struct {
 } EphyrHostBox;
 
 /*
- * host adaptor array
- */
-Bool ephyrHostXVQueryAdaptors(xcb_xv_query_adaptors_reply_t **a_adaptors);
-xcb_xv_adaptor_info_t* ephyrHostXVAdaptorArrayAt(const xcb_xv_query_adaptors_reply_t *a_this,
-                                                 int a_index);
-
-/*
  * host adaptor
  */
-
-char ephyrHostXVAdaptorGetType(const xcb_xv_adaptor_info_t *a_this);
-char* ephyrHostXVAdaptorGetName(const xcb_xv_adaptor_info_t *a_this);
 EphyrHostVideoFormat *ephyrHostXVAdaptorGetVideoFormats
     (const xcb_xv_adaptor_info_t *a_this, int *a_nb_formats);
 
diff --git a/hw/kdrive/ephyr/ephyrvideo.c b/hw/kdrive/ephyr/ephyrvideo.c
index bf00694..be59886 100644
--- a/hw/kdrive/ephyr/ephyrvideo.c
+++ b/hw/kdrive/ephyr/ephyrvideo.c
@@ -31,6 +31,8 @@
 #endif
 #include <string.h>
 #include <X11/extensions/Xv.h>
+#include <xcb/xcb.h>
+#include <xcb/xcb_aux.h>
 #include "ephyrlog.h"
 #include "kdrive.h"
 #include "kxv.h"
@@ -381,7 +383,8 @@ portAttributesDup(const xcb_xv_query_port_attributes_reply_t *a_encodings)
 static Bool
 ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this)
 {
-    xcb_xv_adaptor_info_t *cur_host_adaptor = NULL;
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    xcb_screen_t *xscreen = xcb_aux_get_screen(conn, hostx_get_screen());
     EphyrHostVideoFormat *video_formats = NULL;
     EphyrHostEncoding *encodings = NULL;
     xcb_xv_query_port_attributes_reply_t *attributes = NULL;
@@ -390,14 +393,22 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this)
         num_formats = 0, i = 0, port_priv_offset = 0;
     unsigned num_encodings = 0;
     Bool is_ok = FALSE;
+    xcb_generic_error_t *e = NULL;
+    xcb_xv_adaptor_info_iterator_t it;
 
     EPHYR_RETURN_VAL_IF_FAIL(a_this, FALSE);
 
     EPHYR_LOG("enter\n");
 
-    if (!ephyrHostXVQueryAdaptors(&a_this->host_adaptors)) {
-        EPHYR_LOG_ERROR("failed to query host adaptors\n");
-        goto out;
+    {
+        xcb_xv_query_adaptors_cookie_t cookie =
+            xcb_xv_query_adaptors(conn, xscreen->root);
+        a_this->host_adaptors = xcb_xv_query_adaptors_reply(conn, cookie, &e);
+        if (e) {
+            free(e);
+            EPHYR_LOG_ERROR("failed to query host adaptors\n");
+            goto out;
+        }
     }
     if (a_this->host_adaptors)
         a_this->num_adaptors = a_this->host_adaptors->num_adaptors;
@@ -417,22 +428,24 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this)
             goto out;
         }
     }
+
+    it = xcb_xv_query_adaptors_info_iterator(a_this->host_adaptors);
     for (i = 0; i < a_this->num_adaptors; i++) {
+        xcb_xv_adaptor_info_t *cur_host_adaptor = it.data;
         int j = 0;
 
-        cur_host_adaptor = ephyrHostXVAdaptorArrayAt(a_this->host_adaptors, i);
-        if (!cur_host_adaptor)
-            continue;
         a_this->adaptors[i].nPorts = cur_host_adaptor->num_ports;
         if (a_this->adaptors[i].nPorts <= 0) {
             EPHYR_LOG_ERROR("Could not find any port of adaptor %d\n", i);
             continue;
         }
-        a_this->adaptors[i].type = ephyrHostXVAdaptorGetType(cur_host_adaptor);
+        a_this->adaptors[i].type = cur_host_adaptor->type;
         a_this->adaptors[i].type |= XvWindowMask;
         a_this->adaptors[i].flags =
             VIDEO_OVERLAID_IMAGES | VIDEO_CLIP_TO_VIEWPORT;
-        a_this->adaptors[i].name = ephyrHostXVAdaptorGetName(cur_host_adaptor);
+        a_this->adaptors[i].name =
+            strndup(xcb_xv_adaptor_info_name(cur_host_adaptor),
+                    cur_host_adaptor->name_size);
         if (!a_this->adaptors[i].name)
             a_this->adaptors[i].name = strdup("Xephyr Video Overlay");
         base_port_id = cur_host_adaptor->base_id;
@@ -494,6 +507,8 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this)
         }
         a_this->adaptors[i].pImages = (KdImagePtr) image_formats;
         a_this->adaptors[i].nImages = num_formats;
+
+        xcb_xv_adaptor_info_next(&it);
     }
     is_ok = TRUE;
 
@@ -514,13 +529,16 @@ static Bool
 ephyrXVPrivSetAdaptorsHooks(EphyrXVPriv * a_this)
 {
     int i = 0;
-    xcb_xv_adaptor_info_t *cur_host_adaptor = NULL;
+    xcb_xv_adaptor_info_iterator_t it;
 
     EPHYR_RETURN_VAL_IF_FAIL(a_this, FALSE);
 
     EPHYR_LOG("enter\n");
 
+    it = xcb_xv_query_adaptors_info_iterator(a_this->host_adaptors);
     for (i = 0; i < a_this->num_adaptors; i++) {
+        xcb_xv_adaptor_info_t *cur_host_adaptor = it.data;
+
         a_this->adaptors[i].ReputImage = ephyrReputImage;
         a_this->adaptors[i].StopVideo = ephyrStopVideo;
         a_this->adaptors[i].SetPortAttribute = ephyrSetPortAttribute;
@@ -528,12 +546,6 @@ ephyrXVPrivSetAdaptorsHooks(EphyrXVPriv * a_this)
         a_this->adaptors[i].QueryBestSize = ephyrQueryBestSize;
         a_this->adaptors[i].QueryImageAttributes = ephyrQueryImageAttributes;
 
-        cur_host_adaptor = ephyrHostXVAdaptorArrayAt(a_this->host_adaptors, i);
-        if (!cur_host_adaptor) {
-            EPHYR_LOG_ERROR("failed to get host adaptor at index %d\n", i);
-            continue;
-        }
-
         if (adaptor_has_flags(cur_host_adaptor,
                               XCB_XV_TYPE_IMAGE_MASK | XCB_XV_TYPE_INPUT_MASK))
             a_this->adaptors[i].PutImage = ephyrPutImage;
commit fad79d2e3e53de4f25b3d1dd7accb558464a4a46
Author: Eric Anholt <eric at anholt.net>
Date:   Sun Aug 18 20:08:32 2013 +0200

    ephyr: Refactor XV adaptor feature detection.
    
    This obviously wanted a helper function beforehand, but even more so
    now that we have XCB.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/ephyrhostvideo.c b/hw/kdrive/ephyr/ephyrhostvideo.c
index 9a5a3ba..5c3eb05 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.c
+++ b/hw/kdrive/ephyr/ephyrhostvideo.c
@@ -138,74 +138,6 @@ ephyrHostXVAdaptorGetVideoFormats (const xcb_xv_adaptor_info_t *a_this,
 }
 
 Bool
-ephyrHostXVAdaptorHasPutVideo (const xcb_xv_adaptor_info_t *a_this,
-                               Bool *a_result)
-{
-    EPHYR_RETURN_VAL_IF_FAIL(a_this && a_result, FALSE);
-
-    if ((a_this->type & (XCB_XV_TYPE_VIDEO_MASK | XCB_XV_TYPE_INPUT_MASK)) ==
-        (XCB_XV_TYPE_VIDEO_MASK | XCB_XV_TYPE_INPUT_MASK))
-        *a_result = TRUE;
-    else
-        *a_result = FALSE;
-    return TRUE;
-}
-
-Bool
-ephyrHostXVAdaptorHasGetVideo(const xcb_xv_adaptor_info_t *a_this,
-                              Bool *a_result)
-{
-    if ((a_this->type & (XCB_XV_TYPE_VIDEO_MASK | XCB_XV_TYPE_OUTPUT_MASK)) ==
-        (XCB_XV_TYPE_VIDEO_MASK | XCB_XV_TYPE_OUTPUT_MASK))
-        *a_result = TRUE;
-    else
-        *a_result = FALSE;
-    return TRUE;
-}
-
-Bool
-ephyrHostXVAdaptorHasPutStill(const xcb_xv_adaptor_info_t *a_this,
-                              Bool *a_result)
-{
-    EPHYR_RETURN_VAL_IF_FAIL(a_this && a_result, FALSE);
-
-    if ((a_this->type & (XCB_XV_TYPE_STILL_MASK | XCB_XV_TYPE_INPUT_MASK)) ==
-        (XCB_XV_TYPE_STILL_MASK | XCB_XV_TYPE_INPUT_MASK))
-        *a_result = TRUE;
-    else
-        *a_result = FALSE;
-    return TRUE;
-}
-
-Bool
-ephyrHostXVAdaptorHasGetStill(const xcb_xv_adaptor_info_t *a_this,
-                              Bool *a_result)
-{
-    EPHYR_RETURN_VAL_IF_FAIL(a_this && a_result, FALSE);
-
-    if ((a_this->type & (XCB_XV_TYPE_STILL_MASK | XCB_XV_TYPE_OUTPUT_MASK)) ==
-        (XCB_XV_TYPE_STILL_MASK | XCB_XV_TYPE_OUTPUT_MASK))
-        *a_result = TRUE;
-    else
-        *a_result = FALSE;
-    return TRUE;
-}
-
-Bool
-ephyrHostXVAdaptorHasPutImage(const xcb_xv_adaptor_info_t *a_this,
-                              Bool *a_result)
-{
-    EPHYR_RETURN_VAL_IF_FAIL(a_this && a_result, FALSE);
-
-    if ((a_this->type & (XCB_XV_TYPE_IMAGE_MASK | XCB_XV_TYPE_INPUT_MASK)) ==
-        (XCB_XV_TYPE_IMAGE_MASK | XCB_XV_TYPE_INPUT_MASK))
-        *a_result = TRUE;
-    else
-        *a_result = FALSE;
-    return TRUE;
-}
-
-Bool
 ephyrHostXVQueryEncodings(int a_port_id,
                           EphyrHostEncoding ** a_encodings,
                           unsigned int *a_num_encodings)
diff --git a/hw/kdrive/ephyr/ephyrhostvideo.h b/hw/kdrive/ephyr/ephyrhostvideo.h
index 56a7359..40a12ac 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.h
+++ b/hw/kdrive/ephyr/ephyrhostvideo.h
@@ -98,17 +98,6 @@ char* ephyrHostXVAdaptorGetName(const xcb_xv_adaptor_info_t *a_this);
 EphyrHostVideoFormat *ephyrHostXVAdaptorGetVideoFormats
     (const xcb_xv_adaptor_info_t *a_this, int *a_nb_formats);
 
-Bool ephyrHostXVAdaptorHasPutVideo(const xcb_xv_adaptor_info_t *a_this,
-                                   Bool *a_result);
-Bool ephyrHostXVAdaptorHasGetVideo(const xcb_xv_adaptor_info_t *a_this,
-                                   Bool *a_result);
-Bool ephyrHostXVAdaptorHasPutStill(const xcb_xv_adaptor_info_t *a_this,
-                                   Bool *a_result);
-Bool ephyrHostXVAdaptorHasGetStill(const xcb_xv_adaptor_info_t *a_this,
-                                   Bool *a_result);
-Bool ephyrHostXVAdaptorHasPutImage(const xcb_xv_adaptor_info_t *a_this,
-                                   Bool *a_result);
-
 /*
  * encoding
  */
diff --git a/hw/kdrive/ephyr/ephyrvideo.c b/hw/kdrive/ephyr/ephyrvideo.c
index 7d249d2..bf00694 100644
--- a/hw/kdrive/ephyr/ephyrvideo.c
+++ b/hw/kdrive/ephyr/ephyrvideo.c
@@ -170,6 +170,12 @@ static int s_base_port_id;
  * ************/
 
 static Bool
+adaptor_has_flags(const xcb_xv_adaptor_info_t *adaptor, uint32_t flags)
+{
+    return (adaptor->type & flags) == flags;
+}
+
+static Bool
 DoSimpleClip(BoxPtr a_dst_box, BoxPtr a_clipper, BoxPtr a_result)
 {
     BoxRec dstClippedBox;
@@ -508,7 +514,6 @@ static Bool
 ephyrXVPrivSetAdaptorsHooks(EphyrXVPriv * a_this)
 {
     int i = 0;
-    Bool has_it = FALSE;
     xcb_xv_adaptor_info_t *cur_host_adaptor = NULL;
 
     EPHYR_RETURN_VAL_IF_FAIL(a_this, FALSE);
@@ -528,45 +533,26 @@ ephyrXVPrivSetAdaptorsHooks(EphyrXVPriv * a_this)
             EPHYR_LOG_ERROR("failed to get host adaptor at index %d\n", i);
             continue;
         }
-        has_it = FALSE;
-        if (!ephyrHostXVAdaptorHasPutImage(cur_host_adaptor, &has_it)) {
-            EPHYR_LOG_ERROR("error\n");
-        }
-        if (has_it) {
+
+        if (adaptor_has_flags(cur_host_adaptor,
+                              XCB_XV_TYPE_IMAGE_MASK | XCB_XV_TYPE_INPUT_MASK))
             a_this->adaptors[i].PutImage = ephyrPutImage;
-        }
 
-        has_it = FALSE;
-        if (!ephyrHostXVAdaptorHasPutVideo(cur_host_adaptor, &has_it)) {
-            EPHYR_LOG_ERROR("error\n");
-        }
-        if (has_it) {
+        if (adaptor_has_flags(cur_host_adaptor,
+                              XCB_XV_TYPE_VIDEO_MASK | XCB_XV_TYPE_INPUT_MASK))
             a_this->adaptors[i].PutVideo = ephyrPutVideo;
-        }
 
-        has_it = FALSE;
-        if (!ephyrHostXVAdaptorHasGetVideo(cur_host_adaptor, &has_it)) {
-            EPHYR_LOG_ERROR("error\n");
-        }
-        if (has_it) {
+        if (adaptor_has_flags(cur_host_adaptor,
+                              XCB_XV_TYPE_VIDEO_MASK | XCB_XV_TYPE_OUTPUT_MASK))
             a_this->adaptors[i].GetVideo = ephyrGetVideo;
-        }
 
-        has_it = FALSE;
-        if (!ephyrHostXVAdaptorHasPutStill(cur_host_adaptor, &has_it)) {
-            EPHYR_LOG_ERROR("error\n");
-        }
-        if (has_it) {
+        if (adaptor_has_flags(cur_host_adaptor,
+                              XCB_XV_TYPE_STILL_MASK | XCB_XV_TYPE_INPUT_MASK))
             a_this->adaptors[i].PutStill = ephyrPutStill;
-        }
 
-        has_it = FALSE;
-        if (!ephyrHostXVAdaptorHasGetStill(cur_host_adaptor, &has_it)) {
-            EPHYR_LOG_ERROR("error\n");
-        }
-        if (has_it) {
+        if (adaptor_has_flags(cur_host_adaptor,
+                              XCB_XV_TYPE_STILL_MASK | XCB_XV_TYPE_OUTPUT_MASK))
             a_this->adaptors[i].GetStill = ephyrGetStill;
-        }
     }
     EPHYR_LOG("leave\n");
     return TRUE;
commit 7a9c311add62026972419ef0b04a55680072bfeb
Author: Eric Anholt <eric at anholt.net>
Date:   Sun Aug 18 20:02:53 2013 +0200

    ephyr: Remove some pointless indirection in the XV code.
    
    Now that we have XCB on the server side, we don't need to split these
    functions out.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/ephyrhostvideo.c b/hw/kdrive/ephyr/ephyrhostvideo.c
index ea5fc9b..9a5a3ba 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.c
+++ b/hw/kdrive/ephyr/ephyrhostvideo.c
@@ -43,12 +43,6 @@
 #define FALSE 0
 #endif /*FALSE*/
 
-
-void
-ephyrHostXVInit(void)
-{
-}
-
 Bool
 ephyrHostXVQueryAdaptors (xcb_xv_query_adaptors_reply_t **a_adaptors)
 {
@@ -78,19 +72,6 @@ out:
     return is_ok;
 }
 
-void
-ephyrHostXVAdaptorArrayDelete (xcb_xv_query_adaptors_reply_t *a_adaptors)
-{
-    free (a_adaptors);
-}
-
-int
-ephyrHostXVAdaptorArrayGetSize (const xcb_xv_query_adaptors_reply_t *a_this)
-{
-    EPHYR_RETURN_VAL_IF_FAIL(a_this, -1);
-    return a_this->num_adaptors;
-}
-
 xcb_xv_adaptor_info_t *
 ephyrHostXVAdaptorArrayAt(const xcb_xv_query_adaptors_reply_t *a_this,
                           int a_index)
@@ -156,20 +137,6 @@ ephyrHostXVAdaptorGetVideoFormats (const xcb_xv_adaptor_info_t *a_this,
     return formats;
 }
 
-int
-ephyrHostXVAdaptorGetNbPorts(const xcb_xv_adaptor_info_t *a_this)
-{
-    EPHYR_RETURN_VAL_IF_FAIL(a_this, -1);
-
-    return a_this->num_ports;
-}
-
-int
-ephyrHostXVAdaptorGetFirstPortID (const xcb_xv_adaptor_info_t *a_this)
-{
-    return a_this->base_id;
-}
-
 Bool
 ephyrHostXVAdaptorHasPutVideo (const xcb_xv_adaptor_info_t *a_this,
                                Bool *a_result)
@@ -538,12 +505,6 @@ ephyrHostGetAtomName(int a_atom)
     return ret;
 }
 
-void
-ephyrHostFree(void *a_pointer)
-{
-    free(a_pointer);
-}
-
 Bool
 ephyrHostXVPutImage(int a_screen_num,
                     int a_port_id,
@@ -732,18 +693,3 @@ ephyrHostXVGetStill(int a_screen_num, int a_port_id,
 
     return TRUE;
 }
-
-Bool
-ephyrHostXVStopVideo(int a_screen_num, int a_port_id)
-{
-    xcb_connection_t *conn = hostx_get_xcbconn();
-
-    EPHYR_RETURN_VAL_IF_FAIL(conn, FALSE);
-
-    EPHYR_LOG("enter\n");
-
-    xcb_xv_stop_video(conn, a_port_id, hostx_get_window (a_screen_num));
-
-    EPHYR_LOG("leave\n");
-    return TRUE;
-}
diff --git a/hw/kdrive/ephyr/ephyrhostvideo.h b/hw/kdrive/ephyr/ephyrhostvideo.h
index b946add..56a7359 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.h
+++ b/hw/kdrive/ephyr/ephyrhostvideo.h
@@ -82,16 +82,10 @@ typedef struct {
     unsigned short x1, y1, x2, y2;
 } EphyrHostBox;
 
-void ephyrHostXVInit(void);
-
-void ephyrHostFree(void *a_pointer);
-
 /*
  * host adaptor array
  */
 Bool ephyrHostXVQueryAdaptors(xcb_xv_query_adaptors_reply_t **a_adaptors);
-void ephyrHostXVAdaptorArrayDelete(xcb_xv_query_adaptors_reply_t *a_adaptors);
-int ephyrHostXVAdaptorArrayGetSize(const xcb_xv_query_adaptors_reply_t *a_this);
 xcb_xv_adaptor_info_t* ephyrHostXVAdaptorArrayAt(const xcb_xv_query_adaptors_reply_t *a_this,
                                                  int a_index);
 
@@ -103,8 +97,6 @@ char ephyrHostXVAdaptorGetType(const xcb_xv_adaptor_info_t *a_this);
 char* ephyrHostXVAdaptorGetName(const xcb_xv_adaptor_info_t *a_this);
 EphyrHostVideoFormat *ephyrHostXVAdaptorGetVideoFormats
     (const xcb_xv_adaptor_info_t *a_this, int *a_nb_formats);
-int ephyrHostXVAdaptorGetNbPorts(const xcb_xv_adaptor_info_t *a_this);
-int ephyrHostXVAdaptorGetFirstPortID(const xcb_xv_adaptor_info_t *a_this);
 
 Bool ephyrHostXVAdaptorHasPutVideo(const xcb_xv_adaptor_info_t *a_this,
                                    Bool *a_result);
@@ -216,9 +208,4 @@ Bool ephyrHostXVGetStill(int a_screen_num,
                          int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h,
                          int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h);
 
-/*
- * StopVideo
- */
-Bool ephyrHostXVStopVideo(int a_screen_num, int a_port_id);
-
 #endif /*__EPHYRHOSTVIDEO_H__*/
diff --git a/hw/kdrive/ephyr/ephyrvideo.c b/hw/kdrive/ephyr/ephyrvideo.c
index 5813634..7d249d2 100644
--- a/hw/kdrive/ephyr/ephyrvideo.c
+++ b/hw/kdrive/ephyr/ephyrvideo.c
@@ -287,8 +287,6 @@ ephyrXVPrivNew(void)
         goto error;
     }
 
-    ephyrHostXVInit();
-
     if (!ephyrXVPrivQueryHostAdaptors(xv_priv)) {
         EPHYR_LOG_ERROR("failed to query the host x for xv properties\n");
         goto error;
@@ -317,7 +315,7 @@ ephyrXVPrivDelete(EphyrXVPriv * a_this)
     if (!a_this)
         return;
     if (a_this->host_adaptors) {
-        ephyrHostXVAdaptorArrayDelete(a_this->host_adaptors);
+        free(a_this->host_adaptors);
         a_this->host_adaptors = NULL;
     }
     free(a_this->adaptors);
@@ -396,8 +394,7 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this)
         goto out;
     }
     if (a_this->host_adaptors)
-        a_this->num_adaptors =
-            ephyrHostXVAdaptorArrayGetSize(a_this->host_adaptors);
+        a_this->num_adaptors = a_this->host_adaptors->num_adaptors;
     if (a_this->num_adaptors < 0) {
         EPHYR_LOG_ERROR("failed to get number of host adaptors\n");
         goto out;
@@ -420,8 +417,7 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this)
         cur_host_adaptor = ephyrHostXVAdaptorArrayAt(a_this->host_adaptors, i);
         if (!cur_host_adaptor)
             continue;
-        a_this->adaptors[i].nPorts =
-            ephyrHostXVAdaptorGetNbPorts(cur_host_adaptor);
+        a_this->adaptors[i].nPorts = cur_host_adaptor->num_ports;
         if (a_this->adaptors[i].nPorts <= 0) {
             EPHYR_LOG_ERROR("Could not find any port of adaptor %d\n", i);
             continue;
@@ -433,7 +429,7 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this)
         a_this->adaptors[i].name = ephyrHostXVAdaptorGetName(cur_host_adaptor);
         if (!a_this->adaptors[i].name)
             a_this->adaptors[i].name = strdup("Xephyr Video Overlay");
-        base_port_id = ephyrHostXVAdaptorGetFirstPortID(cur_host_adaptor);
+        base_port_id = cur_host_adaptor->base_id;
         if (base_port_id < 0) {
             EPHYR_LOG_ERROR("failed to get port id for adaptor %d\n", i);
             continue;
@@ -455,10 +451,6 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this)
                                               &num_video_formats);
         a_this->adaptors[i].pFormats = (KdVideoFormatPtr) video_formats;
         a_this->adaptors[i].nFormats = num_video_formats;
-        /* got a_this->adaptors[i].nPorts already
-           a_this->adaptors[i].nPorts =
-           ephyrHostXVAdaptorGetNbPorts (cur_host_adaptor) ;
-         */
         a_this->adaptors[i].pPortPrivates =
             calloc(a_this->adaptors[i].nPorts,
                    sizeof(DevUnion) + sizeof(EphyrPortPriv));
@@ -710,15 +702,14 @@ ephyrXVPrivSaveImageToPortPriv(EphyrPortPriv * a_port_priv,
 static void
 ephyrStopVideo(KdScreenInfo * a_info, pointer a_port_priv, Bool a_exit)
 {
+    xcb_connection_t *conn = hostx_get_xcbconn();
     EphyrPortPriv *port_priv = a_port_priv;
+    EphyrScrPriv *scrpriv = a_info->driver;
 
-    EPHYR_RETURN_IF_FAIL(a_info && a_info->pScreen);
     EPHYR_RETURN_IF_FAIL(port_priv);
 
     EPHYR_LOG("enter\n");
-    if (!ephyrHostXVStopVideo(a_info->pScreen->myNum, port_priv->port_number)) {
-        EPHYR_LOG_ERROR("XvStopVideo() failed\n");
-    }
+    xcb_xv_stop_video(conn, port_priv->port_number, scrpriv->win);
     EPHYR_LOG("leave\n");
 }
 
commit 46cf6bf5692ef751ec9d17ae2292565d4b13f14b
Author: Eric Anholt <eric at anholt.net>
Date:   Sun Aug 18 18:38:29 2013 +0200

    ephyr: Move event processing into ephyr.c.
    
    No more extra event structure to translate between hostx.c and
    ephyr.c!
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index 089c0e2..932327d 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -27,6 +27,9 @@
 #include <kdrive-config.h>
 #endif
 
+#include <xcb/xcb_keysyms.h>
+#include <X11/keysym.h>
+
 #include "ephyr.h"
 
 #include "inputstr.h"
@@ -799,13 +802,13 @@ ephyrCrossScreen(ScreenPtr pScreen, Bool entering)
 {
 }
 
-int ephyrCurScreen;             /*current event screen */
+ScreenPtr ephyrCursorScreen; /* screen containing the cursor */
 
 static void
 ephyrWarpCursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y)
 {
     OsBlockSIGIO();
-    ephyrCurScreen = pScreen->myNum;
+    ephyrCursorScreen = pScreen;
     miPointerWarpCursor(inputInfo.pointer, pScreen, x, y);
 
     OsReleaseSIGIO();
@@ -853,123 +856,324 @@ ephyrExposePairedWindow(int a_remote)
 }
 #endif                          /* XF86DRI */
 
-void
-ephyrPoll(void)
+static KdScreenInfo *
+screen_from_window(Window w)
 {
-    EphyrHostXEvent ev;
-
-    while (hostx_get_event(&ev)) {
-        switch (ev.type) {
-        case EPHYR_EV_MOUSE_MOTION:
-            if (!ephyrMouse ||
-                !((EphyrPointerPrivate *) ephyrMouse->driverPrivate)->enabled) {
-                EPHYR_LOG("skipping mouse motion:%d\n", ephyrCurScreen);
-                continue;
-            }
-            {
-                if (ev.data.mouse_motion.screen >= 0
-                    && (ephyrCurScreen != ev.data.mouse_motion.screen)) {
-                    EPHYR_LOG("warping mouse cursor. "
-                              "cur_screen%d, motion_screen:%d\n",
-                              ephyrCurScreen, ev.data.mouse_motion.screen);
-                    if (ev.data.mouse_motion.screen >= 0) {
-                        ephyrWarpCursor
-                            (inputInfo.pointer,
-                             screenInfo.screens[ev.data.mouse_motion.screen],
-                             ev.data.mouse_motion.x, ev.data.mouse_motion.y);
-                    }
-                }
-                else {
-                    int x = 0, y = 0;
+    int i = 0;
+
+    for (i = 0; i < screenInfo.numScreens; i++) {
+        ScreenPtr pScreen = screenInfo.screens[i];
+        KdPrivScreenPtr kdscrpriv = KdGetScreenPriv(pScreen);
+        KdScreenInfo *screen = kdscrpriv->screen;
+        EphyrScrPriv *scrpriv = screen->driver;
+
+        if (scrpriv->win == w
+            || scrpriv->peer_win == w
+            || scrpriv->win_pre_existing == w) {
+            return screen;
+        }
+    }
+
+    return NULL;
+}
+
+static void
+ephyrProcessErrorEvent(xcb_generic_event_t *xev)
+{
+    xcb_generic_error_t *e = (xcb_generic_error_t *)xev;
+
+    FatalError("X11 error\n"
+               "Error code: %hhu\n"
+               "Sequence number: %hu\n"
+               "Major code: %hhu\tMinor code: %hu\n"
+               "Error value: %u\n",
+               e->error_code,
+               e->sequence,
+               e->major_code, e->minor_code,
+               e->resource_id);
+}
+
+static void
+ephyrProcessExpose(xcb_generic_event_t *xev)
+{
+    xcb_expose_event_t *expose = (xcb_expose_event_t *)xev;
+    KdScreenInfo *screen = screen_from_window(expose->window);
+    EphyrScrPriv *scrpriv = screen->driver;
 
+    /* Wait for the last expose event in a series of cliprects
+     * to actually paint our screen.
+     */
+    if (expose->count != 0)
+        return;
+
+    if (scrpriv) {
+        hostx_paint_rect(scrpriv->screen, 0, 0, 0, 0,
+                         scrpriv->win_width,
+                         scrpriv->win_height);
+    } else {
+        EPHYR_LOG_ERROR("failed to get host screen\n");
 #ifdef XF86DRI
-                    EphyrWindowPair *pair = NULL;
+        /*
+         * We only receive expose events when the expose event
+         * have be generated for a drawable that is a host X
+         * window managed by Xephyr. Host X windows managed by
+         * Xephyr exists for instance when Xephyr is asked to
+         * create a GL drawable in a DRI environment.
+         */
+        ephyrExposePairedWindow(expose->window);
+#endif                          /* XF86DRI */
+    }
+}
+
+static void
+ephyrProcessMouseMotion(xcb_generic_event_t *xev)
+{
+    xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *)xev;
+    KdScreenInfo *screen = screen_from_window(motion->event);
+
+    if (!ephyrMouse ||
+        !((EphyrPointerPrivate *) ephyrMouse->driverPrivate)->enabled) {
+        EPHYR_LOG("skipping mouse motion:%d\n", screen->pScreen->myNum);
+        return;
+    }
+
+    if (ephyrCursorScreen != screen->pScreen) {
+        EPHYR_LOG("warping mouse cursor. "
+                  "cur_screen%d, motion_screen:%d\n",
+                  ephyrCursorScreen, screen->pScreen->myNum);
+        ephyrWarpCursor(inputInfo.pointer, screen->pScreen,
+                        motion->event_x, motion->event_y);
+    }
+    else {
+        int x = 0, y = 0;
+
+#ifdef XF86DRI
+        EphyrWindowPair *pair = NULL;
 #endif
-                    EPHYR_LOG("enqueuing mouse motion:%d\n", ephyrCurScreen);
-                    x = ev.data.mouse_motion.x;
-                    y = ev.data.mouse_motion.y;
-                    EPHYR_LOG("initial (x,y):(%d,%d)\n", x, y);
+        EPHYR_LOG("enqueuing mouse motion:%d\n", ephyrCurScreen);
+        x = motion->event_x;
+        y = motion->event_y;
+        EPHYR_LOG("initial (x,y):(%d,%d)\n", x, y);
 #ifdef XF86DRI
-                    EPHYR_LOG("is this window peered by a gl drawable ?\n");
-                    if (findWindowPairFromRemote(ev.data.mouse_motion.window,
-                                                 &pair)) {
-                        EPHYR_LOG("yes, it is peered\n");
-                        x += pair->local->drawable.x;
-                        y += pair->local->drawable.y;
-                    }
-                    else {
-                        EPHYR_LOG("no, it is not peered\n");
-                    }
-                    EPHYR_LOG("final (x,y):(%d,%d)\n", x, y);
+        EPHYR_LOG("is this window peered by a gl drawable ?\n");
+        if (findWindowPairFromRemote(motion->event, &pair)) {
+            EPHYR_LOG("yes, it is peered\n");
+            x += pair->local->drawable.x;
+            y += pair->local->drawable.y;
+        }
+        else {
+            EPHYR_LOG("no, it is not peered\n");
+        }
+        EPHYR_LOG("final (x,y):(%d,%d)\n", x, y);
 #endif
-                    KdEnqueuePointerEvent(ephyrMouse, mouseState, x, y, 0);
+        KdEnqueuePointerEvent(ephyrMouse, mouseState, x, y, 0);
+    }
+}
+
+static void
+ephyrProcessButtonPress(xcb_generic_event_t *xev)
+{
+    xcb_button_press_event_t *button = (xcb_button_press_event_t *)xev;
+
+    if (!ephyrMouse ||
+        !((EphyrPointerPrivate *) ephyrMouse->driverPrivate)->enabled) {
+        EPHYR_LOG("skipping mouse press:%d\n", ephyrCurScreen);
+        return;
+    }
+
+    ephyrUpdateModifierState(button->state);
+    /* This is a bit hacky. will break for button 5 ( defined as 0x10 )
+     * Check KD_BUTTON defines in kdrive.h
+     */
+    mouseState |= 1 << (button->detail - 1);
+
+    EPHYR_LOG("enqueuing mouse press:%d\n", ephyrCurScreen);
+    KdEnqueuePointerEvent(ephyrMouse, mouseState | KD_MOUSE_DELTA, 0, 0, 0);
+}
+
+static void
+ephyrProcessButtonRelease(xcb_generic_event_t *xev)
+{
+    xcb_button_press_event_t *button = (xcb_button_press_event_t *)xev;
+
+    if (!ephyrMouse ||
+        !((EphyrPointerPrivate *) ephyrMouse->driverPrivate)->enabled) {
+        return;
+    }
+
+    ephyrUpdateModifierState(button->state);
+    mouseState &= ~(1 << (button->detail - 1));
+
+    EPHYR_LOG("enqueuing mouse release:%d\n", ephyrCurScreen);
+    KdEnqueuePointerEvent(ephyrMouse, mouseState | KD_MOUSE_DELTA, 0, 0, 0);
+}
+
+static void
+ephyrProcessKeyPress(xcb_generic_event_t *xev)
+{
+    xcb_key_press_event_t *key = (xcb_key_press_event_t *)xev;
+
+    if (!ephyrKbd ||
+        !((EphyrKbdPrivate *) ephyrKbd->driverPrivate)->enabled) {
+        return;
+    }
+
+    ephyrUpdateModifierState(key->state);
+    KdEnqueueKeyboardEvent(ephyrKbd, key->detail, FALSE);
+}
+
+static void
+ephyrProcessKeyRelease(xcb_generic_event_t *xev)
+{
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    xcb_key_release_event_t *key = (xcb_key_release_event_t *)xev;
+    static xcb_key_symbols_t *keysyms;
+    static int grabbed_screen = -1;
+
+    if (!keysyms)
+        keysyms = xcb_key_symbols_alloc(conn);
+
+    if ((xcb_key_symbols_get_keysym(keysyms, key->detail, 0) == XK_Shift_L
+         || xcb_key_symbols_get_keysym(keysyms, key->detail, 0) == XK_Shift_R)
+        && (key->state & XCB_MOD_MASK_CONTROL)) {
+        KdScreenInfo *screen = screen_from_window(key->event);
+        EphyrScrPriv *scrpriv = screen->driver;
+
+        if (grabbed_screen != -1) {
+            xcb_ungrab_keyboard(conn, XCB_TIME_CURRENT_TIME);
+            xcb_ungrab_pointer(conn, XCB_TIME_CURRENT_TIME);
+            grabbed_screen = -1;
+            hostx_set_win_title(screen,
+                                "(ctrl+shift grabs mouse and keyboard)");
+        }
+        else {
+            /* Attempt grab */
+            xcb_grab_keyboard_cookie_t kbgrabc =
+                xcb_grab_keyboard(conn,
+                                  TRUE,
+                                  scrpriv->win,
+                                  XCB_TIME_CURRENT_TIME,
+                                  XCB_GRAB_MODE_ASYNC,
+                                  XCB_GRAB_MODE_ASYNC);
+            xcb_grab_keyboard_reply_t *kbgrabr;
+            xcb_grab_pointer_cookie_t pgrabc =
+                xcb_grab_pointer(conn,
+                                 TRUE,
+                                 scrpriv->win,
+                                 0,
+                                 XCB_GRAB_MODE_ASYNC,
+                                 XCB_GRAB_MODE_ASYNC,
+                                 scrpriv->win,
+                                 XCB_NONE,
+                                 XCB_TIME_CURRENT_TIME);
+            xcb_grab_pointer_reply_t *pgrabr;
+            kbgrabr = xcb_grab_keyboard_reply(conn, kbgrabc, NULL);
+            if (!kbgrabr || kbgrabr->status != XCB_GRAB_STATUS_SUCCESS) {
+                xcb_discard_reply(conn, pgrabc.sequence);
+                xcb_ungrab_pointer(conn, XCB_TIME_CURRENT_TIME);
+            } else {
+                pgrabr = xcb_grab_pointer_reply(conn, pgrabc, NULL);
+                if (!pgrabr || pgrabr->status != XCB_GRAB_STATUS_SUCCESS)
+                    {
+                        xcb_ungrab_keyboard(conn,
+                                            XCB_TIME_CURRENT_TIME);
+                    } else {
+                    grabbed_screen = scrpriv->mynum;
+                    hostx_set_win_title
+                        (screen,
+                         "(ctrl+shift releases mouse and keyboard)");
                 }
             }
-            break;
+        }
+    }
+
+    if (!ephyrKbd ||
+        !((EphyrKbdPrivate *) ephyrKbd->driverPrivate)->enabled) {
+        return;
+    }
+
+    /* Still send the release event even if above has happened server
+     * will get confused with just an up event.  Maybe it would be
+     * better to just block shift+ctrls getting to kdrive all
+     * together.
+     */
+    ephyrUpdateModifierState(key->state);
+    KdEnqueueKeyboardEvent(ephyrKbd, key->detail, TRUE);
+}
+
+static void
+ephyrProcessConfigureNotify(xcb_generic_event_t *xev)
+{
+    xcb_configure_notify_event_t *configure =
+        (xcb_configure_notify_event_t *)xev;
+    KdScreenInfo *screen = screen_from_window(configure->window);
+    EphyrScrPriv *scrpriv = screen->driver;
+
+    if (!scrpriv ||
+        (scrpriv->win_pre_existing == None && !EphyrWantResize)) {
+        return;
+    }
+
+#ifdef RANDR
+    ephyrResizeScreen(screen->pScreen, configure->width, configure->height);
+#endif /* RANDR */
+}
+
+void
+ephyrPoll(void)
+{
+    xcb_connection_t *conn = hostx_get_xcbconn();
 
-        case EPHYR_EV_MOUSE_PRESS:
-            if (!ephyrMouse ||
-                !((EphyrPointerPrivate *) ephyrMouse->driverPrivate)->enabled) {
-                EPHYR_LOG("skipping mouse press:%d\n", ephyrCurScreen);
-                continue;
+    while (TRUE) {
+        xcb_generic_event_t *xev = xcb_poll_for_event(conn);
+        if (!xev) {
+            /* If our XCB connection has died (for example, our window was
+             * closed), exit now.
+             */
+            if (xcb_connection_has_error(conn)) {
+                CloseWellKnownConnections();
+                OsCleanup(1);
+                exit(1);
             }
-            EPHYR_LOG("enqueuing mouse press:%d\n", ephyrCurScreen);
-            ephyrUpdateModifierState(ev.key_state);
-            mouseState |= ev.data.mouse_down.button_num;
-            KdEnqueuePointerEvent(ephyrMouse, mouseState | KD_MOUSE_DELTA, 0, 0,
-                                  0);
+
             break;
+        }
 
-        case EPHYR_EV_MOUSE_RELEASE:
-            if (!ephyrMouse ||
-                !((EphyrPointerPrivate *) ephyrMouse->driverPrivate)->enabled)
-                continue;
-            ephyrUpdateModifierState(ev.key_state);
-            mouseState &= ~ev.data.mouse_up.button_num;
-            EPHYR_LOG("enqueuing mouse release:%d\n", ephyrCurScreen);
-            KdEnqueuePointerEvent(ephyrMouse, mouseState | KD_MOUSE_DELTA, 0, 0,
-                                  0);
+        switch (xev->response_type & 0x7f) {
+        case 0:
+            ephyrProcessErrorEvent(xev);
             break;
 
-        case EPHYR_EV_KEY_PRESS:
-            if (!ephyrKbd ||
-                !((EphyrKbdPrivate *) ephyrKbd->driverPrivate)->enabled)
-                continue;
-            ephyrUpdateModifierState(ev.key_state);
-            KdEnqueueKeyboardEvent(ephyrKbd, ev.data.key_down.scancode, FALSE);
+        case XCB_EXPOSE:
+            ephyrProcessExpose(xev);
             break;
 
-        case EPHYR_EV_KEY_RELEASE:
-            if (!ephyrKbd ||
-                !((EphyrKbdPrivate *) ephyrKbd->driverPrivate)->enabled)
-                continue;
-            ephyrUpdateModifierState(ev.key_state);
-            KdEnqueueKeyboardEvent(ephyrKbd, ev.data.key_up.scancode, TRUE);
+        case XCB_MOTION_NOTIFY:
+            ephyrProcessMouseMotion(xev);
             break;
 
-#ifdef XF86DRI
-        case EPHYR_EV_EXPOSE:
-            /*
-             * We only receive expose events when the expose event have
-             * be generated for a drawable that is a host X window managed
-             * by Xephyr. Host X windows managed by Xephyr exists for instance
-             * when Xephyr is asked to create a GL drawable in a DRI environment.
-             */
-            ephyrExposePairedWindow(ev.data.expose.window);
+        case XCB_KEY_PRESS:
+            ephyrProcessKeyPress(xev);
             break;
-#endif                          /* XF86DRI */
 
-#ifdef RANDR
-        case EPHYR_EV_CONFIGURE:
-            ephyrResizeScreen(screenInfo.screens[ev.data.configure.screen],
-                              ev.data.configure.width,
-                              ev.data.configure.height);
+        case XCB_KEY_RELEASE:
+            ephyrProcessKeyRelease(xev);
+            break;
+
+        case XCB_BUTTON_PRESS:
+            ephyrProcessButtonPress(xev);
             break;
-#endif /* RANDR */
 
-        default:
+        case XCB_BUTTON_RELEASE:
+            ephyrProcessButtonRelease(xev);
+            break;
+
+        case XCB_CONFIGURE_NOTIFY:
+            ephyrProcessConfigureNotify(xev);
             break;
         }
+
+        free(xev);
     }
 }
 
diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index c2754e3..b189ebd 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -853,231 +853,6 @@ hostx_load_keymap(void)
     ephyrKeySyms.maxKeyCode = max_keycode;
 }
 
-static KdScreenInfo *
-screen_from_window(Window w)
-{
-    int index = 0;
-
-    for (index = 0; index < HostX.n_screens; index++) {
-        EphyrScrPriv *scrpriv = HostX.screens[index]->driver;
-        if (scrpriv->win == w
-            || scrpriv->peer_win == w
-            || scrpriv->win_pre_existing == w) {
-            return HostX.screens[index];
-        }
-    }
-
-    return NULL;
-}
-
-int
-hostx_get_event(EphyrHostXEvent * ev)
-{
-    xcb_generic_event_t *xev;
-    static int grabbed_screen = -1;
-    static xcb_key_symbols_t *keysyms;
-
-    if (!keysyms)
-        keysyms = xcb_key_symbols_alloc(HostX.conn);
-
-    xev = xcb_poll_for_event(HostX.conn);
-    if (!xev) {
-        /* If our XCB connection has died (for example, our window was
-         * closed), exit now.
-         */
-        if (xcb_connection_has_error(HostX.conn)) {
-            CloseWellKnownConnections();
-            OsCleanup(1);
-            exit(1);
-        }
-
-        return 0;
-    }
-
-    switch (xev->response_type & 0x7f) {
-    case 0: { /* error */
-        xcb_generic_error_t *e = (xcb_generic_error_t *)xev;
-        fprintf(stderr, "X11 error\n"
-                "Error code: %hhu\n"
-                "Sequence number: %hu\n"
-                "Major code: %hhu\tMinor code: %hu\n"
-                "Error value: %u\n",
-                e->error_code,
-                e->sequence,
-                e->major_code, e->minor_code,
-                e->resource_id);
-        free(xev);
-        exit(1);
-    }
-
-    case XCB_EXPOSE: {
-        xcb_expose_event_t *expose = (xcb_expose_event_t *)xev;
-        KdScreenInfo *screen = screen_from_window(expose->window);
-        EphyrScrPriv *scrpriv = screen->driver;
-
-        /* Wait for the last expose event in a series of cliprects
-         * to actually paint our screen.
-         */
-        if (expose->count != 0)
-            break;
-
-        if (scrpriv) {
-            hostx_paint_rect(screen, 0, 0, 0, 0,
-                             scrpriv->win_width,
-                             scrpriv->win_height);
-        }
-        else {
-            EPHYR_LOG_ERROR("failed to get host screen\n");
-            ev->type = EPHYR_EV_EXPOSE;
-            ev->data.expose.window = expose->window;
-            free(xev);
-            return 1;
-        }
-        return 0;
-    }
-
-    case XCB_MOTION_NOTIFY: {
-        xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *)xev;
-        KdScreenInfo *screen = screen_from_window(motion->event);
-        EphyrScrPriv *scrpriv = screen->driver;
-
-        ev->type = EPHYR_EV_MOUSE_MOTION;
-        ev->data.mouse_motion.x = motion->event_x;
-        ev->data.mouse_motion.y = motion->event_y;
-        ev->data.mouse_motion.window = motion->event;
-        ev->data.mouse_motion.screen = scrpriv ? scrpriv->mynum : -1;
-        free(xev);
-        return 1;
-    }
-
-    case XCB_BUTTON_PRESS: {
-        xcb_button_press_event_t *button = (xcb_button_press_event_t *)xev;
-        ev->type = EPHYR_EV_MOUSE_PRESS;
-        ev->key_state = button->state;
-        /* 
-         * This is a bit hacky. will break for button 5 ( defined as 0x10 )
-         * Check KD_BUTTON defines in kdrive.h 
-         */
-        ev->data.mouse_down.button_num = 1 << (button->detail - 1);
-        free(xev);
-        return 1;
-    }
-
-    case XCB_BUTTON_RELEASE: {
-        xcb_button_release_event_t *button = (xcb_button_release_event_t *)xev;
-        ev->type = EPHYR_EV_MOUSE_RELEASE;
-        ev->key_state = button->state;
-        ev->data.mouse_up.button_num = 1 << (button->detail-1);
-        free(xev);
-        return 1;
-    }
-
-    case XCB_KEY_PRESS: {
-        xcb_key_press_event_t *key = (xcb_key_press_event_t *)xev;
-        ev->type = EPHYR_EV_KEY_PRESS;
-        ev->key_state = key->state;
-        ev->data.key_down.scancode = key->detail;
-        free(xev);
-        return 1;
-    }
-
-    case XCB_KEY_RELEASE: {
-        xcb_key_release_event_t *key = (xcb_key_release_event_t *)xev;
-        if ((xcb_key_symbols_get_keysym(keysyms, key->detail, 0) == XK_Shift_L
-             || xcb_key_symbols_get_keysym(keysyms, key->detail, 0) == XK_Shift_R)
-            && (key->state & XCB_MOD_MASK_CONTROL)) {
-            KdScreenInfo *screen = screen_from_window(key->event);
-            EphyrScrPriv *scrpriv = screen->driver;
-
-            if (grabbed_screen != -1) {
-                xcb_ungrab_keyboard(HostX.conn, XCB_TIME_CURRENT_TIME);
-                xcb_ungrab_pointer(HostX.conn, XCB_TIME_CURRENT_TIME);
-                grabbed_screen = -1;
-                hostx_set_win_title(screen,
-                                    "(ctrl+shift grabs mouse and keyboard)");
-            }
-            else {
-                /* Attempt grab */
-                xcb_grab_keyboard_cookie_t kbgrabc =
-                    xcb_grab_keyboard(HostX.conn,
-                                      TRUE,
-                                      scrpriv->win,
-                                      XCB_TIME_CURRENT_TIME,
-                                      XCB_GRAB_MODE_ASYNC,
-                                      XCB_GRAB_MODE_ASYNC);
-                xcb_grab_keyboard_reply_t *kbgrabr;
-                xcb_grab_pointer_cookie_t pgrabc =
-                    xcb_grab_pointer(HostX.conn,
-                                     TRUE,
-                                     scrpriv->win,
-                                     0,
-                                     XCB_GRAB_MODE_ASYNC,
-                                     XCB_GRAB_MODE_ASYNC,
-                                     scrpriv->win,
-                                     XCB_NONE,
-                                     XCB_TIME_CURRENT_TIME);
-                xcb_grab_pointer_reply_t *pgrabr;
-                kbgrabr = xcb_grab_keyboard_reply(HostX.conn, kbgrabc, NULL);
-                if (!kbgrabr || kbgrabr->status != XCB_GRAB_STATUS_SUCCESS) {
-                    xcb_discard_reply(HostX.conn, pgrabc.sequence);
-                    xcb_ungrab_pointer(HostX.conn, XCB_TIME_CURRENT_TIME);
-                } else {
-                    pgrabr = xcb_grab_pointer_reply(HostX.conn, pgrabc, NULL);
-                    if (!pgrabr || pgrabr->status != XCB_GRAB_STATUS_SUCCESS)
-                        {
-                            xcb_ungrab_keyboard(HostX.conn,
-                                                XCB_TIME_CURRENT_TIME);
-                        } else {
-                        grabbed_screen = scrpriv->mynum;
-                        hostx_set_win_title
-                            (screen,
-                             "(ctrl+shift releases mouse and keyboard)");
-                    }
-                }
-            }
-        }
-
-        /* Still send the release event even if above has happened
-         * server will get confused with just an up event. 
-         * Maybe it would be better to just block shift+ctrls getting to
-         * kdrive all togeather. 
-         */
-        ev->type = EPHYR_EV_KEY_RELEASE;
-        ev->key_state = key->state;
-        ev->data.key_up.scancode = key->detail;
-        return 1;
-    }
-
-    case ConfigureNotify:
-        {
-            xcb_configure_notify_event_t *configure =
-                (xcb_configure_notify_event_t *)xev;
-            KdScreenInfo *screen = screen_from_window(configure->window);
-            EphyrScrPriv *scrpriv = screen->driver;
-
-            if (!scrpriv ||
-                (scrpriv->win_pre_existing == None && !EphyrWantResize)) {
-                free(xev);
-                return 0;
-            }
-
-            ev->type = EPHYR_EV_CONFIGURE;
-            ev->data.configure.width = configure->width;
-            ev->data.configure.height = configure->height;
-            ev->data.configure.window = configure->window;
-            ev->data.configure.screen = scrpriv->mynum;
-            free(xev);
-
-            return 1;
-        }
-    default:
-        break;
-
-    }
-    free(xev);
-    return 0;
-}
-
 xcb_connection_t *
 hostx_get_xcbconn(void)
 {
diff --git a/hw/kdrive/ephyr/hostx.h b/hw/kdrive/ephyr/hostx.h
index 8018f94..0323b33 100644
--- a/hw/kdrive/ephyr/hostx.h
+++ b/hw/kdrive/ephyr/hostx.h
@@ -41,65 +41,12 @@
 #endif
 
 typedef struct EphyrHostXVars EphyrHostXVars;
-typedef struct EphyrHostXEvent EphyrHostXEvent;
-typedef enum EphyrHostXEventType {
-    EPHYR_EV_MOUSE_MOTION,
-    EPHYR_EV_MOUSE_PRESS,
-    EPHYR_EV_MOUSE_RELEASE,
-    EPHYR_EV_KEY_PRESS,
-    EPHYR_EV_KEY_RELEASE,
-    EPHYR_EV_EXPOSE,
-    EPHYR_EV_CONFIGURE,
-} EphyrHostXEventType;
 
 typedef struct {
     int minKeyCode;
     int maxKeyCode;
 } EphyrKeySyms;
 
-struct EphyrHostXEvent {
-    EphyrHostXEventType type;
-
-    union {
-        struct mouse_motion {
-            int x;
-            int y;
-            int screen;
-            int window;
-        } mouse_motion;
-
-        struct mouse_down {
-            int button_num;
-        } mouse_down;
-
-        struct mouse_up {
-            int button_num;
-        } mouse_up;
-
-        struct key_up {
-            int scancode;
-        } key_up;
-
-        struct key_down {
-            int scancode;
-        } key_down;
-
-        struct expose {
-            int window;
-        } expose;
-
-        struct configure {
-            int width;
-            int height;
-            int screen;
-            int window;
-        } configure;
-
-    } data;
-
-    int key_state;
-};
-
 typedef struct {
     VisualID visualid;
     int screen;
@@ -199,9 +146,6 @@ hostx_paint_rect(KdScreenInfo *screen,
 void
  hostx_load_keymap(void);
 
-int
- hostx_get_event(EphyrHostXEvent * ev);
-
 xcb_connection_t *
 hostx_get_xcbconn(void);
 
commit 847c856effde482c13cdefcdca8176cee3bf67c4
Author: Eric Anholt <eric at anholt.net>
Date:   Sun Aug 18 17:28:08 2013 +0200

    ephyr: Move the host screen info into the kdrive screen private.
    
    We can include xcb bits from the same place as server headers, so
    there's no need to hide them any more.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index 003ef21..089c0e2 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -99,8 +99,9 @@ ephyrCardInit(KdCardInfo * card)
 }
 
 Bool
-ephyrScreenInitialize(KdScreenInfo * screen, EphyrScrPriv * scrpriv)
+ephyrScreenInitialize(KdScreenInfo *screen)
 {
+    EphyrScrPriv *scrpriv = screen->driver;
     int width = 640, height = 480;
     CARD32 redMask, greenMask, blueMask;
 
@@ -117,7 +118,7 @@ ephyrScreenInitialize(KdScreenInfo * screen, EphyrScrPriv * scrpriv)
         if (screen->fb.depth < hostx_get_depth()
             && (screen->fb.depth == 24 || screen->fb.depth == 16
                 || screen->fb.depth == 8)) {
-            hostx_set_server_depth(screen, screen->fb.depth);
+            scrpriv->server_depth = screen->fb.depth;
         }
         else
             ErrorF
@@ -180,27 +181,6 @@ ephyrScreenInitialize(KdScreenInfo * screen, EphyrScrPriv * scrpriv)
     return ephyrMapFramebuffer(screen);
 }
 
-Bool
-ephyrScreenInit(KdScreenInfo * screen)
-{
-    EphyrScrPriv *scrpriv;
-
-    scrpriv = calloc(1, sizeof(EphyrScrPriv));
-
-    if (!scrpriv)
-        return FALSE;
-
-    screen->driver = scrpriv;
-
-    if (!ephyrScreenInitialize(screen, scrpriv)) {
-        screen->driver = 0;
-        free(scrpriv);
-        return FALSE;
-    }
-
-    return TRUE;
-}
-
 void *
 ephyrWindowLinear(ScreenPtr pScreen,
                   CARD32 row,
diff --git a/hw/kdrive/ephyr/ephyr.h b/hw/kdrive/ephyr/ephyr.h
index be910c1..73fdb59 100644
--- a/hw/kdrive/ephyr/ephyr.h
+++ b/hw/kdrive/ephyr/ephyr.h
@@ -29,6 +29,7 @@
 #include <unistd.h>
 #include <signal.h>
 #include <libgen.h>
+#include <xcb/xcb_image.h>
 
 #include "os.h"                 /* for OsSignal() */
 #include "kdrive.h"
@@ -61,10 +62,24 @@ typedef struct _ephyrFakexaPriv {
 } EphyrFakexaPriv;
 
 typedef struct _ephyrScrPriv {
+    /* ephyr server info */
     Rotation randr;
     Bool shadow;
     DamagePtr pDamage;
     EphyrFakexaPriv *fakexa;
+
+    /* Host X window info */
+    xcb_window_t win;
+    xcb_window_t win_pre_existing;    /* Set via -parent option like xnest */
+    xcb_window_t peer_win;            /* Used for GL; should be at most one */
+    xcb_image_t *ximg;
+    int win_width, win_height;
+    int server_depth;
+    unsigned char *fb_data;     /* only used when host bpp != server bpp */
+    xcb_shm_segment_info_t shminfo;
+
+    KdScreenInfo *screen;
+    int mynum;                  /* Screen number */
 } EphyrScrPriv;
 
 extern KdCardFuncs ephyrFuncs;
@@ -80,10 +95,7 @@ Bool
  ephyrCardInit(KdCardInfo * card);
 
 Bool
- ephyrScreenInit(KdScreenInfo * screen);
-
-Bool
- ephyrScreenInitialize(KdScreenInfo * screen, EphyrScrPriv * scrpriv);
+ephyrScreenInitialize(KdScreenInfo *screen);
 
 Bool
  ephyrInitScreen(ScreenPtr pScreen);
diff --git a/hw/kdrive/ephyr/ephyrinit.c b/hw/kdrive/ephyr/ephyrinit.c
index 9a1dd7d..7812dbe 100644
--- a/hw/kdrive/ephyr/ephyrinit.c
+++ b/hw/kdrive/ephyr/ephyrinit.c
@@ -147,6 +147,9 @@ processScreenArg(const char *screen_size, char *parent_id)
 
         screen = KdScreenInfoAdd(card);
         KdParseScreen(screen, screen_size);
+        screen->driver = calloc(1, sizeof(EphyrScrPriv));
+        if (!screen->driver)
+            FatalError("Couldn't alloc screen private\n");
 
         if (parent_id) {
             p_id = strtol(parent_id, NULL, 0);
@@ -369,7 +372,7 @@ ephyrCursorEnable(ScreenPtr pScreen)
 
 KdCardFuncs ephyrFuncs = {
     ephyrCardInit,              /* cardinit */
-    ephyrScreenInit,            /* scrinit */
+    ephyrScreenInitialize,      /* scrinit */
     ephyrInitScreen,            /* initScreen */
     ephyrFinishInitScreen,      /* finishInitScreen */
     ephyrCreateResources,       /* createRes */
diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index 6d780cd..c2754e3 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -56,20 +56,6 @@
 #include "ephyrlog.h"
 #include "ephyr.h"
 
-struct EphyrHostScreen {
-    Window win;
-    Window win_pre_existing;    /* Set via -parent option like xnest */
-    Window peer_win;            /* Used for GL; should be at most one */
-    xcb_image_t    *ximg;
-    int win_width, win_height;
-    int server_depth;
-    unsigned char *fb_data;     /* only used when host bpp != server bpp */
-    xcb_shm_segment_info_t shminfo;
-
-    KdScreenInfo *screen;
-    int mynum;                  /* Screen number */
-};
-
 struct EphyrHostXVars {
     char *server_dpy_name;
     xcb_connection_t *conn;
@@ -83,7 +69,7 @@ struct EphyrHostXVars {
     Bool have_shm;
 
     int n_screens;
-    struct EphyrHostScreen *screens;
+    KdScreenInfo **screens;
 
     long damage_debug_msec;
 
@@ -111,29 +97,15 @@ static void
 
 #define host_depth_matches_server(_vars) (HostX.depth == (_vars)->server_depth)
 
-static struct EphyrHostScreen *
-host_screen_from_screen_info(KdScreenInfo *screen)
-{
-    int i;
-
-    for (i = 0; i < HostX.n_screens; i++) {
-        if (HostX.screens[i].screen == screen) {
-            return &HostX.screens[i];
-        }
-    }
-    return NULL;
-}
-
 int
 hostx_want_screen_size(KdScreenInfo *screen, int *width, int *height)
 {
-    struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
+    EphyrScrPriv *scrpriv = screen->driver;
 
-    if (host_screen &&
-        (host_screen->win_pre_existing != None ||
-         HostX.use_fullscreen == TRUE)) {
-        *width = host_screen->win_width;
-        *height = host_screen->win_height;
+    if (scrpriv && (scrpriv->win_pre_existing != None ||
+                    HostX.use_fullscreen == TRUE)) {
+        *width = scrpriv->win_width;
+        *height = scrpriv->win_height;
         return 1;
     }
 
@@ -143,15 +115,16 @@ hostx_want_screen_size(KdScreenInfo *screen, int *width, int *height)
 void
 hostx_add_screen(KdScreenInfo *screen, unsigned long win_id, int screen_num)
 {
+    EphyrScrPriv *scrpriv = screen->driver;
     int index = HostX.n_screens;
 
     HostX.n_screens += 1;
     HostX.screens = realloc(HostX.screens,
-                            HostX.n_screens * sizeof(struct EphyrHostScreen));
-    memset(&HostX.screens[index], 0, sizeof(struct EphyrHostScreen));
+                            HostX.n_screens * sizeof(HostX.screens[0]));
+    HostX.screens[index] = screen;
 
-    HostX.screens[index].screen = screen;
-    HostX.screens[index].win_pre_existing = win_id;
+    scrpriv->screen = screen;
+    scrpriv->win_pre_existing = win_id;
 }
 
 void
@@ -163,25 +136,25 @@ hostx_set_display_name(char *name)
 void
 hostx_set_screen_number(KdScreenInfo *screen, int number)
 {
-    struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
+    EphyrScrPriv *scrpriv = screen->driver;
 
-    if (host_screen) {
-        host_screen->mynum = number;
-        hostx_set_win_title(host_screen->screen, "");
+    if (scrpriv) {
+        scrpriv->mynum = number;
+        hostx_set_win_title(screen, "");
     }
 }
 
 void
 hostx_set_win_title(KdScreenInfo *screen, const char *extra_text)
 {
-    struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
+    EphyrScrPriv *scrpriv = screen->driver;
 
-    if (!host_screen)
+    if (!scrpriv)
         return;
 
     if (ephyrTitle) {
         xcb_icccm_set_wm_name(HostX.conn,
-                              host_screen->win,
+                              scrpriv->win,
                               XCB_ATOM_STRING,
                               8,
                               strlen(ephyrTitle),
@@ -193,10 +166,10 @@ hostx_set_win_title(KdScreenInfo *screen, const char *extra_text)
         memset(buf, 0, BUF_LEN + 1);
         snprintf(buf, BUF_LEN, "Xephyr on %s.%d %s",
                  HostX.server_dpy_name,
-                 host_screen->mynum, (extra_text != NULL) ? extra_text : "");
+                 scrpriv->mynum, (extra_text != NULL) ? extra_text : "");
 
         xcb_icccm_set_wm_name(HostX.conn,
-                              host_screen->win,
+                              scrpriv->win,
                               XCB_ATOM_STRING,
                               8,
                               strlen(buf),
@@ -219,9 +192,9 @@ hostx_use_host_cursor(void)
 int
 hostx_want_preexisting_window(KdScreenInfo *screen)
 {
-    struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
+    EphyrScrPriv *scrpriv = screen->driver;
 
-    if (host_screen && host_screen->win_pre_existing) {
+    if (scrpriv && scrpriv->win_pre_existing) {
         return 1;
     }
     else {
@@ -261,9 +234,10 @@ hostx_set_fullscreen_hint(void)
     free(reply);
 
     for (index = 0; index < HostX.n_screens; index++) {
+        EphyrScrPriv *scrpriv = HostX.screens[index]->driver;
         xcb_change_property(HostX.conn,
                             PropModeReplace,
-                            HostX.screens[index].win,
+                            scrpriv->win,
                             atom_WINDOW_STATE,
                             XCB_ATOM_ATOM,
                             32,
@@ -316,7 +290,7 @@ hostx_init(void)
     char *class_hint;
     size_t class_len;
     const xcb_query_extension_reply_t *shm_rep;
-    xcb_screen_t *screen;
+    xcb_screen_t *xscreen;
 
     attr =
         XCB_EVENT_MASK_BUTTON_PRESS
@@ -334,11 +308,11 @@ hostx_init(void)
         exit(1);
     }
 
-    screen = xcb_aux_get_screen(HostX.conn, HostX.screen);
-    HostX.winroot = screen->root;
+    xscreen = xcb_aux_get_screen(HostX.conn, HostX.screen);
+    HostX.winroot = xscreen->root;
     HostX.gc = xcb_generate_id(HostX.conn);
-    HostX.depth = screen->root_depth;
-    HostX.visual  = xcb_aux_find_visual_by_id(screen, screen->root_visual);
+    HostX.depth = xscreen->root_depth;
+    HostX.visual  = xcb_aux_find_visual_by_id(xscreen, xscreen->root_visual);
 
     xcb_create_gc(HostX.conn, HostX.gc, HostX.winroot, 0, NULL);
     cookie_WINDOW_STATE = xcb_intern_atom(HostX.conn, FALSE,
@@ -350,19 +324,21 @@ hostx_init(void)
                         "_NET_WM_STATE_FULLSCREEN");
 
     for (index = 0; index < HostX.n_screens; index++) {
-        struct EphyrHostScreen *host_screen = &HostX.screens[index];
+        KdScreenInfo *screen = HostX.screens[index];
+        EphyrScrPriv *scrpriv = screen->driver;
 
-        host_screen->win = xcb_generate_id(HostX.conn);
-        host_screen->server_depth = HostX.depth;
+        scrpriv->win = xcb_generate_id(HostX.conn);
+        scrpriv->server_depth = HostX.depth;
+        scrpriv->ximg = NULL;
 
-        if (host_screen->win_pre_existing != XCB_WINDOW_NONE) {
+        if (scrpriv->win_pre_existing != XCB_WINDOW_NONE) {
             xcb_get_geometry_reply_t *prewin_geom;
             xcb_get_geometry_cookie_t cookie;
             xcb_generic_error_t *e = NULL;
 
             /* Get screen size from existing window */
             cookie = xcb_get_geometry(HostX.conn,
-                                      host_screen->win_pre_existing);
+                                      scrpriv->win_pre_existing);
             prewin_geom = xcb_get_geometry_reply(HostX.conn, cookie, &e);
 
             if (e) {
@@ -372,18 +348,18 @@ hostx_init(void)
                 exit (1);
             }
 
-            host_screen->win_width  = prewin_geom->width;
-            host_screen->win_height = prewin_geom->height;
+            scrpriv->win_width  = prewin_geom->width;
+            scrpriv->win_height = prewin_geom->height;
 
             free(prewin_geom);
 
             xcb_create_window(HostX.conn,
                               XCB_COPY_FROM_PARENT,
-                              host_screen->win,
-                              host_screen->win_pre_existing,
+                              scrpriv->win,
+                              scrpriv->win_pre_existing,
                               0,0,
-                              host_screen->win_width,
-                              host_screen->win_height,
+                              scrpriv->win_width,
+                              scrpriv->win_height,
                               0,
                               XCB_WINDOW_CLASS_COPY_FROM_PARENT,
                               XCB_COPY_FROM_PARENT,
@@ -393,7 +369,7 @@ hostx_init(void)
         else {
             xcb_create_window(HostX.conn,
                               XCB_COPY_FROM_PARENT,
-                              host_screen->win,
+                              scrpriv->win,
                               HostX.winroot,
                               0,0,100,100, /* will resize */
                               0,
@@ -402,12 +378,12 @@ hostx_init(void)
                               XCB_CW_EVENT_MASK,
                               &attr);
 
-            hostx_set_win_title (host_screen->screen,
-                                 "(ctrl+shift grabs mouse and keyboard)");
+            hostx_set_win_title(screen,
+                                "(ctrl+shift grabs mouse and keyboard)");
 
             if (HostX.use_fullscreen) {
-                host_screen->win_width  = screen->width_in_pixels;
-                host_screen->win_height = screen->height_in_pixels;
+                scrpriv->win_width  = xscreen->width_in_pixels;
+                scrpriv->win_height = xscreen->height_in_pixels;
 
                 hostx_set_fullscreen_hint();
             }
@@ -422,7 +398,7 @@ hostx_init(void)
                 strcpy(class_hint + strlen(ephyrResName) + 1, "Xephyr");
                 xcb_change_property(HostX.conn,
                                     XCB_PROP_MODE_REPLACE,
-                                    host_screen->win,
+                                    scrpriv->win,
                                     XCB_ATOM_WM_CLASS,
                                     XCB_ATOM_STRING,
                                     8,
@@ -435,7 +411,7 @@ hostx_init(void)
 
     if (!xcb_aux_parse_color("red", &red, &green, &blue)) {
         xcb_lookup_color_cookie_t c =
-            xcb_lookup_color(HostX.conn, screen->default_colormap, 3, "red");
+            xcb_lookup_color(HostX.conn, xscreen->default_colormap, 3, "red");
         xcb_lookup_color_reply_t *reply =
             xcb_lookup_color_reply(HostX.conn, c, NULL);
         red = reply->exact_red;
@@ -446,7 +422,7 @@ hostx_init(void)
 
     {
         xcb_alloc_color_cookie_t c = xcb_alloc_color(HostX.conn,
-                                                     screen->default_colormap,
+                                                     xscreen->default_colormap,
                                                      red, green, blue);
         xcb_alloc_color_reply_t *r = xcb_alloc_color_reply(HostX.conn, c, NULL);
         red = r->red;
@@ -470,18 +446,17 @@ hostx_init(void)
                           0,0,0,
                           1,1);
         for (index = 0; index < HostX.n_screens; index++) {
+            KdScreenInfo *screen = HostX.screens[index];
+            EphyrScrPriv *scrpriv = screen->driver;
+
             xcb_change_window_attributes(HostX.conn,
-                                         HostX.screens[index].win,
+                                         scrpriv->win,
                                          XCB_CW_CURSOR,
                                          &empty_cursor);
         }
         xcb_free_pixmap(HostX.conn, cursor_pxm);
     }
 
-    for (index = 0; index < HostX.n_screens; index++) {
-        HostX.screens[index].ximg = NULL;
-    }
-
     /* Try to get share memory ximages for a little bit more speed */
     shm_rep = xcb_get_extension_data(HostX.conn, &xcb_shm_id);
     if (!shm_rep || !shm_rep->present || getenv("XEPHYR_NO_SHM")) {
@@ -538,49 +513,40 @@ hostx_get_depth(void)
 int
 hostx_get_server_depth(KdScreenInfo *screen)
 {
-    struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
+    EphyrScrPriv *scrpriv = screen->driver;
 
-    return host_screen ? host_screen->server_depth : 0;
-}
-
-void
-hostx_set_server_depth(KdScreenInfo *screen, int depth)
-{
-    struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
-
-    if (host_screen)
-        host_screen->server_depth = depth;
+    return scrpriv ? scrpriv->server_depth : 0;
 }
 
 int
 hostx_get_bpp(KdScreenInfo *screen)
 {
-    struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
+    EphyrScrPriv *scrpriv = screen->driver;
 
-    if (!host_screen)
+    if (!scrpriv)
         return 0;
 
-    if (host_depth_matches_server (host_screen))
+    if (host_depth_matches_server(scrpriv))
         return HostX.visual->bits_per_rgb_value;
     else
-        return host_screen->server_depth; /*XXX correct ?*/
+        return scrpriv->server_depth; /*XXX correct ?*/
 }
 
 void
 hostx_get_visual_masks(KdScreenInfo *screen,
                        CARD32 *rmsk, CARD32 *gmsk, CARD32 *bmsk)
 {
-    struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
+    EphyrScrPriv *scrpriv = screen->driver;
 
-    if (!host_screen)
+    if (!scrpriv)
         return;
 
-    if (host_depth_matches_server(host_screen)) {
+    if (host_depth_matches_server(scrpriv)) {
         *rmsk = HostX.visual->red_mask;
         *gmsk = HostX.visual->green_mask;
         *bmsk = HostX.visual->blue_mask;
     }
-    else if (host_screen->server_depth == 16) {
+    else if (scrpriv->server_depth == 16) {
         /* Assume 16bpp 565 */
         *rmsk = 0xf800;
         *gmsk = 0x07e0;
@@ -645,11 +611,10 @@ hostx_screen_init(KdScreenInfo *screen,
                   int width, int height, int buffer_height,
                   int *bytes_per_line, int *bits_per_pixel)
 {
+    EphyrScrPriv *scrpriv = screen->driver;
     Bool shm_success = FALSE;
 
-    struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
-
-    if (!host_screen) {
+    if (!scrpriv) {
         fprintf(stderr, "%s: Error in accessing hostx data\n", __func__);
         exit(1);
     }
@@ -657,64 +622,64 @@ hostx_screen_init(KdScreenInfo *screen,
     EPHYR_DBG("host_screen=%p wxh=%dx%d, buffer_height=%d",
               host_screen, width, height, buffer_height);
 
-    if (host_screen->ximg != NULL) {
+    if (scrpriv->ximg != NULL) {
         /* Free up the image data if previously used
          * i.ie called by server reset
          */
 
         if (HostX.have_shm) {
-            xcb_shm_detach(HostX.conn, host_screen->shminfo.shmseg);
-            xcb_image_destroy (host_screen->ximg);
-            shmdt(host_screen->shminfo.shmaddr);
-            shmctl(host_screen->shminfo.shmid, IPC_RMID, 0);
+            xcb_shm_detach(HostX.conn, scrpriv->shminfo.shmseg);
+            xcb_image_destroy(scrpriv->ximg);
+            shmdt(scrpriv->shminfo.shmaddr);
+            shmctl(scrpriv->shminfo.shmid, IPC_RMID, 0);
         }
         else {
-            free(host_screen->ximg->data);
-            host_screen->ximg->data = NULL;
+            free(scrpriv->ximg->data);
+            scrpriv->ximg->data = NULL;
 
-            xcb_image_destroy(host_screen->ximg);
+            xcb_image_destroy(scrpriv->ximg);
         }
     }
 
     if (HostX.have_shm) {
-        host_screen->ximg = xcb_image_create_native(HostX.conn,
-                                                    width,
-                                                    buffer_height,
-                                                    XCB_IMAGE_FORMAT_Z_PIXMAP,
-                                                    HostX.depth,
-                                                    NULL,
-                                                    ~0,
-                                                    NULL);
-
-        host_screen->shminfo.shmid =
+        scrpriv->ximg = xcb_image_create_native(HostX.conn,
+                                                width,
+                                                buffer_height,
+                                                XCB_IMAGE_FORMAT_Z_PIXMAP,
+                                                HostX.depth,
+                                                NULL,
+                                                ~0,
+                                                NULL);
+
+        scrpriv->shminfo.shmid =
             shmget(IPC_PRIVATE,
-                   host_screen->ximg->stride * buffer_height,
+                   scrpriv->ximg->stride * buffer_height,
                    IPC_CREAT | 0777);
-        host_screen->ximg->data = shmat(host_screen->shminfo.shmid, 0, 0);
-        host_screen->shminfo.shmaddr = host_screen->ximg->data;
+        scrpriv->ximg->data = shmat(scrpriv->shminfo.shmid, 0, 0);
+        scrpriv->shminfo.shmaddr = scrpriv->ximg->data;
 
-        if (host_screen->ximg->data == (uint8_t *) -1) {
+        if (scrpriv->ximg->data == (uint8_t *) -1) {
             EPHYR_DBG
                 ("Can't attach SHM Segment, falling back to plain XImages");
             HostX.have_shm = FALSE;
-            xcb_image_destroy (host_screen->ximg);
-            shmctl(host_screen->shminfo.shmid, IPC_RMID, 0);
+            xcb_image_destroy (scrpriv->ximg);
+            shmctl(scrpriv->shminfo.shmid, IPC_RMID, 0);
         }
         else {
-            EPHYR_DBG("SHM segment attached %p", host_screen->shminfo.shmaddr);
-            host_screen->shminfo.shmseg = xcb_generate_id(HostX.conn);
+            EPHYR_DBG("SHM segment attached %p", scrpriv->shminfo.shmaddr);
+            scrpriv->shminfo.shmseg = xcb_generate_id(HostX.conn);
             xcb_shm_attach(HostX.conn,
-                           host_screen->shminfo.shmseg,
-                           host_screen->shminfo.shmid,
+                           scrpriv->shminfo.shmseg,
+                           scrpriv->shminfo.shmid,
                            FALSE);
             shm_success = TRUE;
         }
     }
 
     if (!shm_success) {
-        EPHYR_DBG("Creating image %dx%d for screen host_screen=%p\n",
-                  width, buffer_height, host_screen);
-        host_screen->ximg = xcb_image_create_native(HostX.conn,
+        EPHYR_DBG("Creating image %dx%d for screen scrpriv=%p\n",
+                  width, buffer_height, scrpriv);
+        scrpriv->ximg = xcb_image_create_native(HostX.conn,
                                                     width,
                                                     buffer_height,
                                                     XCB_IMAGE_FORMAT_Z_PIXMAP,
@@ -723,53 +688,53 @@ hostx_screen_init(KdScreenInfo *screen,
                                                     ~0,
                                                     NULL);
 
-        host_screen->ximg->data =
-            malloc(host_screen->ximg->stride * buffer_height);
+        scrpriv->ximg->data =
+            malloc(scrpriv->ximg->stride * buffer_height);
     }
 
-    *bytes_per_line = host_screen->ximg->stride;
-    *bits_per_pixel = host_screen->ximg->bpp;
+    *bytes_per_line = scrpriv->ximg->stride;
+    *bits_per_pixel = scrpriv->ximg->bpp;
 
-    if (host_screen->win_pre_existing == None && !EphyrWantResize) {
+    if (scrpriv->win_pre_existing == None && !EphyrWantResize) {
         /* Ask the WM to keep our size static */
         xcb_size_hints_t size_hints = {0};
         size_hints.max_width = size_hints.min_width = width;
         size_hints.max_height = size_hints.min_height = height;
         size_hints.flags = (XCB_ICCCM_SIZE_HINT_P_MIN_SIZE |
                             XCB_ICCCM_SIZE_HINT_P_MAX_SIZE);
-        xcb_icccm_set_wm_normal_hints(HostX.conn, host_screen->win,
+        xcb_icccm_set_wm_normal_hints(HostX.conn, scrpriv->win,
                                       &size_hints);
     }
 
-    xcb_map_window(HostX.conn, host_screen->win);
+    xcb_map_window(HostX.conn, scrpriv->win);
 
     xcb_aux_sync(HostX.conn);
 
-    host_screen->win_width = width;
-    host_screen->win_height = height;
+    scrpriv->win_width = width;
+    scrpriv->win_height = height;
 
-    if (host_depth_matches_server(host_screen)) {
+    if (host_depth_matches_server(scrpriv)) {
         EPHYR_DBG("Host matches server");
-        return host_screen->ximg->data;
+        return scrpriv->ximg->data;
     }
     else {
-        EPHYR_DBG("server bpp %i", host_screen->server_depth >> 3);
-        host_screen->fb_data =
-            malloc(width * buffer_height * (host_screen->server_depth >> 3));
-        return host_screen->fb_data;
+        EPHYR_DBG("server bpp %i", scrpriv->server_depth >> 3);
+        scrpriv->fb_data =
+            malloc(width * buffer_height * (scrpriv->server_depth >> 3));
+        return scrpriv->fb_data;
     }
 }
 
-static void hostx_paint_debug_rect(struct EphyrHostScreen *host_screen,
+static void hostx_paint_debug_rect(KdScreenInfo *screen,
                                    int x, int y, int width, int height);
 
 void
 hostx_paint_rect(KdScreenInfo *screen,
                  int sx, int sy, int dx, int dy, int width, int height)
 {
-    struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
+    EphyrScrPriv *scrpriv = screen->driver;
 
-    EPHYR_DBG("painting in screen %d\n", host_screen->mynum);
+    EPHYR_DBG("painting in screen %d\n", scrpriv->mynum);
 
     /*
      *  Copy the image data updated by the shadow layer
@@ -777,7 +742,7 @@ hostx_paint_rect(KdScreenInfo *screen,
      */
 
     if (HostXWantDamageDebug) {
-        hostx_paint_debug_rect(host_screen, dx, dy, width, height);
+        hostx_paint_debug_rect(screen, dx, dy, width, height);
     }
 
     /* 
@@ -792,23 +757,23 @@ hostx_paint_rect(KdScreenInfo *screen,
      *       ... and it will be slower than the matching depth case.
      */
 
-    if (!host_depth_matches_server(host_screen)) {
-        int x, y, idx, bytes_per_pixel = (host_screen->server_depth >> 3);
+    if (!host_depth_matches_server(scrpriv)) {
+        int x, y, idx, bytes_per_pixel = (scrpriv->server_depth >> 3);
         unsigned char r, g, b;
         unsigned long host_pixel;
 
-        EPHYR_DBG("Unmatched host depth host_screen=%p\n", host_screen);
+        EPHYR_DBG("Unmatched host depth scrpriv=%p\n", scrpriv);
         for (y = sy; y < sy + height; y++)
             for (x = sx; x < sx + width; x++) {
                 idx =
-                    (host_screen->win_width * y * bytes_per_pixel) +
+                    (scrpriv->win_width * y * bytes_per_pixel) +
                     (x * bytes_per_pixel);
 
-                switch (host_screen->server_depth) {
+                switch (scrpriv->server_depth) {
                 case 16:
                 {
                     unsigned short pixel =
-                        *(unsigned short *) (host_screen->fb_data + idx);
+                        *(unsigned short *) (scrpriv->fb_data + idx);
 
                     r = ((pixel & 0xf800) >> 8);
                     g = ((pixel & 0x07e0) >> 3);
@@ -816,14 +781,14 @@ hostx_paint_rect(KdScreenInfo *screen,
 
                     host_pixel = (r << 16) | (g << 8) | (b);
 
-                    xcb_image_put_pixel(host_screen->ximg, x, y, host_pixel);
+                    xcb_image_put_pixel(scrpriv->ximg, x, y, host_pixel);
                     break;
                 }
                 case 8:
                 {
                     unsigned char pixel =
-                        *(unsigned char *) (host_screen->fb_data + idx);
-                    xcb_image_put_pixel(host_screen->ximg, x, y,
+                        *(unsigned char *) (scrpriv->fb_data + idx);
+                    xcb_image_put_pixel(scrpriv->ximg, x, y,
                                         HostX.cmap[pixel]);
                     break;
                 }
@@ -834,13 +799,13 @@ hostx_paint_rect(KdScreenInfo *screen,
     }
 
     if (HostX.have_shm) {
-        xcb_image_shm_put(HostX.conn, host_screen->win,
-                          HostX.gc, host_screen->ximg,
-                          host_screen->shminfo,
+        xcb_image_shm_put(HostX.conn, scrpriv->win,
+                          HostX.gc, scrpriv->ximg,
+                          scrpriv->shminfo,
                           sx, sy, dx, dy, width, height, FALSE);
     }
     else {
-        xcb_image_put(HostX.conn, host_screen->win, HostX.gc, host_screen->ximg,
+        xcb_image_put(HostX.conn, scrpriv->win, HostX.gc, scrpriv->ximg,
                       dx, dy, 0);
     }
 
@@ -848,9 +813,10 @@ hostx_paint_rect(KdScreenInfo *screen,
 }
 
 static void
-hostx_paint_debug_rect(struct EphyrHostScreen *host_screen,
+hostx_paint_debug_rect(KdScreenInfo *screen,
                        int x, int y, int width, int height)
 {
+    EphyrScrPriv *scrpriv = screen->driver;
     struct timespec tspec;
     xcb_rectangle_t rect = { .x = x, .y = y, .width = width, .height = height };
     xcb_void_cookie_t cookie;
@@ -864,7 +830,7 @@ hostx_paint_debug_rect(struct EphyrHostScreen *host_screen,
 
     /* fprintf(stderr, "Xephyr updating: %i+%i %ix%i\n", x, y, width, height); */
 
-    cookie = xcb_poly_fill_rectangle_checked(HostX.conn, host_screen->win,
+    cookie = xcb_poly_fill_rectangle_checked(HostX.conn, scrpriv->win,
                                              HostX.gc, 1, &rect);
     e = xcb_request_check(HostX.conn, cookie);
     free(e);
@@ -887,23 +853,21 @@ hostx_load_keymap(void)
     ephyrKeySyms.maxKeyCode = max_keycode;
 }
 
-static struct EphyrHostScreen *
-host_screen_from_window(Window w)
+static KdScreenInfo *
+screen_from_window(Window w)
 {
     int index = 0;
-    struct EphyrHostScreen *result = NULL;
 
     for (index = 0; index < HostX.n_screens; index++) {
-        if (HostX.screens[index].win == w
-            || HostX.screens[index].peer_win == w
-            || HostX.screens[index].win_pre_existing == w) {
-            result = &HostX.screens[index];
-            goto out;
+        EphyrScrPriv *scrpriv = HostX.screens[index]->driver;
+        if (scrpriv->win == w
+            || scrpriv->peer_win == w
+            || scrpriv->win_pre_existing == w) {
+            return HostX.screens[index];
         }
     }
 
- out:
-    return result;
+    return NULL;
 }
 
 int
@@ -948,8 +912,8 @@ hostx_get_event(EphyrHostXEvent * ev)
 
     case XCB_EXPOSE: {
         xcb_expose_event_t *expose = (xcb_expose_event_t *)xev;
-        struct EphyrHostScreen *host_screen =
-            host_screen_from_window(expose->window);
+        KdScreenInfo *screen = screen_from_window(expose->window);
+        EphyrScrPriv *scrpriv = screen->driver;
 
         /* Wait for the last expose event in a series of cliprects
          * to actually paint our screen.
@@ -957,10 +921,10 @@ hostx_get_event(EphyrHostXEvent * ev)
         if (expose->count != 0)
             break;
 
-        if (host_screen) {
-            hostx_paint_rect(host_screen->screen, 0, 0, 0, 0,
-                             host_screen->win_width,
-                             host_screen->win_height);
+        if (scrpriv) {
+            hostx_paint_rect(screen, 0, 0, 0, 0,
+                             scrpriv->win_width,
+                             scrpriv->win_height);
         }
         else {
             EPHYR_LOG_ERROR("failed to get host screen\n");
@@ -974,15 +938,14 @@ hostx_get_event(EphyrHostXEvent * ev)
 
     case XCB_MOTION_NOTIFY: {
         xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *)xev;
-        struct EphyrHostScreen *host_screen =
-            host_screen_from_window(motion->event);
+        KdScreenInfo *screen = screen_from_window(motion->event);
+        EphyrScrPriv *scrpriv = screen->driver;
 
         ev->type = EPHYR_EV_MOUSE_MOTION;
         ev->data.mouse_motion.x = motion->event_x;
         ev->data.mouse_motion.y = motion->event_y;
         ev->data.mouse_motion.window = motion->event;
-        ev->data.mouse_motion.screen =
-            (host_screen ? host_screen->mynum : -1);
+        ev->data.mouse_motion.screen = scrpriv ? scrpriv->mynum : -1;
         free(xev);
         return 1;
     }
@@ -1023,14 +986,14 @@ hostx_get_event(EphyrHostXEvent * ev)
         if ((xcb_key_symbols_get_keysym(keysyms, key->detail, 0) == XK_Shift_L
              || xcb_key_symbols_get_keysym(keysyms, key->detail, 0) == XK_Shift_R)
             && (key->state & XCB_MOD_MASK_CONTROL)) {
-            struct EphyrHostScreen *host_screen =
-                host_screen_from_window(key->event);
+            KdScreenInfo *screen = screen_from_window(key->event);
+            EphyrScrPriv *scrpriv = screen->driver;
 
             if (grabbed_screen != -1) {
                 xcb_ungrab_keyboard(HostX.conn, XCB_TIME_CURRENT_TIME);
                 xcb_ungrab_pointer(HostX.conn, XCB_TIME_CURRENT_TIME);
                 grabbed_screen = -1;
-                hostx_set_win_title(host_screen->screen,
+                hostx_set_win_title(screen,
                                     "(ctrl+shift grabs mouse and keyboard)");
             }
             else {
@@ -1038,7 +1001,7 @@ hostx_get_event(EphyrHostXEvent * ev)
                 xcb_grab_keyboard_cookie_t kbgrabc =
                     xcb_grab_keyboard(HostX.conn,
                                       TRUE,
-                                      host_screen->win,
+                                      scrpriv->win,
                                       XCB_TIME_CURRENT_TIME,
                                       XCB_GRAB_MODE_ASYNC,
                                       XCB_GRAB_MODE_ASYNC);
@@ -1046,11 +1009,11 @@ hostx_get_event(EphyrHostXEvent * ev)
                 xcb_grab_pointer_cookie_t pgrabc =
                     xcb_grab_pointer(HostX.conn,
                                      TRUE,
-                                     host_screen->win,
+                                     scrpriv->win,
                                      0,
                                      XCB_GRAB_MODE_ASYNC,
                                      XCB_GRAB_MODE_ASYNC,
-                                     host_screen->win,
+                                     scrpriv->win,
                                      XCB_NONE,
                                      XCB_TIME_CURRENT_TIME);
                 xcb_grab_pointer_reply_t *pgrabr;
@@ -1065,9 +1028,9 @@ hostx_get_event(EphyrHostXEvent * ev)
                             xcb_ungrab_keyboard(HostX.conn,
                                                 XCB_TIME_CURRENT_TIME);
                         } else {
-                        grabbed_screen = host_screen->mynum;
+                        grabbed_screen = scrpriv->mynum;
                         hostx_set_win_title
-                            (host_screen->screen,
+                            (screen,
                              "(ctrl+shift releases mouse and keyboard)");
                     }
                 }
@@ -1087,14 +1050,13 @@ hostx_get_event(EphyrHostXEvent * ev)
 
     case ConfigureNotify:
         {
-            struct EphyrHostScreen *host_screen;
             xcb_configure_notify_event_t *configure =
                 (xcb_configure_notify_event_t *)xev;
+            KdScreenInfo *screen = screen_from_window(configure->window);
+            EphyrScrPriv *scrpriv = screen->driver;
 
-            host_screen = host_screen_from_window(configure->window);
-
-            if (!host_screen ||
-                (host_screen->win_pre_existing == None && !EphyrWantResize)) {
+            if (!scrpriv ||
+                (scrpriv->win_pre_existing == None && !EphyrWantResize)) {
                 free(xev);
                 return 0;
             }
@@ -1103,7 +1065,7 @@ hostx_get_event(EphyrHostXEvent * ev)
             ev->data.configure.width = configure->width;
             ev->data.configure.height = configure->height;
             ev->data.configure.window = configure->window;
-            ev->data.configure.screen = host_screen->mynum;
+            ev->data.configure.screen = scrpriv->mynum;
             free(xev);
 
             return 1;
@@ -1131,11 +1093,13 @@ hostx_get_screen(void)
 int
 hostx_get_window(int a_screen_number)
 {
+    EphyrScrPriv *scrpriv;
     if (a_screen_number < 0 || a_screen_number >= HostX.n_screens) {
         EPHYR_LOG_ERROR("bad screen number:%d\n", a_screen_number);
         return 0;
     }
-    return HostX.screens[a_screen_number].win;
+    scrpriv = HostX.screens[a_screen_number]->driver;
+    return scrpriv->win;
 }
 
 int
@@ -1228,6 +1192,8 @@ hostx_create_window(int a_screen_number,
     xcb_screen_t *screen = xcb_aux_get_screen(HostX.conn, hostx_get_screen());
     xcb_visualtype_t *visual;
     int depth = 0;
+    EphyrScrPriv *scrpriv = HostX.screens[a_screen_number]->driver;
+
     EPHYR_RETURN_VAL_IF_FAIL(screen && a_geometry, FALSE);
 
     EPHYR_LOG("enter\n");
@@ -1264,8 +1230,8 @@ hostx_create_window(int a_screen_number,
                       XCB_WINDOW_CLASS_COPY_FROM_PARENT,
                       a_visual_id, winmask, attrs);
 
-    if (HostX.screens[a_screen_number].peer_win == XCB_NONE) {
-        HostX.screens[a_screen_number].peer_win = win;
+    if (scrpriv->peer_win == XCB_NONE) {
+        scrpriv->peer_win = win;
     }
     else {
         EPHYR_LOG_ERROR("multiple peer windows created for same screen\n");
diff --git a/hw/kdrive/ephyr/hostx.h b/hw/kdrive/ephyr/hostx.h
index b582e66..8018f94 100644
--- a/hw/kdrive/ephyr/hostx.h
+++ b/hw/kdrive/ephyr/hostx.h
@@ -177,9 +177,6 @@ int
 int
 hostx_get_server_depth(KdScreenInfo *screen);
 
-void
-hostx_set_server_depth(KdScreenInfo *screen, int depth);
-
 int
 hostx_get_bpp(KdScreenInfo *screen);
 
commit 8dadc78e233f341f1ecb8d404de03d98ab210620
Author: Eric Anholt <eric at anholt.net>
Date:   Sun Aug 18 16:45:06 2013 +0200

    ephyr: Rename and use the proper type for what was host_screen->info.
    
    Now that we can include server headers in talking to host X, we don't
    need to hide any more.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index 3715956..6d780cd 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -54,6 +54,7 @@
 #include <xcb/glx.h>
 #endif /* XF86DRI */
 #include "ephyrlog.h"
+#include "ephyr.h"
 
 struct EphyrHostScreen {
     Window win;
@@ -65,7 +66,7 @@ struct EphyrHostScreen {
     unsigned char *fb_data;     /* only used when host bpp != server bpp */
     xcb_shm_segment_info_t shminfo;
 
-    void *info;                 /* Pointer to the screen this is associated with */
+    KdScreenInfo *screen;
     int mynum;                  /* Screen number */
 };
 
@@ -111,12 +112,12 @@ static void
 #define host_depth_matches_server(_vars) (HostX.depth == (_vars)->server_depth)
 
 static struct EphyrHostScreen *
-host_screen_from_screen_info(EphyrScreenInfo * screen)
+host_screen_from_screen_info(KdScreenInfo *screen)
 {
     int i;
 
     for (i = 0; i < HostX.n_screens; i++) {
-        if (HostX.screens[i].info == screen) {
+        if (HostX.screens[i].screen == screen) {
             return &HostX.screens[i];
         }
     }
@@ -124,7 +125,7 @@ host_screen_from_screen_info(EphyrScreenInfo * screen)
 }
 
 int
-hostx_want_screen_size(EphyrScreenInfo screen, int *width, int *height)
+hostx_want_screen_size(KdScreenInfo *screen, int *width, int *height)
 {
     struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
 
@@ -140,7 +141,7 @@ hostx_want_screen_size(EphyrScreenInfo screen, int *width, int *height)
 }
 
 void
-hostx_add_screen(EphyrScreenInfo screen, unsigned long win_id, int screen_num)
+hostx_add_screen(KdScreenInfo *screen, unsigned long win_id, int screen_num)
 {
     int index = HostX.n_screens;
 
@@ -149,7 +150,7 @@ hostx_add_screen(EphyrScreenInfo screen, unsigned long win_id, int screen_num)
                             HostX.n_screens * sizeof(struct EphyrHostScreen));
     memset(&HostX.screens[index], 0, sizeof(struct EphyrHostScreen));
 
-    HostX.screens[index].info = screen;
+    HostX.screens[index].screen = screen;
     HostX.screens[index].win_pre_existing = win_id;
 }
 
@@ -160,18 +161,18 @@ hostx_set_display_name(char *name)
 }
 
 void
-hostx_set_screen_number(EphyrScreenInfo screen, int number)
+hostx_set_screen_number(KdScreenInfo *screen, int number)
 {
     struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
 
     if (host_screen) {
         host_screen->mynum = number;
-        hostx_set_win_title(host_screen->info, "");
+        hostx_set_win_title(host_screen->screen, "");
     }
 }
 
 void
-hostx_set_win_title(EphyrScreenInfo screen, const char *extra_text)
+hostx_set_win_title(KdScreenInfo *screen, const char *extra_text)
 {
     struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
 
@@ -216,7 +217,7 @@ hostx_use_host_cursor(void)
 }
 
 int
-hostx_want_preexisting_window(EphyrScreenInfo screen)
+hostx_want_preexisting_window(KdScreenInfo *screen)
 {
     struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
 
@@ -401,7 +402,7 @@ hostx_init(void)
                               XCB_CW_EVENT_MASK,
                               &attr);
 
-            hostx_set_win_title (host_screen->info,
+            hostx_set_win_title (host_screen->screen,
                                  "(ctrl+shift grabs mouse and keyboard)");
 
             if (HostX.use_fullscreen) {
@@ -535,7 +536,7 @@ hostx_get_depth(void)
 }
 
 int
-hostx_get_server_depth(EphyrScreenInfo screen)
+hostx_get_server_depth(KdScreenInfo *screen)
 {
     struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
 
@@ -543,7 +544,7 @@ hostx_get_server_depth(EphyrScreenInfo screen)
 }
 
 void
-hostx_set_server_depth(EphyrScreenInfo screen, int depth)
+hostx_set_server_depth(KdScreenInfo *screen, int depth)
 {
     struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
 
@@ -552,7 +553,7 @@ hostx_set_server_depth(EphyrScreenInfo screen, int depth)
 }
 
 int
-hostx_get_bpp(EphyrScreenInfo screen)
+hostx_get_bpp(KdScreenInfo *screen)
 {
     struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
 
@@ -566,7 +567,7 @@ hostx_get_bpp(EphyrScreenInfo screen)
 }
 
 void
-hostx_get_visual_masks(EphyrScreenInfo screen,
+hostx_get_visual_masks(KdScreenInfo *screen,
                        CARD32 *rmsk, CARD32 *gmsk, CARD32 *bmsk)
 {
     struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
@@ -640,7 +641,7 @@ hostx_set_cmap_entry(unsigned char idx,
  * by fakexa for storing offscreen pixmap data.
  */
 void *
-hostx_screen_init(EphyrScreenInfo screen,
+hostx_screen_init(KdScreenInfo *screen,
                   int width, int height, int buffer_height,
                   int *bytes_per_line, int *bits_per_pixel)
 {
@@ -763,7 +764,7 @@ static void hostx_paint_debug_rect(struct EphyrHostScreen *host_screen,
                                    int x, int y, int width, int height);
 
 void
-hostx_paint_rect(EphyrScreenInfo screen,
+hostx_paint_rect(KdScreenInfo *screen,
                  int sx, int sy, int dx, int dy, int width, int height)
 {
     struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
@@ -957,7 +958,7 @@ hostx_get_event(EphyrHostXEvent * ev)
             break;
 
         if (host_screen) {
-            hostx_paint_rect(host_screen->info, 0, 0, 0, 0,
+            hostx_paint_rect(host_screen->screen, 0, 0, 0, 0,
                              host_screen->win_width,
                              host_screen->win_height);
         }
@@ -1029,7 +1030,7 @@ hostx_get_event(EphyrHostXEvent * ev)
                 xcb_ungrab_keyboard(HostX.conn, XCB_TIME_CURRENT_TIME);
                 xcb_ungrab_pointer(HostX.conn, XCB_TIME_CURRENT_TIME);
                 grabbed_screen = -1;
-                hostx_set_win_title(host_screen->info,
+                hostx_set_win_title(host_screen->screen,
                                     "(ctrl+shift grabs mouse and keyboard)");
             }
             else {
@@ -1066,7 +1067,7 @@ hostx_get_event(EphyrHostXEvent * ev)
                         } else {
                         grabbed_screen = host_screen->mynum;
                         hostx_set_win_title
-                            (host_screen->info,
+                            (host_screen->screen,
                              "(ctrl+shift releases mouse and keyboard)");
                     }
                 }
diff --git a/hw/kdrive/ephyr/hostx.h b/hw/kdrive/ephyr/hostx.h
index 625ca8a..b582e66 100644
--- a/hw/kdrive/ephyr/hostx.h
+++ b/hw/kdrive/ephyr/hostx.h
@@ -29,6 +29,7 @@
 #include <X11/X.h>
 #include <X11/Xmd.h>
 #include <xcb/xcb.h>
+#include "ephyr.h"
 
 #define EPHYR_WANT_DEBUG 0
 
@@ -41,7 +42,6 @@
 
 typedef struct EphyrHostXVars EphyrHostXVars;
 typedef struct EphyrHostXEvent EphyrHostXEvent;
-typedef void *EphyrScreenInfo;
 typedef enum EphyrHostXEventType {
     EPHYR_EV_MOUSE_MOTION,
     EPHYR_EV_MOUSE_PRESS,
@@ -127,7 +127,7 @@ typedef struct {
 } EphyrRect;
 
 int
- hostx_want_screen_size(EphyrScreenInfo screen, int *width, int *height);
+hostx_want_screen_size(KdScreenInfo *screen, int *width, int *height);
 
 int
  hostx_want_host_cursor(void);
@@ -142,7 +142,7 @@ int
  hostx_want_fullscreen(void);
 
 int
- hostx_want_preexisting_window(EphyrScreenInfo screen);
+hostx_want_preexisting_window(KdScreenInfo *screen);
 
 void
  hostx_use_preexisting_window(unsigned long win_id);
@@ -160,43 +160,43 @@ int
  hostx_init(void);
 
 void
- hostx_add_screen(EphyrScreenInfo screen, unsigned long win_id, int screen_num);
+hostx_add_screen(KdScreenInfo *screen, unsigned long win_id, int screen_num);
 
 void
  hostx_set_display_name(char *name);
 
 void
- hostx_set_screen_number(EphyrScreenInfo screen, int number);
+hostx_set_screen_number(KdScreenInfo *screen, int number);
 
 void
- hostx_set_win_title(EphyrScreenInfo screen, const char *extra_text);
+hostx_set_win_title(KdScreenInfo *screen, const char *extra_text);
 
 int
  hostx_get_depth(void);
 
 int
- hostx_get_server_depth(EphyrScreenInfo screen);
+hostx_get_server_depth(KdScreenInfo *screen);
 
 void
- hostx_set_server_depth(EphyrScreenInfo screen, int depth);
+hostx_set_server_depth(KdScreenInfo *screen, int depth);
 
 int
- hostx_get_bpp(void *info);
+hostx_get_bpp(KdScreenInfo *screen);
 
 void
- hostx_get_visual_masks(void *info, CARD32 *rmsk, CARD32 *gmsk, CARD32 *bmsk);
+hostx_get_visual_masks(KdScreenInfo *screen,
+                       CARD32 *rmsk, CARD32 *gmsk, CARD32 *bmsk);
 void
 
 hostx_set_cmap_entry(unsigned char idx,
                      unsigned char r, unsigned char g, unsigned char b);
 
-void *hostx_screen_init(EphyrScreenInfo screen,
+void *hostx_screen_init(KdScreenInfo *screen,
                         int width, int height, int buffer_height,
                         int *bytes_per_line, int *bits_per_pixel);
 
 void
-
-hostx_paint_rect(EphyrScreenInfo screen,
+hostx_paint_rect(KdScreenInfo *screen,
                  int sx, int sy, int dx, int dy, int width, int height);
 
 void
commit 18d836f6dde46bcac8b794d34f76032688c28851
Author: Eric Anholt <eric at anholt.net>
Date:   Sun Aug 18 14:12:45 2013 +0200

    ephyr: Expose a single function for detecting extensions.
    
    v2: Fix trying to include xcb-dri in the non-dri-build case (Noted by
        Julien)
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index b34b5cc..003ef21 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -26,6 +26,7 @@
 #ifdef HAVE_CONFIG_H
 #include <kdrive-config.h>
 #endif
+
 #include "ephyr.h"
 
 #include "inputstr.h"
@@ -33,6 +34,7 @@
 #include "ephyrlog.h"
 
 #ifdef XF86DRI
+#include <xcb/xf86dri.h>
 #include "ephyrdri.h"
 #include "ephyrdriext.h"
 #include "ephyrglxext.h"
@@ -59,6 +61,16 @@ Bool EphyrWantGrayScale = 0;
 Bool EphyrWantResize = 0;
 
 Bool
+host_has_extension(xcb_extension_t *extension)
+{
+    const xcb_query_extension_reply_t *rep;
+
+    rep = xcb_get_extension_data(hostx_get_xcbconn(), extension);
+
+    return rep && rep->present;
+}
+
+Bool
 ephyrInitialize(KdCardInfo * card, EphyrPriv * priv)
 {
     OsSignal(SIGUSR1, hostx_handle_signal);
@@ -657,7 +669,7 @@ ephyrInitScreen(ScreenPtr pScreen)
     }
 #endif /*XV*/
 #ifdef XF86DRI
-    if (!ephyrNoDRI && !hostx_has_dri()) {
+    if (!ephyrNoDRI && !host_has_extension(&xcb_xf86dri_id)) {
         EPHYR_LOG("host x does not support DRI. Disabling DRI forwarding\n");
         ephyrNoDRI = TRUE;
     }
diff --git a/hw/kdrive/ephyr/ephyrdriext.c b/hw/kdrive/ephyr/ephyrdriext.c
index 617ffb1..13df60a 100644
--- a/hw/kdrive/ephyr/ephyrdriext.c
+++ b/hw/kdrive/ephyr/ephyrdriext.c
@@ -39,6 +39,9 @@
 #define _XF86DRI_SERVER_
 #include <X11/dri/xf86dri.h>
 #include <X11/dri/xf86driproto.h>
+#include <xcb/xcb.h>
+#include <xcb/shape.h>
+#include <xcb/xf86dri.h>
 #include "misc.h"
 #include "privates.h"
 #include "dixstruct.h"
@@ -1319,12 +1322,12 @@ ephyrDRIExtensionInit(ScreenPtr a_screen)
     EphyrDRIScreenPrivPtr screen_priv = NULL;
 
     EPHYR_LOG("enter\n");
-    if (!hostx_has_dri()) {
+    if (!host_has_extension(&xcb_xf86dri_id)) {
         EPHYR_LOG("host does not have DRI extension\n");
         goto out;
     }
     EPHYR_LOG("host X does have DRI extension\n");
-    if (!hostx_has_xshape()) {
+    if (!host_has_extension(&xcb_shape_id)) {
         EPHYR_LOG("host does not have XShape extension\n");
         goto out;
     }
diff --git a/hw/kdrive/ephyr/ephyrglxext.c b/hw/kdrive/ephyr/ephyrglxext.c
index 1231b0d..632a9c4 100644
--- a/hw/kdrive/ephyr/ephyrglxext.c
+++ b/hw/kdrive/ephyr/ephyrglxext.c
@@ -29,6 +29,7 @@
 #include <kdrive-config.h>
 #endif
 
+#include <xcb/glx.h>
 #include "extnsionst.h"
 #include "ephyrglxext.h"
 #include "ephyrhostglx.h"
@@ -83,7 +84,7 @@ ephyrHijackGLXExtension(void)
 {
     const void *(*dispatch_functions)[2];
 
-    if (!hostx_has_glx()) {
+    if (!host_has_extension(&xcb_glx_id)) {
         EPHYR_LOG("host X does not have GLX\n");
         return FALSE;
     }
diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index 97b2dc0..3715956 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -1390,15 +1390,6 @@ out:
     return is_ok;
 }
 
-int
-hostx_has_xshape(void)
-{
-    const xcb_query_extension_reply_t *rep;
-
-    rep = xcb_get_extension_data(HostX.conn, &xcb_shape_id);
-    return rep && rep->present;
-}
-
 #ifdef XF86DRI
 typedef struct {
     int is_valid;
@@ -1471,24 +1462,4 @@ hostx_get_resource_id_peer(int a_local_resource_id, int *a_remote_resource_id)
     return FALSE;
 }
 
-int
-hostx_has_dri(void)
-{
-    const xcb_query_extension_reply_t *dri;
-
-    dri = xcb_get_extension_data(HostX.conn, &xcb_xf86dri_id);
-
-    return dri && dri->present;
-}
-
-int
-hostx_has_glx(void)
-{
-    const xcb_query_extension_reply_t *glx;
-
-    glx = xcb_get_extension_data(HostX.conn, &xcb_glx_id);
-
-    return glx && glx->present;
-}
-
 #endif                          /* XF86DRI */
diff --git a/hw/kdrive/ephyr/hostx.h b/hw/kdrive/ephyr/hostx.h
index 3276eb1..625ca8a 100644
--- a/hw/kdrive/ephyr/hostx.h
+++ b/hw/kdrive/ephyr/hostx.h
@@ -233,7 +233,8 @@ int hostx_set_window_bounding_rectangles(int a_window,
 
 int hostx_set_window_clipping_rectangles(int a_window,
                                          EphyrRect * a_rects, int a_num_rects);
-int hostx_has_xshape(void);
+
+int host_has_extension(xcb_extension_t *extension);
 
 #ifdef XF86DRI
 int hostx_lookup_peer_window(void *a_local_window,
commit 3aacb22d6473480c31fb08f0b2527747dbf5be57
Author: Eric Anholt <eric at anholt.net>
Date:   Sun Aug 18 14:01:53 2013 +0200

    ephyr: Drop dead ephyrHostAtomToLocal code.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/ephyrvideo.c b/hw/kdrive/ephyr/ephyrvideo.c
index 345c7b9..5813634 100644
--- a/hw/kdrive/ephyr/ephyrvideo.c
+++ b/hw/kdrive/ephyr/ephyrvideo.c
@@ -62,10 +62,6 @@ static Bool DoSimpleClip(BoxPtr a_dst_drw, BoxPtr a_clipper, BoxPtr a_result);
 
 static Bool ephyrLocalAtomToHost(int a_local_atom, int *a_host_atom);
 
-/*
-static Bool ephyrHostAtomToLocal (int a_host_atom, int *a_local_atom) ;
-*/
-
 static EphyrXVPriv *ephyrXVPrivNew(void);
 static void ephyrXVPrivDelete(EphyrXVPriv * a_this);
 static Bool ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this);
@@ -240,36 +236,6 @@ ephyrLocalAtomToHost(int a_local_atom, int *a_host_atom)
     return TRUE;
 }
 
-/*
- Not used yed.
-static Bool
-ephyrHostAtomToLocal (int a_host_atom, int *a_local_atom)
-{
-    Bool is_ok=FALSE ;
-    char *atom_name=NULL ;
-    int atom=None ;
-
-    EPHYR_RETURN_VAL_IF_FAIL (a_local_atom, FALSE) ;
-
-    atom_name = ephyrHostGetAtomName (a_host_atom) ;
-    if (!atom_name)
-        goto out ;
-
-    atom = MakeAtom (atom_name, strlen (atom_name), TRUE) ;
-    if (atom == None)
-        goto out ;
-
-    *a_local_atom = atom ;
-    is_ok = TRUE ;
-
-out:
-    if (atom_name) {
-        ephyrHostFree (atom_name) ;
-    }
-    return is_ok ;
-}
-*/
-
 /**************
  *</helpers>
  * ************/
commit 4aaad0bfbcef018eb36839b1d034c3f60022694a
Author: Julien Cristau <jcristau at debian.org>
Date:   Wed Oct 20 20:10:43 2010 +0200

    Xephyr: we're not using Xlib anymore, no need to undef _XSERVER64
    
    Drop obsolete comments about interaction between Xlib code and that
    macro, and stop undefining it.
    
    Signed-off-by: Julien Cristau <jcristau at debian.org>
    Reviewed-by: Eric Anholt <eric at anholt.net>

diff --git a/hw/kdrive/ephyr/ephyrhostglx.c b/hw/kdrive/ephyr/ephyrhostglx.c
index a115866..007524d 100644
--- a/hw/kdrive/ephyr/ephyrhostglx.c
+++ b/hw/kdrive/ephyr/ephyrhostglx.c
@@ -31,17 +31,6 @@
 #include <kdrive-config.h>
 #endif
 
-/*
- * including some server headers (like kdrive-config.h)
- * might define the macro _XSERVER64
- * on 64 bits machines. That macro must _NOT_ be defined for Xlib
- * client code, otherwise bad things happen.
- * So let's undef that macro if necessary.
- */
-#ifdef _XSERVER64
-#undef _XSERVER64
-#endif
-
 #include <X11/Xdefs.h>
 #include <X11/Xmd.h>
 #include <GL/glxproto.h>
diff --git a/hw/kdrive/ephyr/ephyrhostvideo.c b/hw/kdrive/ephyr/ephyrhostvideo.c
index 8b71687..ea5fc9b 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.c
+++ b/hw/kdrive/ephyr/ephyrhostvideo.c
@@ -28,16 +28,6 @@
 #ifdef HAVE_CONFIG_H
 #include <kdrive-config.h>
 #endif
-/*
- * including some server headers (like kdrive-config.h)
- * might define the macro _XSERVER64
- * on 64 bits machines. That macro must _NOT_ be defined for Xlib
- * client code, otherwise bad things happen.
- * So let's undef that macro if necessary.
- */
-#ifdef _XSERVER64
-#undef _XSERVER64
-#endif
 #include <xcb/xv.h>
 #include <xcb/xcb_aux.h>
 #define _HAVE_XALLOC_DECLS
diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index 1eef64e..97b2dc0 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -27,17 +27,6 @@
 #include <kdrive-config.h>
 #endif
 
-/*
- * including some server headers (like kdrive-config.h)
- * might define the macro _XSERVER64
- * on 64 bits machines. That macro must _NOT_ be defined for Xlib
- * client code, otherwise bad things happen.
- * So let's undef that macro if necessary.
- */
-#ifdef _XSERVER64
-#undef _XSERVER64
-#endif
-
 #include "hostx.h"
 
 #include <stdlib.h>
@@ -66,12 +55,6 @@
 #endif /* XF86DRI */
 #include "ephyrlog.h"
 
-/*  
- * All xlib calls go here, which gets built as its own .a .
- * Mixing kdrive and xlib headers causes all sorts of types
- * to get clobbered. 
- */
-
 struct EphyrHostScreen {
     Window win;
     Window win_pre_existing;    /* Set via -parent option like xnest */
commit 0fc2f9f04a44599f598380d4df992bec60c0e3a1
Author: Julien Cristau <jcristau at debian.org>
Date:   Sat Sep 25 16:05:07 2010 +0200

    Xephyr: handle errors in event loop
    
    Signed-off-by: Julien Cristau <jcristau at debian.org>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>

diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index 68bb48a..1eef64e 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -947,6 +947,21 @@ hostx_get_event(EphyrHostXEvent * ev)
     }
 
     switch (xev->response_type & 0x7f) {
+    case 0: { /* error */
+        xcb_generic_error_t *e = (xcb_generic_error_t *)xev;
+        fprintf(stderr, "X11 error\n"
+                "Error code: %hhu\n"
+                "Sequence number: %hu\n"
+                "Major code: %hhu\tMinor code: %hu\n"
+                "Error value: %u\n",
+                e->error_code,
+                e->sequence,
+                e->major_code, e->minor_code,
+                e->resource_id);
+        free(xev);
+        exit(1);
+    }
+
     case XCB_EXPOSE: {
         xcb_expose_event_t *expose = (xcb_expose_event_t *)xev;
         struct EphyrHostScreen *host_screen =
commit 3309a73c826f02c4b2e14180a3254546314ec323
Author: Julien Cristau <jcristau at debian.org>
Date:   Fri Jun 25 14:20:57 2010 +0100

    Xephyr: drop remaining Xlib dependency
    
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Julien Cristau <jcristau at debian.org>

diff --git a/configure.ac b/configure.ac
index a6c466e..8c72cc0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2116,12 +2116,12 @@ if test "$KDRIVE" = yes; then
        AC_DEFINE(KDRIVE_MOUSE, 1, [Enable KDrive mouse driver])
     fi
 
-    XEPHYR_REQUIRED_LIBS="x11 >= 1.6 $LIBXEXT xau xdmcp xcb x11-xcb xcb-shape xcb-aux xcb-image xcb-icccm xcb-shm xcb-keysyms"
+    XEPHYR_REQUIRED_LIBS="xau xdmcp xcb xcb-shape xcb-aux xcb-image xcb-icccm xcb-shm xcb-keysyms"
     if test "x$XV" = xyes; 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 > 1.6"
+        XEPHYR_REQUIRED_LIBS="$XEPHYR_REQUIRED_LIBS libdrm xcb-glx xcb-xf86dri > 1.6"
     fi
 
     if test "x$XEPHYR" = xauto; then
diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index 07a2772..68bb48a 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -51,12 +51,9 @@
 #include <sys/shm.h>
 #include <sys/time.h>
 
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
 #include <X11/keysym.h>
 #include <xcb/xcb.h>
 #include <xcb/xproto.h>
-#include <X11/Xlib-xcb.h>
 #include <xcb/xcb_icccm.h>
 #include <xcb/xcb_aux.h>
 #include <xcb/shm.h>
@@ -91,7 +88,6 @@ struct EphyrHostScreen {
 
 struct EphyrHostXVars {
     char *server_dpy_name;
-    Display *dpy;
     xcb_connection_t *conn;
     int screen;
     xcb_visualtype_t *visual;
@@ -151,7 +147,7 @@ hostx_want_screen_size(EphyrScreenInfo screen, int *width, int *height)
 
     if (host_screen &&
         (host_screen->win_pre_existing != None ||
-         HostX.use_fullscreen == True)) {
+         HostX.use_fullscreen == TRUE)) {
         *width = host_screen->win_width;
         *height = host_screen->win_height;
         return 1;
@@ -233,7 +229,7 @@ hostx_want_host_cursor(void)
 void
 hostx_use_host_cursor(void)
 {
-    HostX.use_host_cursor = True;
+    HostX.use_host_cursor = TRUE;
 }
 
 int
@@ -252,7 +248,7 @@ hostx_want_preexisting_window(EphyrScreenInfo screen)
 void
 hostx_use_fullscreen(void)
 {
-    HostX.use_fullscreen = True;
+    HostX.use_fullscreen = TRUE;
 }
 
 int
@@ -323,15 +319,6 @@ hostx_set_title(char *title)
 #pragma does_not_return(exit)
 #endif
 
-static int _X_NORETURN
-x_io_error_handler(Display * dpy)
-{
-    ErrorF("Lost connection to X server: %s\n", strerror(errno));
-    CloseWellKnownConnections();
-    OsCleanup(1);
-    exit(1);
-}
-
 int
 hostx_init(void)
 {
@@ -358,15 +345,11 @@ hostx_init(void)
 
     EPHYR_DBG("mark");
 
-    if ((HostX.dpy = XOpenDisplay(getenv("DISPLAY"))) == NULL) {
+    if ((HostX.conn = xcb_connect(NULL, &HostX.screen)) == NULL) {
         fprintf(stderr, "\nXephyr cannot open host display. Is DISPLAY set?\n");
         exit(1);
     }
 
-    XSetIOErrorHandler(x_io_error_handler);
-
-    HostX.conn = XGetXCBConnection(HostX.dpy);
-    HostX.screen = DefaultScreen(HostX.dpy);
     screen = xcb_aux_get_screen(HostX.conn, HostX.screen);
     HostX.winroot = screen->root;
     HostX.gc = xcb_generate_id(HostX.conn);
@@ -374,11 +357,11 @@ hostx_init(void)
     HostX.visual  = xcb_aux_find_visual_by_id(screen, screen->root_visual);
 
     xcb_create_gc(HostX.conn, HostX.gc, HostX.winroot, 0, NULL);
-    cookie_WINDOW_STATE = xcb_intern_atom(HostX.conn, False,
+    cookie_WINDOW_STATE = xcb_intern_atom(HostX.conn, FALSE,
                                           strlen("_NET_WM_STATE"),
                                           "_NET_WM_STATE");
     cookie_WINDOW_STATE_FULLSCREEN =
-        xcb_intern_atom(HostX.conn, False,
+        xcb_intern_atom(HostX.conn, FALSE,
                         strlen("_NET_WM_STATE_FULLSCREEN"),
                         "_NET_WM_STATE_FULLSCREEN");
 
@@ -519,7 +502,7 @@ hostx_init(void)
     shm_rep = xcb_get_extension_data(HostX.conn, &xcb_shm_id);
     if (!shm_rep || !shm_rep->present || getenv("XEPHYR_NO_SHM")) {
         fprintf(stderr, "\nXephyr unable to use SHM XImages\n");
-        HostX.have_shm = False;
+        HostX.have_shm = FALSE;
     }
     else {
         /* Really really check we have shm - better way ?*/
@@ -528,19 +511,19 @@ hostx_init(void)
         xcb_void_cookie_t cookie;
         xcb_shm_seg_t shmseg;
 
-        HostX.have_shm = True;
+        HostX.have_shm = TRUE;
 
         shminfo.shmid = shmget(IPC_PRIVATE, 1, IPC_CREAT|0777);
         shminfo.shmaddr = shmat(shminfo.shmid,0,0);
 
         shmseg = xcb_generate_id(HostX.conn);
         cookie = xcb_shm_attach_checked(HostX.conn, shmseg, shminfo.shmid,
-                                        True);
+                                        TRUE);
         e = xcb_request_check(HostX.conn, cookie);
 
         if (e) {
             fprintf(stderr, "\nXephyr unable to use SHM XImages\n");
-            HostX.have_shm = False;
+            HostX.have_shm = FALSE;
             free(e);
         }
 
@@ -678,7 +661,7 @@ hostx_screen_init(EphyrScreenInfo screen,
                   int width, int height, int buffer_height,
                   int *bytes_per_line, int *bits_per_pixel)
 {
-    Bool shm_success = False;
+    Bool shm_success = FALSE;
 
     struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
 
@@ -729,7 +712,7 @@ hostx_screen_init(EphyrScreenInfo screen,
         if (host_screen->ximg->data == (uint8_t *) -1) {
             EPHYR_DBG
                 ("Can't attach SHM Segment, falling back to plain XImages");
-            HostX.have_shm = False;
+            HostX.have_shm = FALSE;
             xcb_image_destroy (host_screen->ximg);
             shmctl(host_screen->shminfo.shmid, IPC_RMID, 0);
         }
@@ -739,8 +722,8 @@ hostx_screen_init(EphyrScreenInfo screen,
             xcb_shm_attach(HostX.conn,
                            host_screen->shminfo.shmseg,
                            host_screen->shminfo.shmid,
-                           False);
-            shm_success = True;
+                           FALSE);
+            shm_success = TRUE;
         }
     }
 
@@ -870,7 +853,7 @@ hostx_paint_rect(EphyrScreenInfo screen,
         xcb_image_shm_put(HostX.conn, host_screen->win,
                           HostX.gc, host_screen->ximg,
                           host_screen->shminfo,
-                          sx, sy, dx, dy, width, height, False);
+                          sx, sy, dx, dy, width, height, FALSE);
     }
     else {
         xcb_image_put(HostX.conn, host_screen->win, HostX.gc, host_screen->ximg,
@@ -1055,7 +1038,7 @@ hostx_get_event(EphyrHostXEvent * ev)
                 /* Attempt grab */
                 xcb_grab_keyboard_cookie_t kbgrabc =
                     xcb_grab_keyboard(HostX.conn,
-                                      True,
+                                      TRUE,
                                       host_screen->win,
                                       XCB_TIME_CURRENT_TIME,
                                       XCB_GRAB_MODE_ASYNC,
@@ -1063,7 +1046,7 @@ hostx_get_event(EphyrHostXEvent * ev)
                 xcb_grab_keyboard_reply_t *kbgrabr;
                 xcb_grab_pointer_cookie_t pgrabc =
                     xcb_grab_pointer(HostX.conn,
-                                     True,
+                                     TRUE,
                                      host_screen->win,
                                      0,
                                      XCB_GRAB_MODE_ASYNC,
@@ -1134,12 +1117,6 @@ hostx_get_event(EphyrHostXEvent * ev)
     return 0;
 }
 
-void *
-hostx_get_display(void)
-{
-    return HostX.dpy;
-}
-
 xcb_connection_t *
 hostx_get_xcbconn(void)
 {
@@ -1189,13 +1166,13 @@ hostx_get_window_attributes(int a_window, EphyrHostWindowAttributes * a_attrs)
 int
 hostx_get_visuals_info(EphyrHostVisualInfo ** a_visuals, int *a_num_entries)
 {
-    Bool is_ok = False;
+    Bool is_ok = FALSE;
     EphyrHostVisualInfo *host_visuals = NULL;
     int nb_items = 0, i = 0, screen_num;
     xcb_screen_iterator_t screens;
     xcb_depth_iterator_t depths;
 
-    EPHYR_RETURN_VAL_IF_FAIL(a_visuals && a_num_entries, False);
+    EPHYR_RETURN_VAL_IF_FAIL(a_visuals && a_num_entries, FALSE);
     EPHYR_LOG("enter\n");
 
     screens = xcb_setup_roots_iterator(xcb_get_setup(HostX.conn));
@@ -1380,11 +1357,10 @@ hostx_set_window_clipping_rectangles(int a_window,
                                      EphyrRect * a_rects, int a_num_rects)
 {
     Bool is_ok = FALSE;
-    Display *dpy = hostx_get_display();
     int i = 0;
     xcb_rectangle_t *rects = NULL;
 
-    EPHYR_RETURN_VAL_IF_FAIL(dpy && a_rects, FALSE);
+    EPHYR_RETURN_VAL_IF_FAIL(a_rects, FALSE);
 
     EPHYR_LOG("enter. num rects:%d\n", a_num_rects);
 
diff --git a/hw/kdrive/ephyr/hostx.h b/hw/kdrive/ephyr/hostx.h
index 1c01f8b..3276eb1 100644
--- a/hw/kdrive/ephyr/hostx.h
+++ b/hw/kdrive/ephyr/hostx.h
@@ -205,8 +205,6 @@ void
 int
  hostx_get_event(EphyrHostXEvent * ev);
 
-void *hostx_get_display(void);
-
 xcb_connection_t *
 hostx_get_xcbconn(void);
 
commit 7da2174cf93f59b7e0372a6dc9d37a510076e187
Author: Julien Cristau <jcristau at debian.org>
Date:   Mon Jun 21 14:39:03 2010 +0100

    Xephyr: move glx code to xcb
    
    v2: Rebase on master, notably adding XCB for
        X_GLXvop_MakeCurrentReadSGI (anholt).
    v3: Fix use-after-free (caught by Julien).
    
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net> (v1)
    Signed-off-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/hw/kdrive/ephyr/ephyrglxext.c b/hw/kdrive/ephyr/ephyrglxext.c
index 22d5108..1231b0d 100644
--- a/hw/kdrive/ephyr/ephyrglxext.c
+++ b/hw/kdrive/ephyr/ephyrglxext.c
@@ -380,10 +380,9 @@ ephyrGLXQueryServerString(__GLXclientState * a_cl, GLbyte * a_pc)
     int length = 0;
 
     EPHYR_LOG("enter\n");
-    if (!ephyrHostGLXGetStringFromServer(req->screen,
-                                         req->name,
-                                         EPHYR_HOST_GLX_QueryServerString,
-                                         &server_string)) {
+    if (!ephyrHostGLXQueryServerString(req->screen,
+                                       req->name,
+                                       &server_string)) {
         EPHYR_LOG_ERROR("failed to query string from host\n");
         goto out;
     }
@@ -724,9 +723,7 @@ ephyrGLXGetStringReal(__GLXclientState * a_cl, GLbyte * a_pc, Bool a_do_swap)
     a_pc += __GLX_SINGLE_HDR_SIZE;
     name = *(GLenum *) (a_pc + 0);
     EPHYR_LOG("context_tag:%d, name:%d\n", context_tag, name);
-    if (!ephyrHostGLXGetStringFromServer(context_tag,
-                                         name,
-                                         EPHYR_HOST_GLX_GetString, &string)) {
+    if (!ephyrHostGLXGetString(context_tag, name, &string)) {
         EPHYR_LOG_ERROR("failed to get string from server\n");
         goto out;
     }
diff --git a/hw/kdrive/ephyr/ephyrhostglx.c b/hw/kdrive/ephyr/ephyrhostglx.c
index 5ecb02d..a115866 100644
--- a/hw/kdrive/ephyr/ephyrhostglx.c
+++ b/hw/kdrive/ephyr/ephyrhostglx.c
@@ -42,11 +42,10 @@
 #undef _XSERVER64
 #endif
 
-#include <X11/Xlibint.h>
-#include <GL/glx.h>
-#include <GL/internal/glcore.h>
+#include <X11/Xdefs.h>
+#include <X11/Xmd.h>
 #include <GL/glxproto.h>
-#include <GL/glxint.h>
+#include <xcb/glx.h>
 #include "ephyrhostglx.h"
 #define _HAVE_XALLOC_DECLS
 #include "ephyrlog.h"
@@ -62,41 +61,20 @@ enum VisualConfRequestType {
 
 static Bool ephyrHostGLXGetVisualConfigsInternal
     (enum VisualConfRequestType a_type,
+     xcb_glx_get_visual_configs_reply_t *reply,
      int32_t a_screen,
-     int32_t * a_num_visuals,
-     int32_t * a_num_props, int32_t * a_props_buf_size, int32_t ** a_props_buf);
-Bool
-ephyrHostGLXGetMajorOpcode(int *a_opcode)
-{
-    Bool is_ok = FALSE;
-    Display *dpy = hostx_get_display();
-    static int opcode;
-    int first_event_return = 0, first_error_return = 0;
-
-    EPHYR_RETURN_VAL_IF_FAIL(dpy, FALSE);
-    EPHYR_LOG("enter\n");
-    if (!opcode) {
-        if (!XQueryExtension(dpy, GLX_EXTENSION_NAME, &opcode,
-                             &first_event_return, &first_error_return)) {
-            EPHYR_LOG_ERROR("XQueryExtension() failed\n");
-            goto out;
-        }
-    }
-    *a_opcode = opcode;
-    is_ok = TRUE;
- out:
-    EPHYR_LOG("release\n");
-    return is_ok;
-}
+     int32_t *a_num_visuals,
+     int32_t *a_num_props,
+     int32_t *a_props_buf_size,
+     int32_t **a_props_buf);
 
 Bool
 ephyrHostGLXQueryVersion(int *a_major, int *a_minor)
 {
     Bool is_ok = FALSE;
-    Display *dpy = hostx_get_display();
-    int major_opcode = 0;
-    xGLXQueryVersionReq *req = NULL;
-    xGLXQueryVersionReply reply;
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    xcb_glx_query_version_cookie_t cookie;
+    xcb_glx_query_version_reply_t *reply;
 
     EPHYR_RETURN_VAL_IF_FAIL(a_major && a_minor, FALSE);
     EPHYR_LOG("enter\n");
@@ -107,26 +85,14 @@ ephyrHostGLXQueryVersion(int *a_major, int *a_minor)
         return TRUE;
     }
 
-    if (!ephyrHostGLXGetMajorOpcode(&major_opcode)) {
-        EPHYR_LOG_ERROR("failed to get major opcode\n");
-        goto out;
-    }
-    EPHYR_LOG("major opcode: %d\n", major_opcode);
-
     /* Send the glXQueryVersion request */
-    memset(&reply, 0, sizeof(reply));
-    LockDisplay(dpy);
-    GetReq(GLXQueryVersion, req);
-    req->reqType = major_opcode;
-    req->glxCode = X_GLXQueryVersion;
-    req->majorVersion = 2;
-    req->minorVersion = 1;
-    _XReply(dpy, (xReply *) &reply, 0, False);
-    UnlockDisplay(dpy);
-    SyncHandle();
-
-    *a_major = glx_major = reply.majorVersion;
-    *a_minor = glx_minor = reply.minorVersion;
+    cookie = xcb_glx_query_version(conn, 2, 1);
+    reply = xcb_glx_query_version_reply(conn, cookie, NULL);
+    if (!reply)
+        goto out;
+    *a_major = reply->major_version;
+    *a_minor = reply->minor_version;
+    free(reply);
 
     EPHYR_LOG("major:%d, minor:%d\n", *a_major, *a_minor);
 
@@ -136,129 +102,63 @@ ephyrHostGLXQueryVersion(int *a_major, int *a_minor)
     return is_ok;
 }
 
-/**
- * GLX protocol structure for the ficticious "GLXGenericGetString" request.
- * 
- * This is a non-existant protocol packet.  It just so happens that all of
- * the real protocol packets used to request a string from the server have
- * an identical binary layout.  The only difference between them is the
- * meaning of the \c for_whom field and the value of the \c glxCode.
- * (this has been copied from the mesa source code)
- */
-typedef struct GLXGenericGetString {
-    CARD8 reqType;
-    CARD8 glxCode;
-    CARD16 length B16;
-    CARD32 for_whom B32;
-    CARD32 name B32;
-} xGLXGenericGetStringReq;
-
-/* These defines are only needed to make the GetReq macro happy.
- */
-#define sz_xGLXGenericGetStringReq 12
-#define X_GLXGenericGetString 0
-
 Bool
-ephyrHostGLXGetStringFromServer(int a_screen_number,
-                                int a_string_name,
-                                enum EphyrHostGLXGetStringOps a_op,
-                                char **a_string)
+ephyrHostGLXGetString(int a_context_tag,
+                      int a_string_name,
+                      char **a_string)
 {
     Bool is_ok = FALSE;
-    Display *dpy = hostx_get_display();
-    int default_screen = DefaultScreen(dpy);
-    xGLXGenericGetStringReq *req = NULL;
-    xGLXSingleReply reply;
-    unsigned long length = 0, numbytes = 0;
-    int major_opcode = 0, get_string_op = 0;
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    xcb_glx_get_string_cookie_t cookie;
+    xcb_glx_get_string_reply_t *reply;
 
-    EPHYR_RETURN_VAL_IF_FAIL(dpy && a_string, FALSE);
+    EPHYR_RETURN_VAL_IF_FAIL(conn && a_string, FALSE);
 
     EPHYR_LOG("enter\n");
-    switch (a_op) {
-    case EPHYR_HOST_GLX_QueryServerString:
-        get_string_op = X_GLXQueryServerString;
-        break;
-    case EPHYR_HOST_GLX_GetString:
-        get_string_op = X_GLsop_GetString;
-        EPHYR_LOG("Going to glXGetString. strname:%#x, ctxttag:%d\n",
-                  a_string_name, a_screen_number);
-        break;
-    default:
-        EPHYR_LOG_ERROR("unknown EphyrHostGLXGetStringOp:%d\n", a_op);
-        goto out;
-    }
-
-    if (!ephyrHostGLXGetMajorOpcode(&major_opcode)) {
-        EPHYR_LOG_ERROR("failed to get major opcode\n");
+    cookie = xcb_glx_get_string(conn, a_context_tag, a_string_name);
+    reply = xcb_glx_get_string_reply(conn, cookie, NULL);
+    if (!reply)
         goto out;
-    }
-    EPHYR_LOG("major opcode: %d\n", major_opcode);
-
-    LockDisplay(dpy);
-
-    /* All of the GLX protocol requests for getting a string from the server
-     * look the same.  The exact meaning of the a_for_whom field is usually
-     * either the screen number (for glXQueryServerString) or the context tag
-     * (for GLXSingle).
-     */
-    GetReq(GLXGenericGetString, req);
-    req->reqType = major_opcode;
-    req->glxCode = get_string_op;
-    req->for_whom = default_screen;
-    req->name = a_string_name;
-
-    _XReply(dpy, (xReply *) &reply, 0, False);
-
-#if UINT32_MAX >= (ULONG_MAX / 4)
-    if (reply.length >= (ULONG_MAX / 4)) {
-        _XEatDataWords(dpy, reply.length);
-        goto eat_out;
-    }
-#endif
-    if (reply.length > 0) {
-        length = (unsigned long) reply.length * 4;
-        numbytes = reply.size;
-        if (numbytes > length) {
-            EPHYR_LOG_ERROR("string length %d longer than reply length %d\n",
-                            numbytes, length);
-            goto eat_out;
-        }
-    }
-    EPHYR_LOG("going to get a string of size:%d\n", numbytes);
-
-    if (numbytes < INT_MAX)
-        *a_string = Xcalloc(numbytes + 1, 1);
-    else
-        *a_string = NULL;
-    if (*a_string == NULL) {
-        EPHYR_LOG_ERROR("allocation failed\n");
-        goto eat_out;
-    }
+    *a_string = malloc(reply->n + 1);
+    memcpy(*a_string, xcb_glx_get_string_string(reply), reply->n);
+    (*a_string)[reply->n] = '\0';
+    free(reply);
+    is_ok = TRUE;
+out:
+    EPHYR_LOG("leave\n");
+    return is_ok;
+}
 
-    if (_XRead(dpy, *a_string, numbytes)) {
-        EPHYR_LOG_ERROR("read failed\n");
-        length = 0; /* if read failed, no idea how much to eat */
-    }
-    else {
-        length -= numbytes;
-        EPHYR_LOG("strname:%#x, strvalue:'%s', strlen:%d\n",
-                  a_string_name, *a_string, numbytes);
-        is_ok = TRUE;
-    }
+Bool ephyrHostGLXQueryServerString(int a_screen_number,
+                                   int a_string_name,
+                                   char **a_string)
+{
+    Bool is_ok = FALSE;
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    int default_screen = hostx_get_screen();
+    xcb_glx_query_server_string_cookie_t cookie;
+    xcb_glx_query_server_string_reply_t *reply;
 
- eat_out:
-    _XEatData(dpy, length);
-    UnlockDisplay(dpy);
-    SyncHandle();
+    EPHYR_RETURN_VAL_IF_FAIL(conn && a_string, FALSE);
 
- out:
+    EPHYR_LOG("enter\n");
+    cookie = xcb_glx_query_server_string(conn, default_screen, a_string_name);
+    reply = xcb_glx_query_server_string_reply(conn, cookie, NULL);
+    if (!reply)
+        goto out;
+    *a_string = malloc(reply->str_len + 1);
+    memcpy(*a_string, xcb_glx_query_server_string_string(reply), reply->str_len);
+    (*a_string)[reply->str_len] = '\0';
+    free(reply);
+    is_ok = TRUE;
+out:
     EPHYR_LOG("leave\n");
     return is_ok;
 }
 
 static Bool
 ephyrHostGLXGetVisualConfigsInternal(enum VisualConfRequestType a_type,
+                                     xcb_glx_get_visual_configs_reply_t *reply,
                                      int32_t a_screen,
                                      int32_t * a_num_visuals,
                                      int32_t * a_num_props,
@@ -266,110 +166,36 @@ ephyrHostGLXGetVisualConfigsInternal(enum VisualConfRequestType a_type,
                                      int32_t ** a_props_buf)
 {
     Bool is_ok = FALSE;
-    Display *dpy = hostx_get_display();
-    xGLXGetVisualConfigsReq *req;
-    xGLXGetFBConfigsReq *fb_req;
-    xGLXVendorPrivateWithReplyReq *vpreq;
-    xGLXGetFBConfigsSGIXReq *sgi_req;
-    xGLXGetVisualConfigsReply reply;
-    char *server_glx_version = NULL, *server_glx_extensions = NULL;
-    int j = 0,
-        major_opcode = 0,
-        num_props = 0,
-        num_visuals = 0, props_buf_size = 0, props_per_visual_size = 0;
+    int num_props = 0, num_visuals = 0, props_buf_size = 0;
+    int props_per_visual_size = 0;
     int32_t *props_buf = NULL;
 
-    EPHYR_RETURN_VAL_IF_FAIL(dpy, FALSE);
-
-    if (!ephyrHostGLXGetMajorOpcode(&major_opcode)) {
-        EPHYR_LOG_ERROR("failed to get opcode\n");
-        goto out;
-    }
-
-    LockDisplay(dpy);
-    switch (a_type) {
-    case EPHYR_GET_FB_CONFIG:
-        GetReq(GLXGetFBConfigs, fb_req);
-        fb_req->reqType = major_opcode;
-        fb_req->glxCode = X_GLXGetFBConfigs;
-        fb_req->screen = DefaultScreen(dpy);
-        break;
-
-    case EPHYR_VENDOR_PRIV_GET_FB_CONFIG_SGIX:
-        GetReqExtra(GLXVendorPrivateWithReply,
-                    sz_xGLXGetFBConfigsSGIXReq
-                    - sz_xGLXVendorPrivateWithReplyReq, vpreq);
-        sgi_req = (xGLXGetFBConfigsSGIXReq *) vpreq;
-        sgi_req->reqType = major_opcode;
-        sgi_req->glxCode = X_GLXVendorPrivateWithReply;
-        sgi_req->vendorCode = X_GLXvop_GetFBConfigsSGIX;
-        sgi_req->screen = DefaultScreen(dpy);
-        break;
-
-    case EPHYR_GET_VISUAL_CONFIGS:
-        GetReq(GLXGetVisualConfigs, req);
-        req->reqType = major_opcode;
-        req->glxCode = X_GLXGetVisualConfigs;
-        req->screen = DefaultScreen(dpy);
-        break;
-    }
-
-    if (!_XReply(dpy, (xReply *) &reply, 0, False)) {
-        EPHYR_LOG_ERROR("unknown error\n");
-        UnlockDisplay(dpy);
-        goto out;
-    }
-    if (!reply.numVisuals) {
+   if (!reply->num_visuals) {
         EPHYR_LOG_ERROR("screen does not support GL rendering\n");
-        UnlockDisplay(dpy);
-        goto out;
-    }
-    num_visuals = reply.numVisuals;
-
-    /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for
-     * FIXME: FBconfigs? 
-     */
-    /* Check number of properties */
-    num_props = reply.numProps;
-    if ((num_props < __GLX_MIN_CONFIG_PROPS) ||
-        (num_props > __GLX_MAX_CONFIG_PROPS)) {
-        /* Huh?  Not in protocol defined limits.  Punt */
-        EPHYR_LOG_ERROR("got a bad reply to request\n");
-        UnlockDisplay(dpy);
         goto out;
     }
+    num_visuals = reply->num_visuals;
+
+    num_props = reply->num_properties;
 
     if (a_type != EPHYR_GET_VISUAL_CONFIGS) {
         num_props *= 2;
     }
-    props_per_visual_size = num_props * __GLX_SIZE_INT32;
-    props_buf_size = props_per_visual_size * reply.numVisuals;
+    props_per_visual_size = num_props * sizeof(uint32_t);
+    props_buf_size = props_per_visual_size * reply->num_visuals;
     props_buf = malloc(props_buf_size);
-    for (j = 0; j < reply.numVisuals; j++) {
-        if (_XRead(dpy,
-                   &((char *) props_buf)[j * props_per_visual_size],
-                   props_per_visual_size) != Success) {
-            EPHYR_LOG_ERROR("read failed\n");
-        }
-    }
-    UnlockDisplay(dpy);
+    if (!props_buf)
+        goto out;
+    memcpy(props_buf, xcb_glx_get_visual_configs_property_list(reply),
+           props_buf_size);
 
     *a_num_visuals = num_visuals;
-    *a_num_props = reply.numProps;
+    *a_num_props = reply->num_properties;
     *a_props_buf_size = props_buf_size;
     *a_props_buf = props_buf;
     is_ok = TRUE;
 
- out:
-    if (server_glx_version) {
-        XFree(server_glx_version);
-        server_glx_version = NULL;
-    }
-    if (server_glx_extensions) {
-        XFree(server_glx_extensions);
-        server_glx_extensions = NULL;
-    }
-    SyncHandle();
+out:
     return is_ok;
 }
 
@@ -380,14 +206,27 @@ ephyrHostGLXGetVisualConfigs(int32_t a_screen,
                              int32_t * a_props_buf_size, int32_t ** a_props_buf)
 {
     Bool is_ok = FALSE;
+    xcb_glx_get_visual_configs_cookie_t cookie;
+    xcb_glx_get_visual_configs_reply_t *reply;
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    int screen = hostx_get_screen();
 
     EPHYR_LOG("enter\n");
-    is_ok = ephyrHostGLXGetVisualConfigsInternal(EPHYR_GET_VISUAL_CONFIGS,
-                                                 a_screen,
-                                                 a_num_visuals,
-                                                 a_num_props,
-                                                 a_props_buf_size, a_props_buf);
-
+    cookie = xcb_glx_get_visual_configs(conn, screen);
+    reply = xcb_glx_get_visual_configs_reply(conn, cookie, NULL);
+    if (!reply)
+        goto out;
+    is_ok = ephyrHostGLXGetVisualConfigsInternal
+        (EPHYR_GET_VISUAL_CONFIGS,
+         reply,
+         a_screen,
+         a_num_visuals,
+         a_num_props,
+         a_props_buf_size,
+         a_props_buf);
+
+out:
+    free(reply);
     EPHYR_LOG("leave:%d\n", is_ok);
     return is_ok;
 }
@@ -399,12 +238,32 @@ ephyrHostGLXVendorPrivGetFBConfigsSGIX(int a_screen,
                                        int32_t * a_props_buf_size,
                                        int32_t ** a_props_buf)
 {
-    Bool is_ok = FALSE;
+    Bool is_ok=FALSE;
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    int screen = hostx_get_screen();
+    xcb_glx_vendor_private_with_reply_cookie_t cookie;
+    union {
+        xcb_glx_vendor_private_with_reply_reply_t *vprep;
+        xcb_glx_get_visual_configs_reply_t *rep;
+    } reply;
 
     EPHYR_LOG("enter\n");
+    cookie = xcb_glx_vendor_private_with_reply(conn,
+                                               X_GLXvop_GetFBConfigsSGIX,
+                                               0, 4, (uint8_t *)&screen);
+    reply.vprep = xcb_glx_vendor_private_with_reply_reply(conn, cookie, NULL);
+    if (!reply.vprep)
+        goto out;
     is_ok = ephyrHostGLXGetVisualConfigsInternal
         (EPHYR_VENDOR_PRIV_GET_FB_CONFIG_SGIX,
-         a_screen, a_num_visuals, a_num_props, a_props_buf_size, a_props_buf);
+         reply.rep,
+         a_screen,
+         a_num_visuals,
+         a_num_props,
+         a_props_buf_size,
+         a_props_buf);
+out:
+    free(reply.vprep);
     EPHYR_LOG("leave\n");
     return is_ok;
 }
@@ -413,39 +272,15 @@ Bool
 ephyrHostGLXSendClientInfo(int32_t a_major, int32_t a_minor,
                            const char *a_extension_list)
 {
-    Bool is_ok = FALSE;
-    Display *dpy = hostx_get_display();
-    xGLXClientInfoReq *req;
+    xcb_connection_t *conn = hostx_get_xcbconn();
     int size;
-    int32_t major_opcode = 0;
-
-    EPHYR_RETURN_VAL_IF_FAIL(dpy && a_extension_list, FALSE);
-
-    if (!ephyrHostGLXGetMajorOpcode(&major_opcode)) {
-        EPHYR_LOG_ERROR("failed to get major opcode\n");
-        goto out;
-    }
-
-    LockDisplay(dpy);
-
-    GetReq(GLXClientInfo, req);
-    req->reqType = major_opcode;
-    req->glxCode = X_GLXClientInfo;
-    req->major = a_major;
-    req->minor = a_minor;
 
-    size = strlen(a_extension_list) + 1;
-    req->length += bytes_to_int32(size);
-    req->numbytes = size;
-    Data(dpy, a_extension_list, size);
+    EPHYR_RETURN_VAL_IF_FAIL(conn && a_extension_list, FALSE);
 
-    UnlockDisplay(dpy);
-    SyncHandle();
+    size = strlen (a_extension_list) + 1;
+    xcb_glx_client_info(conn, a_major, a_minor, size, a_extension_list);
 
-    is_ok = TRUE;
-
- out:
-    return is_ok;
+    return TRUE;
 }
 
 Bool
@@ -457,9 +292,9 @@ ephyrHostGLXCreateContext(int a_screen,
                           Bool a_direct,
                           int code)
 {
+    xcb_connection_t *conn = hostx_get_xcbconn();
     Bool is_ok = FALSE;
-    Display *dpy = hostx_get_display();
-    int major_opcode = 0, remote_context_id = 0;
+    int remote_context_id = 0;
 
     EPHYR_LOG("enter. screen:%d, generic_id:%d, contextid:%d, rendertype:%d, "
                  "direct:%d\n", a_screen, a_generic_id, a_context_id,
@@ -471,39 +306,24 @@ ephyrHostGLXCreateContext(int a_screen,
         goto out;
     }
 
-    if (!ephyrHostGLXGetMajorOpcode(&major_opcode)) {
-        EPHYR_LOG_ERROR("failed to get major opcode\n");
-        goto out;
-    }
-
-    LockDisplay(dpy);
-
     switch (code) {
     case X_GLXCreateContext: {
-        /* Send the glXCreateContext request */
-        xGLXCreateContextReq *req;
-        GetReq(GLXCreateContext, req);
-        req->reqType = major_opcode;
-        req->glxCode = X_GLXCreateContext;
-        req->context = remote_context_id;
-        req->visual = a_generic_id;
-        req->screen = DefaultScreen(dpy);
-        req->shareList = a_share_list_ctxt_id;
-        req->isDirect = a_direct;
-    }
+        xcb_glx_create_context(conn,
+                               remote_context_id,
+                               a_generic_id,
+                               hostx_get_screen(),
+                               a_share_list_ctxt_id,
+                               a_direct);
+   }
 
     case X_GLXCreateNewContext: {
-        /* Send the glXCreateNewContext request */
-        xGLXCreateNewContextReq *req;
-        GetReq(GLXCreateNewContext, req);
-        req->reqType = major_opcode;
-        req->glxCode = X_GLXCreateNewContext;
-        req->context = remote_context_id;
-        req->fbconfig = a_generic_id;
-        req->screen = DefaultScreen(dpy);
-        req->renderType = a_render_type;
-        req->shareList = a_share_list_ctxt_id;
-        req->isDirect = a_direct;
+        xcb_glx_create_new_context(conn,
+                                   remote_context_id,
+                                   a_generic_id,
+                                   hostx_get_screen(),
+                                   a_render_type,
+                                   a_share_list_ctxt_id,
+                                   a_direct);
     }
 
     default:
@@ -511,9 +331,6 @@ ephyrHostGLXCreateContext(int a_screen,
         EPHYR_LOG("Internal error! Invalid CreateContext code!\n");
     }
 
-    UnlockDisplay(dpy);
-    SyncHandle();
-
     is_ok = TRUE;
 
  out:
@@ -524,30 +341,19 @@ ephyrHostGLXCreateContext(int a_screen,
 Bool
 ephyrHostDestroyContext(int a_ctxt_id)
 {
+    xcb_connection_t *conn = hostx_get_xcbconn();
     Bool is_ok = FALSE;
-    Display *dpy = hostx_get_display();
-    int major_opcode = 0, remote_ctxt_id = 0;
-    xGLXDestroyContextReq *req = NULL;
+    int remote_ctxt_id = 0;
 
     EPHYR_LOG("enter:%d\n", a_ctxt_id);
 
-    if (!ephyrHostGLXGetMajorOpcode(&major_opcode)) {
-        EPHYR_LOG_ERROR("failed to get major opcode\n");
-        goto out;
-    }
     if (!hostx_get_resource_id_peer(a_ctxt_id, &remote_ctxt_id)) {
         EPHYR_LOG_ERROR("failed to get remote glx ctxt id\n");
         goto out;
     }
     EPHYR_LOG("host context id:%d\n", remote_ctxt_id);
 
-    LockDisplay(dpy);
-    GetReq(GLXDestroyContext, req);
-    req->reqType = major_opcode;
-    req->glxCode = X_GLXDestroyContext;
-    req->context = remote_ctxt_id;
-    UnlockDisplay(dpy);
-    SyncHandle();
+    xcb_glx_destroy_context(conn, remote_ctxt_id);
 
     is_ok = TRUE;
 
@@ -560,81 +366,71 @@ Bool
 ephyrHostGLXMakeCurrent(int a_drawable, int a_readable,
                         int a_glx_ctxt_id, int a_old_ctxt_tag, int *a_ctxt_tag)
 {
+    xcb_connection_t *conn = hostx_get_xcbconn();
     Bool is_ok = FALSE;
-    Display *dpy = hostx_get_display();
-    int32_t major_opcode = 0;
     int remote_glx_ctxt_id = 0;
-    xGLXMakeCurrentReply reply;
 
     EPHYR_RETURN_VAL_IF_FAIL(a_ctxt_tag, FALSE);
 
     EPHYR_LOG("enter. drawable:%d, read:%d, context:%d, oldtag:%d\n",
               a_drawable, a_readable, a_glx_ctxt_id, a_old_ctxt_tag);
 
-    if (!ephyrHostGLXGetMajorOpcode(&major_opcode)) {
-        EPHYR_LOG_ERROR("failed to get major opcode\n");
-        goto out;
-    }
     if (!hostx_get_resource_id_peer(a_glx_ctxt_id, &remote_glx_ctxt_id)) {
         EPHYR_LOG_ERROR("failed to get remote glx ctxt id\n");
         goto out;
     }
 
-    LockDisplay(dpy);
-
     /* If both drawables are the same, use the old MakeCurrent request.
      * Otherwise, if we have GLX 1.3 or higher, use the MakeContextCurrent
      * request which supports separate read and draw targets.  Failing that,
      * try the SGI MakeCurrentRead extension.  Logic cribbed from Mesa. */
     if (a_drawable == a_readable) {
-        xGLXMakeCurrentReq *req;
-
-        GetReq(GLXMakeCurrent, req);
-        req->reqType = major_opcode;
-        req->glxCode = X_GLXMakeCurrent;
-        req->drawable = a_drawable;
-        req->context = remote_glx_ctxt_id;
-        req->oldContextTag = a_old_ctxt_tag;
+        xcb_glx_make_current_cookie_t cookie;
+        xcb_glx_make_current_reply_t *reply;
+        cookie = xcb_glx_make_current(conn,
+                                      a_drawable,
+                                      remote_glx_ctxt_id,
+                                      a_old_ctxt_tag);
+        reply = xcb_glx_make_current_reply(conn, cookie, NULL);
+        if (!reply)
+            goto out;
+        *a_ctxt_tag = reply->context_tag;
+        free(reply);
     }
     else if (glx_major > 1 || glx_minor >= 3) {
-        xGLXMakeContextCurrentReq *req;
-
-        GetReq(GLXMakeContextCurrent, req);
-        req->reqType = major_opcode;
-        req->glxCode = X_GLXMakeContextCurrent;
-        req->drawable = a_drawable;
-        req->readdrawable = a_readable;
-        req->context = remote_glx_ctxt_id;
-        req->oldContextTag = a_old_ctxt_tag;
+        xcb_glx_make_context_current_cookie_t cookie;
+        xcb_glx_make_context_current_reply_t *reply;
+        cookie = xcb_glx_make_context_current(conn,
+                                              a_old_ctxt_tag,
+                                              a_drawable,
+                                              a_readable,
+                                              remote_glx_ctxt_id);
+        reply = xcb_glx_make_context_current_reply(conn, cookie, NULL);
+        if (!reply)
+            goto out;
+        *a_ctxt_tag = reply->context_tag;
+        free(reply);
     }
     else {
-        xGLXVendorPrivateWithReplyReq *vpreq;
-        xGLXMakeCurrentReadSGIReq *req;
-
-        GetReqExtra(GLXVendorPrivateWithReply,
-                    (sz_xGLXMakeCurrentReadSGIReq -
-                     sz_xGLXVendorPrivateWithReplyReq),
-                    vpreq);
-        req = (xGLXMakeCurrentReadSGIReq *) vpreq;
-        req->reqType = major_opcode;
-        req->glxCode = X_GLXVendorPrivateWithReply;
-        req->vendorCode = X_GLXvop_MakeCurrentReadSGI;
-        req->drawable = a_drawable;
-        req->readable = a_readable;
-        req->context = remote_glx_ctxt_id;
-        req->oldContextTag = a_old_ctxt_tag;
-    }
+        xcb_glx_vendor_private_with_reply_cookie_t cookie;
+        xcb_glx_vendor_private_with_reply_reply_t *reply;
+        uint32_t data[3] = {
+            a_drawable, a_readable, remote_glx_ctxt_id,
+        };
 
-    memset(&reply, 0, sizeof(reply));
-    if (!_XReply(dpy, (xReply *) &reply, 0, False)) {
-        EPHYR_LOG_ERROR("failed to get reply from host\n");
-        UnlockDisplay(dpy);
-        SyncHandle();
-        goto out;
+        EPHYR_LOG("enter\n");
+        cookie = xcb_glx_vendor_private_with_reply(conn,
+                                                   X_GLXvop_MakeCurrentReadSGI,
+                                                   a_old_ctxt_tag,
+                                                   sizeof(data),
+                                                   (uint8_t *)data);
+        reply = xcb_glx_vendor_private_with_reply_reply(conn, cookie, NULL);
+
+        *a_ctxt_tag = reply->retval;
+
+        free(reply);
     }
-    UnlockDisplay(dpy);
-    SyncHandle();
-    *a_ctxt_tag = reply.contextTag;
+
     EPHYR_LOG("context tag:%d\n", *a_ctxt_tag);
     is_ok = TRUE;
 
@@ -643,79 +439,32 @@ ephyrHostGLXMakeCurrent(int a_drawable, int a_readable,
     return is_ok;
 }
 
-#define X_GLXSingle 0
-
-#define __EPHYR_GLX_SINGLE_PUT_CHAR(offset,a) \
-    *((INT8 *) (pc + offset)) = a
-
-#define EPHYR_GLX_SINGLE_PUT_SHORT(offset,a) \
-    *((INT16 *) (pc + offset)) = a
-
-#define EPHYR_GLX_SINGLE_PUT_LONG(offset,a) \
-    *((INT32 *) (pc + offset)) = a
-
-#define EPHYR_GLX_SINGLE_PUT_FLOAT(offset,a) \
-    *((FLOAT32 *) (pc + offset)) = a
-
-#define EPHYR_GLX_SINGLE_READ_XREPLY()       \
-    (void) _XReply(dpy, (xReply*) &reply, 0, False)
-
-#define EPHYR_GLX_SINGLE_GET_RETVAL(a,cast) \
-    a = (cast) reply.retval
-
-#define EPHYR_GLX_SINGLE_GET_SIZE(a) \
-    a = (GLint) reply.size
-
-#define EPHYR_GLX_SINGLE_GET_CHAR(p) \
-    *p = *(GLbyte *)&reply.pad3;
-
-#define EPHYR_GLX_SINGLE_GET_SHORT(p) \
-    *p = *(GLshort *)&reply.pad3;
-
-#define EPHYR_GLX_SINGLE_GET_LONG(p) \
-    *p = *(GLint *)&reply.pad3;
-
-#define EPHYR_GLX_SINGLE_GET_FLOAT(p) \
-    *p = *(GLfloat *)&reply.pad3;
-
 Bool
 ephyrHostGetIntegerValue(int a_current_context_tag, int a_int, int *a_val)
 {
+    xcb_connection_t *conn = hostx_get_xcbconn();
     Bool is_ok = FALSE;
-    Display *dpy = hostx_get_display();
-    int major_opcode = 0, size = 0;
-    xGLXSingleReq *req = NULL;
-    xGLXSingleReply reply;
-    unsigned char *pc = NULL;
+    int size = 0;
+    xcb_glx_get_integerv_cookie_t cookie;
+    xcb_glx_get_integerv_reply_t *reply;
 
     EPHYR_RETURN_VAL_IF_FAIL(a_val, FALSE);
 
     EPHYR_LOG("enter\n");
-    if (!ephyrHostGLXGetMajorOpcode(&major_opcode)) {
-        EPHYR_LOG_ERROR("failed to get major opcode\n");
+    cookie = xcb_glx_get_integerv(conn, a_current_context_tag, a_int);
+    reply = xcb_glx_get_integerv_reply(conn, cookie, NULL);
+    if (!reply)
         goto out;
-    }
-    LockDisplay(dpy);
-    GetReqExtra(GLXSingle, 4, req);
-    req->reqType = major_opcode;
-    req->glxCode = X_GLsop_GetIntegerv;
-    req->contextTag = a_current_context_tag;
-    pc = ((unsigned char *) (req) + sz_xGLXSingleReq);
-    EPHYR_GLX_SINGLE_PUT_LONG(0, a_int);
-    EPHYR_GLX_SINGLE_READ_XREPLY();
-    EPHYR_GLX_SINGLE_GET_SIZE(size);
+    size = reply->n;
     if (!size) {
-        UnlockDisplay(dpy);
-        SyncHandle();
         EPHYR_LOG_ERROR("X_GLsop_GetIngerv failed\n");
         goto out;
     }
-    EPHYR_GLX_SINGLE_GET_LONG(a_val);
-    UnlockDisplay(dpy);
-    SyncHandle();
+    *a_val = reply->datum;
     is_ok = TRUE;
 
- out:
+out:
+    free(reply);
     EPHYR_LOG("leave\n");
     return is_ok;
 }
@@ -724,40 +473,29 @@ Bool
 ephyrHostIsContextDirect(int a_ctxt_id, int *a_is_direct)
 {
     Bool is_ok = FALSE;
-    Display *dpy = hostx_get_display();
-    xGLXIsDirectReq *req = NULL;
-    xGLXIsDirectReply reply;
-    int major_opcode = 0, remote_glx_ctxt_id = 0;
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    xcb_glx_is_direct_cookie_t cookie;
+    xcb_glx_is_direct_reply_t *reply = NULL;
+    int remote_glx_ctxt_id = 0;
 
     EPHYR_LOG("enter\n");
-    if (!ephyrHostGLXGetMajorOpcode(&major_opcode)) {
-        EPHYR_LOG_ERROR("failed to get major opcode\n");
-        goto out;
-    }
-    if (!hostx_get_resource_id_peer(a_ctxt_id, &remote_glx_ctxt_id)) {
-        EPHYR_LOG_ERROR("failed to get remote glx ctxt id\n");
+    if (!hostx_get_resource_id_peer (a_ctxt_id, &remote_glx_ctxt_id)) {
+        EPHYR_LOG_ERROR ("failed to get remote glx ctxt id\n");
         goto out;
     }
-    memset(&reply, 0, sizeof(reply));
 
     /* Send the glXIsDirect request */
-    LockDisplay(dpy);
-    GetReq(GLXIsDirect, req);
-    req->reqType = major_opcode;
-    req->glxCode = X_GLXIsDirect;
-    req->context = remote_glx_ctxt_id;
-    if (!_XReply(dpy, (xReply *) &reply, 0, False)) {
+    cookie = xcb_glx_is_direct(conn, remote_glx_ctxt_id);
+    reply = xcb_glx_is_direct_reply(conn, cookie, NULL);
+    if (!reply) {
         EPHYR_LOG_ERROR("fail in reading reply from host\n");
-        UnlockDisplay(dpy);
-        SyncHandle();
         goto out;
     }
-    UnlockDisplay(dpy);
-    SyncHandle();
-    *a_is_direct = reply.isDirect;
+    *a_is_direct = reply->is_direct;
     is_ok = TRUE;
 
- out:
+out:
+    free(reply);
     EPHYR_LOG("leave\n");
     return is_ok;
 }
diff --git a/hw/kdrive/ephyr/ephyrhostglx.h b/hw/kdrive/ephyr/ephyrhostglx.h
index 7ff515d..309d0f2 100644
--- a/hw/kdrive/ephyr/ephyrhostglx.h
+++ b/hw/kdrive/ephyr/ephyrhostglx.h
@@ -35,10 +35,12 @@ enum EphyrHostGLXGetStringOps {
 };
 
 Bool ephyrHostGLXQueryVersion(int *a_maj, int *a_min);
-Bool ephyrHostGLXGetStringFromServer(int a_screen_number,
-                                     int a_string_name,
-                                     enum EphyrHostGLXGetStringOps a_op,
-                                     char **a_string);
+Bool ephyrHostGLXGetString(int a_context_tag,
+                           int a_string_name,
+                           char **a_string);
+Bool ephyrHostGLXQueryServerString(int a_screen_number,
+                                   int a_string_name,
+                                   char **a_string);
 Bool ephyrHostGLXGetVisualConfigs(int a_screen,
                                   int32_t * a_num_visuals,
                                   int32_t * a_num_props,
@@ -51,7 +53,6 @@ ephyrHostGLXVendorPrivGetFBConfigsSGIX(int a_screen,
                                        int32_t * a_num_props,
                                        int32_t * a_props_buf_size,
                                        int32_t ** a_props_buf);
-Bool ephyrHostGLXGetMajorOpcode(int32_t * a_opcode);
 Bool ephyrHostGLXSendClientInfo(int32_t a_major, int32_t a_minor,
                                 const char *a_extension_list);
 Bool ephyrHostGLXCreateContext(int a_screen,
commit 19c2699b954e2978301c4449dfccc7ca40bf6ae6
Author: Julien Cristau <jcristau at debian.org>
Date:   Wed Jun 23 18:36:00 2010 +0100

    Xephyr: remove unused DRI1 code
    
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Signed-off-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/Makefile.am b/hw/kdrive/ephyr/Makefile.am
index ab02437..7648e14 100644
--- a/hw/kdrive/ephyr/Makefile.am
+++ b/hw/kdrive/ephyr/Makefile.am
@@ -34,8 +34,6 @@ HOSTDRI_SRCS =			\
 	ephyrdriext.h		\
 	ephyrdri.c		\
 	ephyrdri.h		\
-	XF86dri.c		\
-	xf86dri.h		\
 	ephyrglxext.c		\
 	ephyrglxext.h		\
 	ephyrhostglx.c		\
diff --git a/hw/kdrive/ephyr/XF86dri.c b/hw/kdrive/ephyr/XF86dri.c
deleted file mode 100644
index 15b6219..0000000
--- a/hw/kdrive/ephyr/XF86dri.c
+++ /dev/null
@@ -1,654 +0,0 @@
-/* $XFree86: xc/lib/GL/dri/XF86dri.c,v 1.13 2002/10/30 12:51:25 alanh Exp $ */
-/**************************************************************************
-
-Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
-Copyright 2000 VA Linux Systems, Inc.
-All Rights Reserved.
-
-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, sub license, 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 NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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:
- *   Kevin E. Martin <martin at valinux.com>
- *   Jens Owen <jens at tungstengraphics.com>
- *   Rickard E. (Rik) Faith <faith at valinux.com>
- *
- */
-
-/*
- * This file has been copied from the mesa source tree and a little bit
- * modified by:
- *
- * Dodji Seketeli <dodji at openedhand.com>
- */
-
-#ifdef HAVE_CONFIG_H
-#include <kdrive-config.h>
-#endif
-/*
- * including some server headers (like kdrive-config.h)
- * might define the macro _XSERVER64
- * on 64 bits machines. That macro must _NOT_ be defined for Xlib
- * client code, otherwise bad things happen.
- * So let's undef that macro if necessary.
- */
-#ifdef _XSERVER64
-#undef _XSERVER64
-#endif
-
-/* THIS IS NOT AN X CONSORTIUM STANDARD */
-
-#include <X11/Xlibint.h>
-#include <X11/extensions/Xext.h>
-#include <X11/extensions/extutil.h>
-#include <GL/glx.h>
-#include "xf86dri.h"
-#include <X11/dri/xf86driproto.h>
-#include <limits.h>
-
-static XExtensionInfo _xf86dri_info_data;
-static XExtensionInfo *xf86dri_info = &_xf86dri_info_data;
-static char xf86dri_extension_name[] = XF86DRINAME;
-
-#define XF86DRICheckExtension(dpy,i,val) \
-  XextCheckExtension (dpy, i, xf86dri_extension_name, val)
-
-/*****************************************************************************
- *                                                                           *
- *			   private utility routines                          *
- *                                                                           *
- *****************************************************************************/
-
-static int close_display(Display * dpy, XExtCodes * extCodes);
-
-static /* const */ XExtensionHooks xf86dri_extension_hooks = {
-    NULL,                       /* create_gc */
-    NULL,                       /* copy_gc */
-    NULL,                       /* flush_gc */
-    NULL,                       /* free_gc */
-    NULL,                       /* create_font */
-    NULL,                       /* free_font */
-    close_display,              /* close_display */
-    NULL,                       /* wire_to_event */
-    NULL,                       /* event_to_wire */
-    NULL,                       /* error */
-    NULL,                       /* error_string */
-};
-
-static
-XEXT_GENERATE_FIND_DISPLAY(find_display, xf86dri_info,
-                           xf86dri_extension_name,
-                           &xf86dri_extension_hooks, 0, NULL)
-
-static
-XEXT_GENERATE_CLOSE_DISPLAY(close_display, xf86dri_info)
-
-/*****************************************************************************
- *                                                                           *
- *		    public XFree86-DRI Extension routines                    *
- *                                                                           *
- *****************************************************************************/
-#if 0
-#include <stdio.h>
-#define TRACE(msg)  fprintf(stderr,"XF86DRI%s\n", msg);
-#else
-#define TRACE(msg)
-#endif
-Bool
-XF86DRIOpenFullScreen(Display * dpy, int screen, Drawable drawable);
-Bool
-XF86DRICloseFullScreen(Display * dpy, int screen, Drawable drawable);
-
-Bool
-XF86DRIQueryExtension(Display * dpy, int *event_basep, int *error_basep)
-{
-    XExtDisplayInfo *info = find_display(dpy);
-
-    TRACE("QueryExtension...");
-    if (XextHasExtension(info)) {
-        *event_basep = info->codes->first_event;
-        *error_basep = info->codes->first_error;
-        TRACE("QueryExtension... return True");
-        return True;
-    }
-    else {
-        TRACE("QueryExtension... return False");
-        return False;
-    }
-}
-
-Bool
-XF86DRIQueryVersion(Display * dpy, int *majorVersion, int *minorVersion,
-                    int *patchVersion)
-{
-    XExtDisplayInfo *info = find_display(dpy);
-    xXF86DRIQueryVersionReply rep;
-    xXF86DRIQueryVersionReq *req;
-
-    TRACE("QueryVersion...");
-    XF86DRICheckExtension(dpy, info, False);
-
-    LockDisplay(dpy);
-    GetReq(XF86DRIQueryVersion, req);
-    req->reqType = info->codes->major_opcode;
-    req->driReqType = X_XF86DRIQueryVersion;
-    if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
-        UnlockDisplay(dpy);
-        SyncHandle();
-        TRACE("QueryVersion... return False");
-        return False;
-    }
-    *majorVersion = rep.majorVersion;
-    *minorVersion = rep.minorVersion;
-    *patchVersion = rep.patchVersion;
-    UnlockDisplay(dpy);
-    SyncHandle();
-    TRACE("QueryVersion... return True");
-    return True;
-}
-
-Bool
-XF86DRIQueryDirectRenderingCapable(Display * dpy, int screen, Bool *isCapable)
-{
-    XExtDisplayInfo *info = find_display(dpy);
-    xXF86DRIQueryDirectRenderingCapableReply rep;
-    xXF86DRIQueryDirectRenderingCapableReq *req;
-
-    TRACE("QueryDirectRenderingCapable...");
-    XF86DRICheckExtension(dpy, info, False);
-
-    LockDisplay(dpy);
-    GetReq(XF86DRIQueryDirectRenderingCapable, req);
-    req->reqType = info->codes->major_opcode;
-    req->driReqType = X_XF86DRIQueryDirectRenderingCapable;
-    req->screen = screen;
-    if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
-        UnlockDisplay(dpy);
-        SyncHandle();
-        TRACE("QueryDirectRenderingCapable... return False");
-        return False;
-    }
-    *isCapable = rep.isCapable;
-    UnlockDisplay(dpy);
-    SyncHandle();
-    TRACE("QueryDirectRenderingCapable... return True");
-    return True;
-}
-
-Bool
-XF86DRIOpenConnection(Display * dpy, int screen,
-                      drm_handle_t * hSAREA, char **busIdString)
-{
-    XExtDisplayInfo *info = find_display(dpy);
-    xXF86DRIOpenConnectionReply rep;
-    xXF86DRIOpenConnectionReq *req;
-
-    TRACE("OpenConnection...");
-    XF86DRICheckExtension(dpy, info, False);
-
-    LockDisplay(dpy);
-    GetReq(XF86DRIOpenConnection, req);
-    req->reqType = info->codes->major_opcode;
-    req->driReqType = X_XF86DRIOpenConnection;
-    req->screen = screen;
-    if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
-        UnlockDisplay(dpy);
-        SyncHandle();
-        TRACE("OpenConnection... return False");
-        return False;
-    }
-
-    *hSAREA = rep.hSAREALow;
-    if (sizeof(drm_handle_t) == 8) {
-        int shift = 32;         /* var to prevent warning on next line */
-
-        *hSAREA |= ((drm_handle_t) rep.hSAREAHigh) << shift;
-    }
-
-    if (rep.length) {
-        if (rep.busIdStringLength < INT_MAX)
-            *busIdString = calloc(rep.busIdStringLength + 1, 1);
-        else
-            *busIdString = NULL;
-        if (*busIdString == NULL) {
-            _XEatDataWords(dpy, rep.length);
-            UnlockDisplay(dpy);
-            SyncHandle();
-            TRACE("OpenConnection... return False");
-            return False;
-        }
-        _XReadPad(dpy, *busIdString, rep.busIdStringLength);
-    }
-    else {
-        *busIdString = NULL;
-    }
-    UnlockDisplay(dpy);
-    SyncHandle();
-    TRACE("OpenConnection... return True");
-    return True;
-}
-
-Bool
-XF86DRIAuthConnection(Display * dpy, int screen, drm_magic_t magic)
-{
-    XExtDisplayInfo *info = find_display(dpy);
-    xXF86DRIAuthConnectionReq *req;
-    xXF86DRIAuthConnectionReply rep;
-
-    TRACE("AuthConnection...");
-    XF86DRICheckExtension(dpy, info, False);
-
-    LockDisplay(dpy);
-    GetReq(XF86DRIAuthConnection, req);
-    req->reqType = info->codes->major_opcode;
-    req->driReqType = X_XF86DRIAuthConnection;
-    req->screen = screen;
-    req->magic = magic;
-    rep.authenticated = 0;
-    if (!_XReply(dpy, (xReply *) &rep, 0, xFalse) || !rep.authenticated) {
-        UnlockDisplay(dpy);
-        SyncHandle();
-        TRACE("AuthConnection... return False");
-        return False;
-    }
-    UnlockDisplay(dpy);
-    SyncHandle();
-    TRACE("AuthConnection... return True");
-    return True;
-}
-
-Bool
-XF86DRICloseConnection(Display * dpy, int screen)
-{
-    XExtDisplayInfo *info = find_display(dpy);
-    xXF86DRICloseConnectionReq *req;
-
-    TRACE("CloseConnection...");
-
-    XF86DRICheckExtension(dpy, info, False);
-
-    LockDisplay(dpy);
-    GetReq(XF86DRICloseConnection, req);
-    req->reqType = info->codes->major_opcode;
-    req->driReqType = X_XF86DRICloseConnection;
-    req->screen = screen;
-    UnlockDisplay(dpy);
-    SyncHandle();
-    TRACE("CloseConnection... return True");
-    return True;
-}
-
-Bool
-XF86DRIGetClientDriverName(Display * dpy, int screen,
-                           int *ddxDriverMajorVersion,
-                           int *ddxDriverMinorVersion,
-                           int *ddxDriverPatchVersion, char **clientDriverName)
-{
-    XExtDisplayInfo *info = find_display(dpy);
-    xXF86DRIGetClientDriverNameReply rep;
-    xXF86DRIGetClientDriverNameReq *req;
-
-    TRACE("GetClientDriverName...");
-    XF86DRICheckExtension(dpy, info, False);
-
-    LockDisplay(dpy);
-    GetReq(XF86DRIGetClientDriverName, req);
-    req->reqType = info->codes->major_opcode;
-    req->driReqType = X_XF86DRIGetClientDriverName;
-    req->screen = screen;
-    if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
-        UnlockDisplay(dpy);
-        SyncHandle();
-        TRACE("GetClientDriverName... return False");
-        return False;
-    }
-
-    *ddxDriverMajorVersion = rep.ddxDriverMajorVersion;
-    *ddxDriverMinorVersion = rep.ddxDriverMinorVersion;
-    *ddxDriverPatchVersion = rep.ddxDriverPatchVersion;
-
-    if (rep.length) {
-        if (rep.clientDriverNameLength < INT_MAX)
-            *clientDriverName = calloc(rep.clientDriverNameLength + 1, 1);
-        else
-            *clientDriverName = NULL;
-        if (*clientDriverName == NULL) {
-            _XEatDataWords(dpy, rep.length);
-            UnlockDisplay(dpy);
-            SyncHandle();
-            TRACE("GetClientDriverName... return False");
-            return False;
-        }
-        _XReadPad(dpy, *clientDriverName, rep.clientDriverNameLength);
-    }
-    else {
-        *clientDriverName = NULL;
-    }
-    UnlockDisplay(dpy);
-    SyncHandle();
-    TRACE("GetClientDriverName... return True");
-    return True;
-}
-
-Bool
-XF86DRICreateContextWithConfig(Display * dpy, int screen, int configID,
-                               XID *context, drm_context_t * hHWContext)
-{
-    XExtDisplayInfo *info = find_display(dpy);
-    xXF86DRICreateContextReply rep;
-    xXF86DRICreateContextReq *req;
-
-    TRACE("CreateContext...");
-    XF86DRICheckExtension(dpy, info, False);
-
-    LockDisplay(dpy);
-    GetReq(XF86DRICreateContext, req);
-    req->reqType = info->codes->major_opcode;
-    req->driReqType = X_XF86DRICreateContext;
-    req->visual = configID;
-    req->screen = screen;
-    *context = XAllocID(dpy);
-    req->context = *context;
-    if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
-        UnlockDisplay(dpy);
-        SyncHandle();
-        TRACE("CreateContext... return False");
-        return False;
-    }
-    *hHWContext = rep.hHWContext;
-    UnlockDisplay(dpy);
-    SyncHandle();
-    TRACE("CreateContext... return True");
-    return True;
-}
-
-Bool
-XF86DRICreateContext(Display * dpy, int screen, Visual * visual,
-                     XID *context, drm_context_t * hHWContext)
-{
-    return XF86DRICreateContextWithConfig(dpy, screen, visual->visualid,
-                                          context, hHWContext);
-}
-
-GLboolean
-XF86DRIDestroyContext(Display * dpy, int screen, XID context)
-{
-    XExtDisplayInfo *info = find_display(dpy);
-    xXF86DRIDestroyContextReq *req;
-
-    TRACE("DestroyContext...");
-    XF86DRICheckExtension(dpy, info, False);
-
-    LockDisplay(dpy);
-    GetReq(XF86DRIDestroyContext, req);
-    req->reqType = info->codes->major_opcode;
-    req->driReqType = X_XF86DRIDestroyContext;
-    req->screen = screen;
-    req->context = context;
-    UnlockDisplay(dpy);
-    SyncHandle();
-    TRACE("DestroyContext... return True");
-    return True;
-}
-
-GLboolean
-XF86DRICreateDrawable(Display * dpy, int screen,
-                      XID drawable, drm_drawable_t * hHWDrawable)
-{
-    XExtDisplayInfo *info = find_display(dpy);
-    xXF86DRICreateDrawableReply rep;
-    xXF86DRICreateDrawableReq *req;
-
-    TRACE("CreateDrawable...");
-    XF86DRICheckExtension(dpy, info, False);
-
-    LockDisplay(dpy);
-    GetReq(XF86DRICreateDrawable, req);
-    req->reqType = info->codes->major_opcode;
-    req->driReqType = X_XF86DRICreateDrawable;
-    req->screen = screen;
-    req->drawable = drawable;
-    if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
-        UnlockDisplay(dpy);
-        SyncHandle();
-        TRACE("CreateDrawable... return False");
-        return False;
-    }
-    *hHWDrawable = rep.hHWDrawable;
-    UnlockDisplay(dpy);
-    SyncHandle();
-    TRACE("CreateDrawable... return True");
-    return True;
-}
-
-static int
-noopErrorHandler(Display * dpy, XErrorEvent * xerr)
-{
-    return 0;
-}
-
-GLboolean
-XF86DRIDestroyDrawable(Display * dpy, int screen, XID drawable)
-{
-    XExtDisplayInfo *info = find_display(dpy);
-    xXF86DRIDestroyDrawableReq *req;
-    int (*oldXErrorHandler) (Display *, XErrorEvent *);
-
-    TRACE("DestroyDrawable...");
-    XF86DRICheckExtension(dpy, info, False);
-
-    /* This is called from the DRI driver, which used call it like this
-     *
-     *   if (windowExists(drawable))
-     *     destroyDrawable(drawable);
-     *
-     * which is a textbook race condition - the window may disappear
-     * from the server between checking for its existance and
-     * destroying it.  Instead we change the semantics of
-     * __DRIinterfaceMethodsRec::destroyDrawable() to succeed even if
-     * the windows is gone, by wrapping the destroy call in an error
-     * handler. */
-
-    XSync(dpy, GL_FALSE);
-    oldXErrorHandler = XSetErrorHandler(noopErrorHandler);
-
-    LockDisplay(dpy);
-    GetReq(XF86DRIDestroyDrawable, req);
-    req->reqType = info->codes->major_opcode;
-    req->driReqType = X_XF86DRIDestroyDrawable;
-    req->screen = screen;
-    req->drawable = drawable;
-    UnlockDisplay(dpy);
-    SyncHandle();
-
-    XSetErrorHandler(oldXErrorHandler);
-
-    TRACE("DestroyDrawable... return True");
-    return True;
-}
-
-Bool
-XF86DRIGetDrawableInfo(Display * dpy, int screen, Drawable drawable,
-                       unsigned int *index, unsigned int *stamp,
-                       int *X, int *Y, int *W, int *H,
-                       int *numClipRects, drm_clip_rect_t ** pClipRects,
-                       int *backX, int *backY,
-                       int *numBackClipRects, drm_clip_rect_t ** pBackClipRects)
-{
-    XExtDisplayInfo *info = find_display(dpy);
-    xXF86DRIGetDrawableInfoReply rep;
-    xXF86DRIGetDrawableInfoReq *req = NULL;
-    int total_rects;
-
-    TRACE("GetDrawableInfo...");
-    XF86DRICheckExtension(dpy, info, False);
-
-    LockDisplay(dpy);
-    GetReq(XF86DRIGetDrawableInfo, req);
-    req->reqType = info->codes->major_opcode;
-    req->driReqType = X_XF86DRIGetDrawableInfo;
-    req->screen = screen;
-    req->drawable = drawable;
-
-    if (!_XReply(dpy, (xReply *) &rep, 1, xFalse)) {
-        UnlockDisplay(dpy);
-        SyncHandle();
-        TRACE("GetDrawableInfo... return False");
-        return False;
-    }
-    *index = rep.drawableTableIndex;
-    *stamp = rep.drawableTableStamp;
-    *X = (int) rep.drawableX;
-    *Y = (int) rep.drawableY;
-    *W = (int) rep.drawableWidth;
-    *H = (int) rep.drawableHeight;
-    *numClipRects = rep.numClipRects;
-    total_rects = *numClipRects;
-
-    *backX = rep.backX;
-    *backY = rep.backY;
-    *numBackClipRects = rep.numBackClipRects;
-    total_rects += *numBackClipRects;
-
-#if 0
-    /* Because of the fix in Xserver/GL/dri/xf86dri.c, this check breaks
-     * backwards compatibility (Because of the >> 2 shift) but the fix
-     * enables multi-threaded apps to work.
-     */
-    if (rep.length != ((((SIZEOF(xXF86DRIGetDrawableInfoReply) -
-                          SIZEOF(xGenericReply) +
-                          total_rects * sizeof(drm_clip_rect_t)) +
-                         3) & ~3) >> 2)) {
-        _XEatDataWords(dpy, rep.length);
-        UnlockDisplay(dpy);
-        SyncHandle();
-        TRACE("GetDrawableInfo... return False");
-        return False;
-    }
-#endif
-
-    if (*numClipRects) {
-        int len = sizeof(drm_clip_rect_t) * (*numClipRects);
-
-        *pClipRects = (drm_clip_rect_t *) calloc(len, 1);
-        if (*pClipRects)
-            _XRead(dpy, (char *) *pClipRects, len);
-    }
-    else {
-        *pClipRects = NULL;
-    }
-
-    if (*numBackClipRects) {
-        int len = sizeof(drm_clip_rect_t) * (*numBackClipRects);
-
-        *pBackClipRects = (drm_clip_rect_t *) calloc(len, 1);
-        if (*pBackClipRects)
-            _XRead(dpy, (char *) *pBackClipRects, len);
-    }
-    else {
-        *pBackClipRects = NULL;
-    }
-
-    UnlockDisplay(dpy);
-    SyncHandle();
-    TRACE("GetDrawableInfo... return True");
-    return True;
-}
-
-Bool
-XF86DRIGetDeviceInfo(Display * dpy, int screen, drm_handle_t * hFrameBuffer,
-                     int *fbOrigin, int *fbSize, int *fbStride,
-                     int *devPrivateSize, void **pDevPrivate)
-{
-    XExtDisplayInfo *info = find_display(dpy);
-    xXF86DRIGetDeviceInfoReply rep;
-    xXF86DRIGetDeviceInfoReq *req;
-
-    TRACE("GetDeviceInfo...");
-    XF86DRICheckExtension(dpy, info, False);
-
-    LockDisplay(dpy);
-    GetReq(XF86DRIGetDeviceInfo, req);
-    req->reqType = info->codes->major_opcode;
-    req->driReqType = X_XF86DRIGetDeviceInfo;
-    req->screen = screen;
-    if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
-        UnlockDisplay(dpy);
-        SyncHandle();
-        TRACE("GetDeviceInfo... return False");
-        return False;
-    }
-
-    *hFrameBuffer = rep.hFrameBufferLow;
-    if (sizeof(drm_handle_t) == 8) {
-        int shift = 32;         /* var to prevent warning on next line */
-
-        *hFrameBuffer |= ((drm_handle_t) rep.hFrameBufferHigh) << shift;
-    }
-
-    *fbOrigin = rep.framebufferOrigin;
-    *fbSize = rep.framebufferSize;
-    *fbStride = rep.framebufferStride;
-    *devPrivateSize = rep.devPrivateSize;
-
-    if (rep.length) {
-        if (!(*pDevPrivate = (void *) calloc(rep.devPrivateSize, 1))) {
-            _XEatDataWords(dpy, rep.length);
-            UnlockDisplay(dpy);
-            SyncHandle();
-            TRACE("GetDeviceInfo... return False");
-            return False;
-        }
-        _XRead(dpy, (char *) *pDevPrivate, rep.devPrivateSize);
-    }
-    else {
-        *pDevPrivate = NULL;
-    }
-
-    UnlockDisplay(dpy);
-    SyncHandle();
-    TRACE("GetDeviceInfo... return True");
-    return True;
-}
-
-Bool
-XF86DRIOpenFullScreen(Display * dpy, int screen, Drawable drawable)
-{
-    /* This function and the underlying X protocol are deprecated.
-     */
-    (void) dpy;
-    (void) screen;
-    (void) drawable;
-    return False;
-}
-
-Bool
-XF86DRICloseFullScreen(Display * dpy, int screen, Drawable drawable)
-{
-    /* This function and the underlying X protocol are deprecated.
-     */
-    (void) dpy;
-    (void) screen;
-    (void) drawable;
-    return True;
-}
diff --git a/hw/kdrive/ephyr/xf86dri.h b/hw/kdrive/ephyr/xf86dri.h
deleted file mode 100644
index 88d3f3b..0000000
--- a/hw/kdrive/ephyr/xf86dri.h
+++ /dev/null
@@ -1,124 +0,0 @@
-/* $XFree86: xc/lib/GL/dri/xf86dri.h,v 1.8 2002/10/30 12:51:25 alanh Exp $ */
-/**************************************************************************
-
-Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
-Copyright 2000 VA Linux Systems, Inc.
-All Rights Reserved.
-
-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, sub license, 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 NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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.
-
-**************************************************************************/
-
-/**
- * \file xf86dri.h
- * Protocol numbers and function prototypes for DRI X protocol.
- *
- * \author Kevin E. Martin <martin at valinux.com>
- * \author Jens Owen <jens at tungstengraphics.com>
- * \author Rickard E. (Rik) Faith <faith at valinux.com>
- */
-
-#ifndef _XF86DRI_H_
-#define _XF86DRI_H_
-
-#include <X11/Xfuncproto.h>
-#include <xf86drm.h>
-
-#define X_XF86DRIQueryVersion			0
-#define X_XF86DRIQueryDirectRenderingCapable	1
-#define X_XF86DRIOpenConnection			2
-#define X_XF86DRICloseConnection		3
-#define X_XF86DRIGetClientDriverName		4
-#define X_XF86DRICreateContext			5
-#define X_XF86DRIDestroyContext			6
-#define X_XF86DRICreateDrawable			7
-#define X_XF86DRIDestroyDrawable		8
-#define X_XF86DRIGetDrawableInfo		9
-#define X_XF86DRIGetDeviceInfo			10
-#define X_XF86DRIAuthConnection                 11
-#define X_XF86DRIOpenFullScreen                 12      /* Deprecated */
-#define X_XF86DRICloseFullScreen                13      /* Deprecated */
-
-#define XF86DRINumberEvents		0
-
-#define XF86DRIClientNotLocal		0
-#define XF86DRIOperationNotSupported	1
-#define XF86DRINumberErrors		(XF86DRIOperationNotSupported + 1)
-
-#ifndef _XF86DRI_SERVER_
-
-_XFUNCPROTOBEGIN
-
-Bool XF86DRIQueryExtension(Display * dpy, int *event_base, int *error_base);
-
-Bool XF86DRIQueryVersion(Display * dpy, int *majorVersion, int *minorVersion,
-                         int *patchVersion);
-
-Bool XF86DRIQueryDirectRenderingCapable(Display * dpy, int screen,
-                                        Bool *isCapable);
-
-Bool XF86DRIOpenConnection(Display * dpy, int screen, drm_handle_t * hSAREA,
-                           char **busIDString);
-
-Bool XF86DRIAuthConnection(Display * dpy, int screen, drm_magic_t magic);
-
-Bool XF86DRICloseConnection(Display * dpy, int screen);
-
-Bool XF86DRIGetClientDriverName(Display * dpy, int screen,
-                                int *ddxDriverMajorVersion,
-                                int *ddxDriverMinorVersion,
-                                int *ddxDriverPatchVersion,
-                                char **clientDriverName);
-
-Bool XF86DRICreateContext(Display * dpy, int screen, Visual * visual,
-                          XID *ptr_to_returned_context_id,
-                          drm_context_t * hHWContext);
-
-Bool XF86DRICreateContextWithConfig(Display * dpy, int screen, int configID,
-                                    XID *ptr_to_returned_context_id,
-                                    drm_context_t * hHWContext);
-
-extern GLboolean XF86DRIDestroyContext(Display * dpy, int screen,
-                                       XID context_id);
-
-extern GLboolean XF86DRICreateDrawable(Display * dpy, int screen,
-                                       XID drawable,
-                                       drm_drawable_t * hHWDrawable);
-
-extern GLboolean XF86DRIDestroyDrawable(Display * dpy, int screen,
-                                        XID drawable);
-
-Bool XF86DRIGetDrawableInfo(Display * dpy, int screen, Drawable drawable,
-                            unsigned int *index, unsigned int *stamp,
-                            int *X, int *Y, int *W, int *H,
-                            int *numClipRects, drm_clip_rect_t ** pClipRects,
-                            int *backX, int *backY,
-                            int *numBackClipRects,
-                            drm_clip_rect_t ** pBackClipRects);
-
-Bool XF86DRIGetDeviceInfo(Display * dpy, int screen,
-                          drm_handle_t * hFrameBuffer, int *fbOrigin,
-                          int *fbSize, int *fbStride, int *devPrivateSize,
-                          void **pDevPrivate);
-
-_XFUNCPROTOEND
-#endif                          /* _XF86DRI_SERVER_ */
-#endif                          /* _XF86DRI_H_ */
commit 68b7db19e8d3c1ac55a811327d3058f4c8fb45ec
Author: Julien Cristau <jcristau at debian.org>
Date:   Sun Jun 20 00:07:08 2010 +0100

    Xephyr: move ephyrdri over to xcb
    
    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>

diff --git a/configure.ac b/configure.ac
index b8d9a25..a6c466e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2121,7 +2121,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
 
     if test "x$XEPHYR" = xauto; then
diff --git a/hw/kdrive/ephyr/ephyrdri.c b/hw/kdrive/ephyr/ephyrdri.c
index 3a4a063..16678fc 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
@@ -49,13 +47,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;
@@ -65,31 +71,48 @@ Bool
 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;
 }
@@ -97,13 +120,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
@@ -113,7 +136,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
@@ -121,15 +147,27 @@ ephyrDRIGetClientDriverName(int a_screen,
                              && a_ddx_driver_patch_version
                              && 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;
 }
@@ -139,17 +177,23 @@ ephyrDRICreateContext(int a_screen,
                       int a_visual_id,
                       CARD32 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;
-    XID returned_ctxt_id = ctxt_id;
+    xcb_xf86dri_create_context_cookie_t cookie;
+    xcb_xf86dri_create_context_reply_t *reply;
+
+    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, &returned_ctxt_id, a_hw_ctxt);
+    cookie = xcb_xf86dri_create_context(conn, screen, a_visual_id, 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;
 }
@@ -157,13 +201,13 @@ ephyrDRICreateContext(int a_screen,
 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
@@ -171,11 +215,20 @@ ephyrDRICreateDrawable(int a_screen,
                        int a_drawable, 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;
 }
@@ -206,7 +259,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
@@ -218,16 +274,22 @@ ephyrDRIGetDrawableInfo(int a_screen,
         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)) {
-        EPHYR_LOG_ERROR("XF86DRIGetDrawableInfo ()\n");
+    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);
@@ -247,6 +309,7 @@ ephyrDRIGetDrawableInfo(int a_screen,
  out:
     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);
+    free(reply);
     return is_ok;
 }
 
@@ -259,13 +322,35 @@ ephyrDRIGetDeviceInfo(int a_screen,
                       int *a_dev_private_size, 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;
 }
commit aea119cd05807ed77336f96a40f8e4607c6ce169
Author: Julien Cristau <jcristau at debian.org>
Date:   Sun Jun 20 11:13:26 2010 +0100

    Xephyr: use xcb-xv instead of libXv
    
    v2: Massive, conflict-filled rebase.  I think I resolved everything
        right, but this host xv code makes my eyes bleed.  Touch-tested XV
        after the rebase (anholt).
    
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net> (v1)
    Signed-off-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/configure.ac b/configure.ac
index db7ef7c..b8d9a25 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2118,7 +2118,7 @@ if test "$KDRIVE" = yes; then
 
     XEPHYR_REQUIRED_LIBS="x11 >= 1.6 $LIBXEXT xau xdmcp xcb x11-xcb xcb-shape xcb-aux xcb-image xcb-icccm xcb-shm xcb-keysyms"
     if test "x$XV" = xyes; then
-        XEPHYR_REQUIRED_LIBS="$XEPHYR_REQUIRED_LIBS xv"
+        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"
diff --git a/hw/kdrive/ephyr/ephyrhostvideo.c b/hw/kdrive/ephyr/ephyrhostvideo.c
index 99f0f50..8b71687 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.c
+++ b/hw/kdrive/ephyr/ephyrhostvideo.c
@@ -38,12 +38,8 @@
 #ifdef _XSERVER64
 #undef _XSERVER64
 #endif
-#include <X11/Xutil.h>
-#include <X11/Xlibint.h>
-#include <X11/extensions/Xvlib.h>
-#include <X11/extensions/Xvproto.h>
-#include <X11/extensions/Xext.h>
-#include <X11/extensions/extutil.h>
+#include <xcb/xv.h>
+#include <xcb/xcb_aux.h>
 #define _HAVE_XALLOC_DECLS
 
 #include "hostx.h"
@@ -56,295 +52,114 @@
 #ifndef FALSE
 #define FALSE 0
 #endif /*FALSE*/
-static XExtensionInfo _xv_info_data;
-static XExtensionInfo *xv_info = &_xv_info_data;
-static const char *xv_extension_name = XvName;
-static char *xv_error_string(Display * dpy, int code, XExtCodes * codes,
-                             char *buf, int n);
-static int xv_close_display(Display * dpy, XExtCodes * codes);
-static Bool xv_wire_to_event(Display * dpy, XEvent * host, xEvent *wire);
-
-static XExtensionHooks xv_extension_hooks = {
-    NULL,                       /* create_gc */
-    NULL,                       /* copy_gc */
-    NULL,                       /* flush_gc */
-    NULL,                       /* free_gc */
-    NULL,                       /* create_font */
-    NULL,                       /* free_font */
-    xv_close_display,           /* close_display */
-    xv_wire_to_event,           /* wire_to_event */
-    NULL,                       /* event_to_wire */
-    NULL,                       /* error */
-    xv_error_string             /* error_string */
-};
-
-static const char *xv_error_list[] = {
-    "BadPort",                  /* XvBadPort     */
-    "BadEncoding",              /* XvBadEncoding */
-    "BadControl"                /* XvBadControl  */
-};
-
-#define XvCheckExtension(dpy, i, val) \
-  XextCheckExtension(dpy, i, xv_extension_name, val)
-#define XvGetReq(name, req) \
-        WORD64ALIGN\
-        if ((dpy->bufptr + SIZEOF(xv##name##Req)) > dpy->bufmax)\
-                _XFlush(dpy);\
-        req = (xv##name##Req *)(dpy->last_req = dpy->bufptr);\
-        req->reqType = info->codes->major_opcode;\
-        req->xvReqType = xv_##name; \
-        req->length = (SIZEOF(xv##name##Req))>>2;\
-        dpy->bufptr += SIZEOF(xv##name##Req);\
-        dpy->request++
-
-static
-XEXT_GENERATE_CLOSE_DISPLAY(xv_close_display, xv_info)
-
-static
-XEXT_GENERATE_FIND_DISPLAY(xv_find_display, xv_info,
-                           xv_extension_name,
-                           &xv_extension_hooks, XvNumEvents, NULL)
-
-static
-XEXT_GENERATE_ERROR_STRING(xv_error_string, xv_extension_name,
-                           XvNumErrors, xv_error_list)
-
-struct _EphyrHostXVAdaptorArray {
-    XvAdaptorInfo *adaptors;
-    unsigned int nb_adaptors;
-};
-
-/*heavily copied from libx11*/
-#define BUFSIZE 2048
-static void
-ephyrHostXVLogXErrorEvent(Display * a_display,
-                          XErrorEvent * a_err_event, FILE * a_fp)
-{
-    char buffer[BUFSIZ];
-    char mesg[BUFSIZ];
-    char number[32];
-    const char *mtype = "XlibMessage";
-    register _XExtension *ext = (_XExtension *) NULL;
-    _XExtension *bext = (_XExtension *) NULL;
-    Display *dpy = a_display;
-
-    XGetErrorText(dpy, a_err_event->error_code, buffer, BUFSIZ);
-    XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ);
-    (void) fprintf(a_fp, "%s:  %s\n  ", mesg, buffer);
-    XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d",
-                          mesg, BUFSIZ);
-    (void) fprintf(a_fp, mesg, a_err_event->request_code);
-    if (a_err_event->request_code < 128) {
-        snprintf(number, sizeof(number), "%d", a_err_event->request_code);
-        XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ);
-    }
-    else {
-        for (ext = dpy->ext_procs;
-             ext && (ext->codes.major_opcode != a_err_event->request_code);
-             ext = ext->next);
-        if (ext)
-            strcpy(buffer, ext->name);
-        else
-            buffer[0] = '\0';
-    }
-    (void) fprintf(a_fp, " (%s)\n", buffer);
-    if (a_err_event->request_code >= 128) {
-        XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d",
-                              mesg, BUFSIZ);
-        fputs("  ", a_fp);
-        (void) fprintf(a_fp, mesg, a_err_event->minor_code);
-        if (ext) {
-            snprintf(mesg, sizeof(mesg), "%s.%d",
-                     ext->name, a_err_event->minor_code);
-            XGetErrorDatabaseText(dpy, "XRequest", mesg, "", buffer, BUFSIZ);
-            (void) fprintf(a_fp, " (%s)", buffer);
-        }
-        fputs("\n", a_fp);
-    }
-    if (a_err_event->error_code >= 128) {
-        /* kludge, try to find the extension that caused it */
-        buffer[0] = '\0';
-        for (ext = dpy->ext_procs; ext; ext = ext->next) {
-            if (ext->error_string)
-                (*ext->error_string) (dpy, a_err_event->error_code, &ext->codes,
-                                      buffer, BUFSIZ);
-            if (buffer[0]) {
-                bext = ext;
-                break;
-            }
-            if (ext->codes.first_error &&
-                ext->codes.first_error < (int) a_err_event->error_code &&
-                (!bext || ext->codes.first_error > bext->codes.first_error))
-                bext = ext;
-        }
-        if (bext)
-            snprintf(buffer, sizeof(buffer), "%s.%d", bext->name,
-                     a_err_event->error_code - bext->codes.first_error);
-        else
-            strcpy(buffer, "Value");
-        XGetErrorDatabaseText(dpy, mtype, buffer, "", mesg, BUFSIZ);
-        if (mesg[0]) {
-            fputs("  ", a_fp);
-            (void) fprintf(a_fp, mesg, a_err_event->resourceid);
-            fputs("\n", a_fp);
-        }
-        /* let extensions try to print the values */
-        for (ext = dpy->ext_procs; ext; ext = ext->next) {
-            if (ext->error_values)
-                (*ext->error_values) (dpy, a_err_event, a_fp);
-        }
-    }
-    else if ((a_err_event->error_code == BadWindow) ||
-             (a_err_event->error_code == BadPixmap) ||
-             (a_err_event->error_code == BadCursor) ||
-             (a_err_event->error_code == BadFont) ||
-             (a_err_event->error_code == BadDrawable) ||
-             (a_err_event->error_code == BadColor) ||
-             (a_err_event->error_code == BadGC) ||
-             (a_err_event->error_code == BadIDChoice) ||
-             (a_err_event->error_code == BadValue) ||
-             (a_err_event->error_code == BadAtom)) {
-        if (a_err_event->error_code == BadValue)
-            XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x",
-                                  mesg, BUFSIZ);
-        else if (a_err_event->error_code == BadAtom)
-            XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x",
-                                  mesg, BUFSIZ);
-        else
-            XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x",
-                                  mesg, BUFSIZ);
-        fputs("  ", a_fp);
-        (void) fprintf(a_fp, mesg, a_err_event->resourceid);
-        fputs("\n", a_fp);
-    }
-    XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d",
-                          mesg, BUFSIZ);
-    fputs("  ", a_fp);
-    (void) fprintf(a_fp, mesg, a_err_event->serial);
-    XGetErrorDatabaseText(dpy, mtype, "CurrentSerial", "Current Serial #%d",
-                          mesg, BUFSIZ);
-    fputs("\n  ", a_fp);
-    (void) fprintf(a_fp, mesg, dpy->request);
-    fputs("\n", a_fp);
-}
 
-static int
-ephyrHostXVErrorHandler(Display * a_display, XErrorEvent * a_error_event)
-{
-    EPHYR_LOG_ERROR("got an error from the host xserver:\n");
-    ephyrHostXVLogXErrorEvent(a_display, a_error_event, stderr);
-    return Success;
-}
 
 void
 ephyrHostXVInit(void)
 {
-    static Bool s_initialized;
-
-    if (s_initialized)
-        return;
-    XSetErrorHandler(ephyrHostXVErrorHandler);
-    s_initialized = TRUE;
 }
 
 Bool
-ephyrHostXVQueryAdaptors(EphyrHostXVAdaptorArray ** a_adaptors)
+ephyrHostXVQueryAdaptors (xcb_xv_query_adaptors_reply_t **a_adaptors)
 {
-    EphyrHostXVAdaptorArray *result = NULL;
-    int ret = 0;
     Bool is_ok = FALSE;
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    xcb_xv_query_adaptors_cookie_t cookie;
+    xcb_xv_query_adaptors_reply_t *reply = NULL;
+    xcb_generic_error_t *e = NULL;
 
     EPHYR_RETURN_VAL_IF_FAIL(a_adaptors, FALSE);
 
     EPHYR_LOG("enter\n");
 
-    result = calloc(1, sizeof(EphyrHostXVAdaptorArray));
-    if (!result)
-        goto out;
-
-    ret = XvQueryAdaptors(hostx_get_display(),
-                          DefaultRootWindow(hostx_get_display()),
-                          &result->nb_adaptors, &result->adaptors);
-    if (ret != Success) {
-        EPHYR_LOG_ERROR("failed to query host adaptors: %d\n", ret);
+    cookie = xcb_xv_query_adaptors(conn,
+		    xcb_aux_get_screen(conn, hostx_get_screen())->root);
+    reply = xcb_xv_query_adaptors_reply(hostx_get_xcbconn(), cookie, &e);
+    if (e) {
+        EPHYR_LOG_ERROR ("failed to query host adaptors: %d\n", e->error_code);
         goto out;
     }
-    *a_adaptors = result;
+    *a_adaptors = reply;
     is_ok = TRUE;
 
- out:
+out:
     EPHYR_LOG("leave\n");
+    free(e);
     return is_ok;
 }
 
 void
-ephyrHostXVAdaptorArrayDelete(EphyrHostXVAdaptorArray * a_adaptors)
+ephyrHostXVAdaptorArrayDelete (xcb_xv_query_adaptors_reply_t *a_adaptors)
 {
-    if (!a_adaptors)
-        return;
-    if (a_adaptors->adaptors) {
-        XvFreeAdaptorInfo(a_adaptors->adaptors);
-        a_adaptors->adaptors = NULL;
-        a_adaptors->nb_adaptors = 0;
-    }
-    XFree(a_adaptors);
+    free (a_adaptors);
 }
 
 int
-ephyrHostXVAdaptorArrayGetSize(const EphyrHostXVAdaptorArray * a_this)
+ephyrHostXVAdaptorArrayGetSize (const xcb_xv_query_adaptors_reply_t *a_this)
 {
     EPHYR_RETURN_VAL_IF_FAIL(a_this, -1);
-    return a_this->nb_adaptors;
+    return a_this->num_adaptors;
 }
 
-EphyrHostXVAdaptor *
-ephyrHostXVAdaptorArrayAt(const EphyrHostXVAdaptorArray * a_this, int a_index)
+xcb_xv_adaptor_info_t *
+ephyrHostXVAdaptorArrayAt(const xcb_xv_query_adaptors_reply_t *a_this,
+                          int a_index)
 {
+    int i;
+    xcb_xv_adaptor_info_iterator_t it;
     EPHYR_RETURN_VAL_IF_FAIL(a_this, NULL);
 
-    if (a_index >= a_this->nb_adaptors)
+    it = xcb_xv_query_adaptors_info_iterator(a_this);
+    if (a_index >= a_this->num_adaptors)
         return NULL;
-    return (EphyrHostXVAdaptor *) &a_this->adaptors[a_index];
+    for (i = 0; i < a_index; i++)
+        xcb_xv_adaptor_info_next(&it);
+
+    return it.data;
 }
 
 char
-ephyrHostXVAdaptorGetType(const EphyrHostXVAdaptor * a_this)
+ephyrHostXVAdaptorGetType(const xcb_xv_adaptor_info_t *a_this)
 {
     EPHYR_RETURN_VAL_IF_FAIL(a_this, -1);
-    return ((const XvAdaptorInfo *) a_this)->type;
+    return a_this->type;
 }
 
-const char *
-ephyrHostXVAdaptorGetName(const EphyrHostXVAdaptor * a_this)
+char *
+ephyrHostXVAdaptorGetName(const xcb_xv_adaptor_info_t *a_this)
 {
+    char *name;
+
     EPHYR_RETURN_VAL_IF_FAIL(a_this, NULL);
 
-    return ((const XvAdaptorInfo *) a_this)->name;
+    name = malloc(a_this->name_size + 1);
+    if (!name)
+        return NULL;
+    memcpy(name, xcb_xv_adaptor_info_name(a_this), a_this->name_size);
+    name[a_this->name_size] = '\0';
+
+    return name;
 }
 
-EphyrHostVideoFormat *
-ephyrHostXVAdaptorGetVideoFormats(const EphyrHostXVAdaptor * a_this,
-                                  int *a_nb_formats)
+EphyrHostVideoFormat*
+ephyrHostXVAdaptorGetVideoFormats (const xcb_xv_adaptor_info_t *a_this,
+                                   int *a_nb_formats)
 {
     EphyrHostVideoFormat *formats = NULL;
     int nb_formats = 0, i = 0;
-    XVisualInfo *visual_info, visual_info_template;
-    int nb_visual_info;
+    xcb_xv_format_t *format = xcb_xv_adaptor_info_formats(a_this);
 
     EPHYR_RETURN_VAL_IF_FAIL(a_this, NULL);
 
-    nb_formats = ((const XvAdaptorInfo *) a_this)->num_formats;
+    nb_formats = a_this->num_formats;
     formats = calloc(nb_formats, sizeof(EphyrHostVideoFormat));
     for (i = 0; i < nb_formats; i++) {
-        memset(&visual_info_template, 0, sizeof(visual_info_template));
-        visual_info_template.visualid =
-            ((const XvAdaptorInfo *) a_this)->formats[i].visual_id;
-        visual_info = XGetVisualInfo(hostx_get_display(),
-                                     VisualIDMask,
-                                     &visual_info_template, &nb_visual_info);
-        formats[i].depth = ((const XvAdaptorInfo *) a_this)->formats[i].depth;
-        formats[i].visual_class = visual_info->class;
-        XFree(visual_info);
+        xcb_visualtype_t *visual =
+            xcb_aux_find_visual_by_id(
+                    xcb_aux_get_screen(hostx_get_xcbconn(), hostx_get_screen()),
+                    format[i].visual);
+        formats[i].depth = format[i].depth;
+        formats[i].visual_class = visual->_class;
     }
     if (a_nb_formats)
         *a_nb_formats = nb_formats;
@@ -352,28 +167,27 @@ ephyrHostXVAdaptorGetVideoFormats(const EphyrHostXVAdaptor * a_this,
 }
 
 int
-ephyrHostXVAdaptorGetNbPorts(const EphyrHostXVAdaptor * a_this)
+ephyrHostXVAdaptorGetNbPorts(const xcb_xv_adaptor_info_t *a_this)
 {
     EPHYR_RETURN_VAL_IF_FAIL(a_this, -1);
 
-    return ((const XvAdaptorInfo *) a_this)->num_ports;
+    return a_this->num_ports;
 }
 
 int
-ephyrHostXVAdaptorGetFirstPortID(const EphyrHostXVAdaptor * a_this)
+ephyrHostXVAdaptorGetFirstPortID (const xcb_xv_adaptor_info_t *a_this)
 {
-    EPHYR_RETURN_VAL_IF_FAIL(a_this, -1);
-
-    return ((const XvAdaptorInfo *) a_this)->base_id;
+    return a_this->base_id;
 }
 
 Bool
-ephyrHostXVAdaptorHasPutVideo(const EphyrHostXVAdaptor * a_this, Bool *a_result)
+ephyrHostXVAdaptorHasPutVideo (const xcb_xv_adaptor_info_t *a_this,
+                               Bool *a_result)
 {
     EPHYR_RETURN_VAL_IF_FAIL(a_this && a_result, FALSE);
 
-    if ((((const XvAdaptorInfo *) a_this)->type &
-         (XvVideoMask | XvInputMask)) == (XvVideoMask | XvInputMask))
+    if ((a_this->type & (XCB_XV_TYPE_VIDEO_MASK | XCB_XV_TYPE_INPUT_MASK)) ==
+        (XCB_XV_TYPE_VIDEO_MASK | XCB_XV_TYPE_INPUT_MASK))
         *a_result = TRUE;
     else
         *a_result = FALSE;
@@ -381,10 +195,11 @@ ephyrHostXVAdaptorHasPutVideo(const EphyrHostXVAdaptor * a_this, Bool *a_result)
 }
 
 Bool
-ephyrHostXVAdaptorHasGetVideo(const EphyrHostXVAdaptor * a_this, Bool *a_result)
+ephyrHostXVAdaptorHasGetVideo(const xcb_xv_adaptor_info_t *a_this,
+                              Bool *a_result)
 {
-    if ((((const XvAdaptorInfo *) a_this)->type &
-         (XvVideoMask | XvOutputMask)) == (XvVideoMask | XvOutputMask))
+    if ((a_this->type & (XCB_XV_TYPE_VIDEO_MASK | XCB_XV_TYPE_OUTPUT_MASK)) ==
+        (XCB_XV_TYPE_VIDEO_MASK | XCB_XV_TYPE_OUTPUT_MASK))
         *a_result = TRUE;
     else
         *a_result = FALSE;
@@ -392,12 +207,13 @@ ephyrHostXVAdaptorHasGetVideo(const EphyrHostXVAdaptor * a_this, Bool *a_result)
 }
 
 Bool
-ephyrHostXVAdaptorHasPutStill(const EphyrHostXVAdaptor * a_this, Bool *a_result)
+ephyrHostXVAdaptorHasPutStill(const xcb_xv_adaptor_info_t *a_this,
+                              Bool *a_result)
 {
     EPHYR_RETURN_VAL_IF_FAIL(a_this && a_result, FALSE);
 
-    if ((((const XvAdaptorInfo *) a_this)->type &
-         (XvStillMask | XvInputMask)) == (XvStillMask | XvInputMask))
+    if ((a_this->type & (XCB_XV_TYPE_STILL_MASK | XCB_XV_TYPE_INPUT_MASK)) ==
+        (XCB_XV_TYPE_STILL_MASK | XCB_XV_TYPE_INPUT_MASK))
         *a_result = TRUE;
     else
         *a_result = FALSE;
@@ -405,12 +221,13 @@ ephyrHostXVAdaptorHasPutStill(const EphyrHostXVAdaptor * a_this, Bool *a_result)
 }
 
 Bool
-ephyrHostXVAdaptorHasGetStill(const EphyrHostXVAdaptor * a_this, Bool *a_result)
+ephyrHostXVAdaptorHasGetStill(const xcb_xv_adaptor_info_t *a_this,
+                              Bool *a_result)
 {
     EPHYR_RETURN_VAL_IF_FAIL(a_this && a_result, FALSE);
 
-    if ((((const XvAdaptorInfo *) a_this)->type &
-         (XvStillMask | XvOutputMask)) == (XvStillMask | XvOutputMask))
+    if ((a_this->type & (XCB_XV_TYPE_STILL_MASK | XCB_XV_TYPE_OUTPUT_MASK)) ==
+        (XCB_XV_TYPE_STILL_MASK | XCB_XV_TYPE_OUTPUT_MASK))
         *a_result = TRUE;
     else
         *a_result = FALSE;
@@ -418,12 +235,13 @@ ephyrHostXVAdaptorHasGetStill(const EphyrHostXVAdaptor * a_this, Bool *a_result)
 }
 
 Bool
-ephyrHostXVAdaptorHasPutImage(const EphyrHostXVAdaptor * a_this, Bool *a_result)
+ephyrHostXVAdaptorHasPutImage(const xcb_xv_adaptor_info_t *a_this,
+                              Bool *a_result)
 {
     EPHYR_RETURN_VAL_IF_FAIL(a_this && a_result, FALSE);
 
-    if ((((const XvAdaptorInfo *) a_this)->type &
-         (XvImageMask | XvInputMask)) == (XvImageMask | XvInputMask))
+    if ((a_this->type & (XCB_XV_TYPE_IMAGE_MASK | XCB_XV_TYPE_INPUT_MASK)) ==
+        (XCB_XV_TYPE_IMAGE_MASK | XCB_XV_TYPE_INPUT_MASK))
         *a_result = TRUE;
     else
         *a_result = FALSE;
@@ -436,34 +254,36 @@ ephyrHostXVQueryEncodings(int a_port_id,
                           unsigned int *a_num_encodings)
 {
     EphyrHostEncoding *encodings = NULL;
-    XvEncodingInfo *encoding_info = NULL;
+    xcb_xv_encoding_info_iterator_t encoding_info;
+    xcb_xv_query_encodings_cookie_t cookie;
+    xcb_xv_query_encodings_reply_t *reply;
     unsigned int num_encodings = 0, i;
-    int ret = 0;
 
     EPHYR_RETURN_VAL_IF_FAIL(a_encodings && a_num_encodings, FALSE);
 
-    ret = XvQueryEncodings(hostx_get_display(),
-                           a_port_id, &num_encodings, &encoding_info);
-    if (num_encodings && encoding_info) {
-        encodings = calloc(num_encodings, sizeof(EphyrHostEncoding));
-        for (i = 0; i < num_encodings; i++) {
-            encodings[i].id = encoding_info[i].encoding_id;
-            encodings[i].name = strdup(encoding_info[i].name);
-            encodings[i].width = encoding_info[i].width;
-            encodings[i].height = encoding_info[i].height;
-            encodings[i].rate.numerator = encoding_info[i].rate.numerator;
-            encodings[i].rate.denominator = encoding_info[i].rate.denominator;
+    cookie = xcb_xv_query_encodings(hostx_get_xcbconn(), a_port_id);
+    reply = xcb_xv_query_encodings_reply(hostx_get_xcbconn(), cookie, NULL);
+    if (!reply)
+        return FALSE;
+    num_encodings = reply->num_encodings;
+    encoding_info = xcb_xv_query_encodings_info_iterator(reply);
+    if (num_encodings) {
+        encodings = calloc(num_encodings, sizeof (EphyrHostEncoding));
+        for (i=0; i<num_encodings; i++, xcb_xv_encoding_info_next(&encoding_info)) {
+            encodings[i].id = encoding_info.data->encoding;
+            encodings[i].name = malloc(encoding_info.data->name_size + 1);
+	    memcpy(encodings[i].name, xcb_xv_encoding_info_name(encoding_info.data), encoding_info.data->name_size);
+	    encodings[i].name[encoding_info.data->name_size] = '\0';
+            encodings[i].width = encoding_info.data->width;
+            encodings[i].height = encoding_info.data->height;
+            encodings[i].rate.numerator = encoding_info.data->rate.numerator;
+            encodings[i].rate.denominator = encoding_info.data->rate.denominator;
         }
     }
-    if (encoding_info) {
-        XvFreeEncodingInfo(encoding_info);
-        encoding_info = NULL;
-    }
+    free(reply);
     *a_encodings = encodings;
     *a_num_encodings = num_encodings;
 
-    if (ret != Success)
-        return FALSE;
     return TRUE;
 }
 
@@ -482,26 +302,26 @@ ephyrHostEncodingsDelete(EphyrHostEncoding * a_encodings, int a_num_encodings)
 }
 
 void
-ephyrHostAttributesDelete(EphyrHostAttribute * a_attributes)
+ephyrHostAttributesDelete(xcb_xv_query_port_attributes_reply_t *a_attributes)
 {
-    if (!a_attributes)
-        return;
-    XFree(a_attributes);
+    free(a_attributes);
 }
 
 Bool
 ephyrHostXVQueryPortAttributes(int a_port_id,
-                               EphyrHostAttribute ** a_attributes,
-                               int *a_num_attributes)
+                               xcb_xv_query_port_attributes_reply_t **a_attributes)
 {
-    EPHYR_RETURN_VAL_IF_FAIL(a_attributes && a_num_attributes, FALSE);
+    xcb_xv_query_port_attributes_cookie_t cookie;
+    xcb_xv_query_port_attributes_reply_t *reply;
+    xcb_connection_t *conn = hostx_get_xcbconn();
 
-    *a_attributes =
-        (EphyrHostAttribute *) XvQueryPortAttributes(hostx_get_display(),
-                                                     a_port_id,
-                                                     a_num_attributes);
+    EPHYR_RETURN_VAL_IF_FAIL(a_attributes, FALSE);
 
-    return TRUE;
+    cookie = xcb_xv_query_port_attributes(conn, a_port_id);
+    reply = xcb_xv_query_port_attributes_reply(conn, cookie, NULL);
+    *a_attributes = reply;
+
+    return (reply != NULL);
 }
 
 Bool
@@ -509,31 +329,66 @@ ephyrHostXVQueryImageFormats(int a_port_id,
                              EphyrHostImageFormat ** a_formats,
                              int *a_num_format)
 {
-    XvImageFormatValues *result = NULL;
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    xcb_xv_list_image_formats_cookie_t cookie;
+    xcb_xv_list_image_formats_reply_t *reply;
+    xcb_xv_image_format_info_t *format;
+    EphyrHostImageFormat *ephyrFormats;
+    int i;
 
     EPHYR_RETURN_VAL_IF_FAIL(a_formats && a_num_format, FALSE);
 
-    result = XvListImageFormats(hostx_get_display(), a_port_id, a_num_format);
-    *a_formats = (EphyrHostImageFormat *) result;
+    cookie = xcb_xv_list_image_formats(conn, a_port_id);
+    reply = xcb_xv_list_image_formats_reply(conn, cookie, NULL);
+    if (!reply)
+        return FALSE;
+    *a_num_format = reply->num_formats;
+    ephyrFormats = calloc(reply->num_formats, sizeof(EphyrHostImageFormat));
+    if (!ephyrFormats) {
+        free(reply);
+        return FALSE;
+    }
+    format = xcb_xv_list_image_formats_format(reply);
+    for (i = 0; i < reply->num_formats; i++) {
+        ephyrFormats[i].id = format[i].id;
+        ephyrFormats[i].type = format[i].type;
+        ephyrFormats[i].byte_order = format[i].byte_order;
+        memcpy(ephyrFormats[i].guid, format[i].guid, 16);
+        ephyrFormats[i].bits_per_pixel = format[i].bpp;
+        ephyrFormats[i].format = format[i].format;
+        ephyrFormats[i].num_planes = format[i].num_planes;
+        ephyrFormats[i].depth = format[i].depth;
+        ephyrFormats[i].red_mask = format[i].red_mask;
+        ephyrFormats[i].green_mask = format[i].green_mask;
+        ephyrFormats[i].blue_mask = format[i].blue_mask;
+        ephyrFormats[i].y_sample_bits = format[i].y_sample_bits;
+        ephyrFormats[i].u_sample_bits = format[i].u_sample_bits;
+        ephyrFormats[i].v_sample_bits = format[i].v_sample_bits;
+        ephyrFormats[i].horz_y_period = format[i].vhorz_y_period;
+        ephyrFormats[i].horz_u_period = format[i].vhorz_u_period;
+        ephyrFormats[i].horz_v_period = format[i].vhorz_v_period;
+        ephyrFormats[i].vert_y_period = format[i].vvert_y_period;
+        ephyrFormats[i].vert_u_period = format[i].vvert_u_period;
+        ephyrFormats[i].vert_v_period = format[i].vvert_v_period;
+        memcpy(ephyrFormats[i].component_order, format[i].vcomp_order, 32);
+        ephyrFormats[i].scanline_order = format[i].vscanline_order;
+    }
+    *a_formats = ephyrFormats;
+
+    free(reply);
     return TRUE;
-
 }
 
 Bool
 ephyrHostXVSetPortAttribute(int a_port_id, int a_atom, int a_attr_value)
 {
-    int res = Success;
-
-    EPHYR_LOG("atom,name,value: (%d,%s,%d)\n",
-              a_atom, XGetAtomName(hostx_get_display(), a_atom), a_attr_value);
+    EPHYR_LOG("atom,value: (%d,%d)\n", a_atom, a_attr_value);
 
-    res = XvSetPortAttribute(hostx_get_display(),
-                             a_port_id, a_atom, a_attr_value);
-    if (res != Success) {
-        EPHYR_LOG_ERROR("XvSetPortAttribute() failed: %d\n", res);
-        return FALSE;
-    }
-    XFlush(hostx_get_display());
+    xcb_xv_set_port_attribute(hostx_get_xcbconn(),
+                              a_port_id,
+                              a_atom,
+                              a_attr_value);
+    xcb_flush(hostx_get_xcbconn());
     EPHYR_LOG("leave\n");
 
     return TRUE;
@@ -542,20 +397,24 @@ ephyrHostXVSetPortAttribute(int a_port_id, int a_atom, int a_attr_value)
 Bool
 ephyrHostXVGetPortAttribute(int a_port_id, int a_atom, int *a_attr_value)
 {
-    int res = Success;
     Bool ret = FALSE;
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    xcb_xv_get_port_attribute_cookie_t cookie;
+    xcb_xv_get_port_attribute_reply_t *reply;
+    xcb_generic_error_t *e;
 
     EPHYR_RETURN_VAL_IF_FAIL(a_attr_value, FALSE);
 
-    EPHYR_LOG("enter, a_port_id: %d, a_atomid: %d, attr_name: %s\n",
-              a_port_id, a_atom, XGetAtomName(hostx_get_display(), a_atom));
+    EPHYR_LOG("enter, a_port_id: %d, a_atomid: %d\n", a_port_id, a_atom);
 
-    res = XvGetPortAttribute(hostx_get_display(),
-                             a_port_id, a_atom, a_attr_value);
-    if (res != Success) {
-        EPHYR_LOG_ERROR("XvGetPortAttribute() failed: %d \n", res);
+    cookie = xcb_xv_get_port_attribute(conn, a_port_id, a_atom);
+    reply = xcb_xv_get_port_attribute_reply(conn, cookie, &e);
+    if (e) {
+        EPHYR_LOG_ERROR ("XvGetPortAttribute() failed: %d \n", e->error_code);
+        free(e);
         goto out;
     }
+    *a_attr_value = reply->value;
     EPHYR_LOG("atom,value: (%d, %d)\n", a_atom, *a_attr_value);
 
     ret = TRUE;
@@ -574,70 +433,38 @@ ephyrHostXVQueryBestSize(int a_port_id,
                          unsigned int a_drw_h,
                          unsigned int *a_actual_w, unsigned int *a_actual_h)
 {
-    int res = 0;
     Bool is_ok = FALSE;
+    xcb_xv_query_best_size_cookie_t cookie;
+    xcb_xv_query_best_size_reply_t *reply;
 
     EPHYR_RETURN_VAL_IF_FAIL(a_actual_w && a_actual_h, FALSE);
 
     EPHYR_LOG("enter: frame (%dx%d), drw (%dx%d)\n",
               a_frame_w, a_frame_h, a_drw_w, a_drw_h);
 
-    res = XvQueryBestSize(hostx_get_display(),
-                          a_port_id,
-                          a_motion,
-                          a_frame_w, a_frame_h,
-                          a_drw_w, a_drw_h, a_actual_w, a_actual_h);
-    if (res != Success) {
-        EPHYR_LOG_ERROR("XvQueryBestSize() failed: %d\n", res);
+    cookie = xcb_xv_query_best_size(hostx_get_xcbconn(),
+                                    a_port_id,
+                                    a_frame_w, a_frame_h,
+                                    a_drw_w, a_drw_h,
+                                    a_motion);
+    reply = xcb_xv_query_best_size_reply(hostx_get_xcbconn(), cookie, NULL);
+    if (!reply) {
+        EPHYR_LOG_ERROR ("XvQueryBestSize() failed\n");
         goto out;
     }
-    XSync(hostx_get_display(), FALSE);
+    *a_actual_w = reply->actual_width;
+    *a_actual_h = reply->actual_height;
+    free(reply);
 
     EPHYR_LOG("actual (%dx%d)\n", *a_actual_w, *a_actual_h);
     is_ok = TRUE;
 
- out:
+out:
+    free(reply);
     EPHYR_LOG("leave\n");
     return is_ok;
 }
 
-static Bool
-xv_wire_to_event(Display * dpy, XEvent * host, xEvent *wire)
-{
-    XExtDisplayInfo *info = xv_find_display(dpy);
-    XvEvent *re = (XvEvent *) host;
-    xvEvent *event = (xvEvent *) wire;
-
-    XvCheckExtension(dpy, info, False);
-
-    switch ((event->u.u.type & 0x7F) - info->codes->first_event) {
-    case XvVideoNotify:
-        re->xvvideo.type = event->u.u.type & 0x7f;
-        re->xvvideo.serial = _XSetLastRequestRead(dpy, (xGenericReply *) event);
-        re->xvvideo.send_event = ((event->u.u.type & 0x80) != 0);
-        re->xvvideo.display = dpy;
-        re->xvvideo.time = event->u.videoNotify.time;
-        re->xvvideo.reason = event->u.videoNotify.reason;
-        re->xvvideo.drawable = event->u.videoNotify.drawable;
-        re->xvvideo.port_id = event->u.videoNotify.port;
-        break;
-    case XvPortNotify:
-        re->xvport.type = event->u.u.type & 0x7f;
-        re->xvport.serial = _XSetLastRequestRead(dpy, (xGenericReply *) event);
-        re->xvport.send_event = ((event->u.u.type & 0x80) != 0);
-        re->xvport.display = dpy;
-        re->xvport.time = event->u.portNotify.time;
-        re->xvport.port_id = event->u.portNotify.port;
-        re->xvport.attribute = event->u.portNotify.attribute;
-        re->xvport.value = event->u.portNotify.value;
-        break;
-    default:
-        return False;
-    }
-
-    return True;
-}
-
 Bool
 ephyrHostXVQueryImageAttributes(int a_port_id,
                                 int a_image_id /*image fourcc code */ ,
@@ -646,77 +473,85 @@ ephyrHostXVQueryImageAttributes(int a_port_id,
                                 int *a_image_size,
                                 int *a_pitches, int *a_offsets)
 {
-    Display *dpy = hostx_get_display();
-    Bool ret = FALSE;
-    XExtDisplayInfo *info = xv_find_display(dpy);
-    xvQueryImageAttributesReq *req = NULL;
-    xvQueryImageAttributesReply rep;
+    xcb_connection_t *conn = hostx_get_xcbconn ();
+    xcb_xv_query_image_attributes_cookie_t cookie;
+    xcb_xv_query_image_attributes_reply_t *reply;
 
     EPHYR_RETURN_VAL_IF_FAIL(a_width, FALSE);
     EPHYR_RETURN_VAL_IF_FAIL(a_height, FALSE);
     EPHYR_RETURN_VAL_IF_FAIL(a_image_size, FALSE);
 
-    XvCheckExtension(dpy, info, FALSE);
-
-    LockDisplay(dpy);
-
-    XvGetReq(QueryImageAttributes, req);
-    req->id = a_image_id;
-    req->port = a_port_id;
-    req->width = *a_width;
-    req->height = *a_height;
-    /*
-     * read the reply
-     */
-    if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
-        EPHYR_LOG_ERROR("QeryImageAttribute req failed\n");
-        goto out;
-    }
+    cookie = xcb_xv_query_image_attributes(conn,
+                                           a_port_id, a_image_id,
+                                           *a_width, *a_height);
+    reply = xcb_xv_query_image_attributes_reply(conn, cookie, NULL);
+    if (!reply)
+        return FALSE;
     if (a_pitches && a_offsets) {
-        _XRead(dpy, (char *) a_pitches, rep.num_planes << 2);
-        _XRead(dpy, (char *) a_offsets, rep.num_planes << 2);
-    }
-    else {
-        _XEatDataWords(dpy, rep.length);
-    }
-    *a_width = rep.width;
-    *a_height = rep.height;
-    *a_image_size = rep.data_size;
-
-    ret = TRUE;
+        memcpy(a_pitches,
+               xcb_xv_query_image_attributes_pitches(reply),
+               reply->num_planes << 2);
+        memcpy(a_offsets,
+               xcb_xv_query_image_attributes_offsets(reply),
+               reply->num_planes << 2);
+    }
+    *a_width = reply->width;
+    *a_height = reply->height;
+    *a_image_size = reply->data_size;
+    free(reply);
 
- out:
-    UnlockDisplay(dpy);
-    SyncHandle();
-    return ret;
+    return TRUE;
 }
 
 Bool
 ephyrHostGetAtom(const char *a_name, Bool a_create_if_not_exists, int *a_atom)
 {
-    int atom = None;
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    xcb_intern_atom_cookie_t cookie;
+    xcb_intern_atom_reply_t *reply;
 
     EPHYR_RETURN_VAL_IF_FAIL(a_atom, FALSE);
 
-    atom = XInternAtom(hostx_get_display(), a_name, a_create_if_not_exists);
-    if (atom == None) {
+    cookie = xcb_intern_atom(conn,
+                             a_create_if_not_exists,
+                             strlen(a_name),
+                             a_name);
+    reply = xcb_intern_atom_reply(conn, cookie, NULL);
+    if (!reply || reply->atom == None) {
+        free(reply);
         return FALSE;
     }
-    *a_atom = atom;
+    *a_atom = reply->atom;
+    free(reply);
     return TRUE;
 }
 
 char *
 ephyrHostGetAtomName(int a_atom)
 {
-    return XGetAtomName(hostx_get_display(), a_atom);
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    xcb_get_atom_name_cookie_t cookie;
+    xcb_get_atom_name_reply_t *reply;
+    char *ret;
+
+    cookie = xcb_get_atom_name(conn, a_atom);
+    reply = xcb_get_atom_name_reply(conn, cookie, NULL);
+    if (!reply)
+        return NULL;
+    ret = malloc(xcb_get_atom_name_name_length(reply) + 1);
+    if (ret) {
+        memcpy(ret, xcb_get_atom_name_name(reply),
+               xcb_get_atom_name_name_length(reply));
+        ret[xcb_get_atom_name_name_length(reply)] = '\0';
+    }
+    free(reply);
+    return ret;
 }
 
 void
 ephyrHostFree(void *a_pointer)
 {
-    if (a_pointer)
-        XFree(a_pointer);
+    free(a_pointer);
 }
 
 Bool
@@ -737,36 +572,39 @@ ephyrHostXVPutImage(int a_screen_num,
                     EphyrHostBox * a_clip_rects, int a_clip_rect_nums)
 {
     Bool is_ok = TRUE;
-    XvImage *xv_image = NULL;
-    GC gc = 0;
-    XGCValues gc_values;
-    Display *dpy = hostx_get_display();
-    XRectangle *rects = NULL;
-    int res = 0;
+    xcb_connection_t *conn = hostx_get_xcbconn ();
+    xcb_gcontext_t gc;
+    xcb_rectangle_t *rects = NULL;
+    int data_len, width, height;
+    xcb_xv_query_image_attributes_cookie_t image_attr_cookie;
+    xcb_xv_query_image_attributes_reply_t *image_attr_reply;
 
     EPHYR_RETURN_VAL_IF_FAIL(a_buf, FALSE);
 
     EPHYR_LOG("enter, num_clip_rects: %d\n", a_clip_rect_nums);
 
-    memset(&gc_values, 0, sizeof(gc_values));
-    gc = XCreateGC(dpy, hostx_get_window(a_screen_num), 0L, &gc_values);
-    if (!gc) {
-        EPHYR_LOG_ERROR("failed to create gc \n");
+    gc = xcb_generate_id(conn);
+    xcb_create_gc(conn, gc, hostx_get_window(a_screen_num), 0, NULL);
+
+    image_attr_cookie = xcb_xv_query_image_attributes(conn,
+                                                      a_port_id,
+                                                      a_image_id,
+                                                      a_image_width,
+                                                      a_image_height);
+    image_attr_reply = xcb_xv_query_image_attributes_reply(conn,
+                                                           image_attr_cookie,
+                                                           NULL);
+    if (!image_attr_reply)
         goto out;
-    }
-    xv_image = (XvImage *) XvCreateImage(hostx_get_display(),
-                                         a_port_id, a_image_id,
-                                         NULL, a_image_width, a_image_height);
-    if (!xv_image) {
-        EPHYR_LOG_ERROR("failed to create image\n");
-        goto out;
-    }
-    xv_image->data = (char *) a_buf;
+    data_len = image_attr_reply->data_size;
+    width = image_attr_reply->width;
+    height = image_attr_reply->height;
+    free(image_attr_reply);
+
     if (a_clip_rect_nums) {
         int i = 0;
-
-        rects = calloc(a_clip_rect_nums, sizeof(XRectangle));
-        for (i = 0; i < a_clip_rect_nums; i++) {
+        rects = calloc(a_clip_rect_nums, sizeof(xcb_rectangle_t));
+        for (i=0; i < a_clip_rect_nums; i++) {
             rects[i].x = a_clip_rects[i].x1;
             rects[i].y = a_clip_rects[i].y1;
             rects[i].width = a_clip_rects[i].x2 - a_clip_rects[i].x1;
@@ -774,31 +612,28 @@ ephyrHostXVPutImage(int a_screen_num,
             EPHYR_LOG("(x,y,w,h): (%d,%d,%d,%d)\n",
                       rects[i].x, rects[i].y, rects[i].width, rects[i].height);
         }
-        XSetClipRectangles(dpy, gc, 0, 0, rects, a_clip_rect_nums, YXBanded);
-        /*this always returns 1 */
-    }
-    res = XvPutImage(dpy, a_port_id,
-                     hostx_get_window(a_screen_num),
-                     gc, xv_image,
+        xcb_set_clip_rectangles(conn,
+                                XCB_CLIP_ORDERING_YX_BANDED,
+                                gc,
+                                0,
+                                0,
+                                a_clip_rect_nums,
+                                rects);
+	free(rects);
+    }
+    xcb_xv_put_image(conn,
+                     a_port_id,
+                     hostx_get_window (a_screen_num),
+                     gc,
+                     a_image_id,
                      a_src_x, a_src_y, a_src_w, a_src_h,
-                     a_drw_x, a_drw_y, a_drw_w, a_drw_h);
-    if (res != Success) {
-        EPHYR_LOG_ERROR("XvPutImage() failed: %d\n", res);
-        goto out;
-    }
+                     a_drw_x, a_drw_y, a_drw_w, a_drw_h,
+                     width, height,
+                     data_len, a_buf);
     is_ok = TRUE;
 
- out:
-    if (xv_image) {
-        XFree(xv_image);
-        xv_image = NULL;
-    }
-    if (gc) {
-        XFreeGC(dpy, gc);
-        gc = NULL;
-    }
-    free(rects);
-    rects = NULL;
+out:
+    xcb_free_gc(conn, gc);
     EPHYR_LOG("leave\n");
     return is_ok;
 }
@@ -809,34 +644,22 @@ ephyrHostXVPutVideo(int a_screen_num, int a_port_id,
                     int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h)
 {
     Bool is_ok = FALSE;
-    int res = FALSE;
-    GC gc = 0;
-    XGCValues gc_values;
-    Display *dpy = hostx_get_display();
+    xcb_gcontext_t gc;
+    xcb_connection_t *conn = hostx_get_xcbconn();
 
-    EPHYR_RETURN_VAL_IF_FAIL(dpy, FALSE);
+    EPHYR_RETURN_VAL_IF_FAIL(conn, FALSE);
 
-    gc = XCreateGC(dpy, hostx_get_window(a_screen_num), 0L, &gc_values);
-    if (!gc) {
-        EPHYR_LOG_ERROR("failed to create gc \n");
-        goto out;
-    }
-    res = XvPutVideo(dpy, a_port_id, hostx_get_window(a_screen_num), gc,
+    gc = xcb_generate_id(conn);
+    xcb_create_gc(conn, gc, hostx_get_window (a_screen_num), 0, NULL);
+    xcb_xv_put_video(conn,
+                     a_port_id,
+                     hostx_get_window (a_screen_num), gc,
                      a_vid_x, a_vid_y, a_vid_w, a_vid_h,
                      a_drw_x, a_drw_y, a_drw_w, a_drw_h);
-
-    if (res != Success) {
-        EPHYR_LOG_ERROR("XvPutVideo() failed: %d\n", res);
-        goto out;
-    }
-
     is_ok = TRUE;
 
- out:
-    if (gc) {
-        XFreeGC(dpy, gc);
-        gc = NULL;
-    }
+    xcb_free_gc(conn, gc);
+
     return is_ok;
 }
 
@@ -845,36 +668,26 @@ ephyrHostXVGetVideo(int a_screen_num, int a_port_id,
                     int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h,
                     int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h)
 {
-    Bool is_ok = FALSE;
-    int res = FALSE;
-    GC gc = 0;
-    XGCValues gc_values;
-    Display *dpy = hostx_get_display();
+    xcb_gcontext_t gc;
+    xcb_connection_t *conn = hostx_get_xcbconn();
 
-    EPHYR_RETURN_VAL_IF_FAIL(dpy, FALSE);
+    EPHYR_RETURN_VAL_IF_FAIL(conn, FALSE);
 
-    gc = XCreateGC(dpy, hostx_get_window(a_screen_num), 0L, &gc_values);
-    if (!gc) {
-        EPHYR_LOG_ERROR("failed to create gc \n");
-        goto out;
-    }
-    res = XvGetVideo(dpy, a_port_id, hostx_get_window(a_screen_num), gc,
+    gc = xcb_generate_id(conn);
+    xcb_create_gc(conn,
+                  gc,
+                  hostx_get_window (a_screen_num),
+                  0, NULL);
+    xcb_xv_get_video(conn,
+                     a_port_id,
+                     hostx_get_window (a_screen_num),
+                     gc,
                      a_vid_x, a_vid_y, a_vid_w, a_vid_h,
                      a_drw_x, a_drw_y, a_drw_w, a_drw_h);
 
-    if (res != Success) {
-        EPHYR_LOG_ERROR("XvGetVideo() failed: %d\n", res);
-        goto out;
-    }
-
-    is_ok = TRUE;
+    xcb_free_gc(conn, gc);
 
- out:
-    if (gc) {
-        XFreeGC(dpy, gc);
-        gc = NULL;
-    }
-    return is_ok;
+    return TRUE;
 }
 
 Bool
@@ -882,36 +695,26 @@ ephyrHostXVPutStill(int a_screen_num, int a_port_id,
                     int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h,
                     int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h)
 {
-    Bool is_ok = FALSE;
-    int res = FALSE;
-    GC gc = 0;
-    XGCValues gc_values;
-    Display *dpy = hostx_get_display();
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    xcb_gcontext_t gc;
 
-    EPHYR_RETURN_VAL_IF_FAIL(dpy, FALSE);
+    EPHYR_RETURN_VAL_IF_FAIL(conn, FALSE);
 
-    gc = XCreateGC(dpy, hostx_get_window(a_screen_num), 0L, &gc_values);
-    if (!gc) {
-        EPHYR_LOG_ERROR("failed to create gc \n");
-        goto out;
-    }
-    res = XvPutStill(dpy, a_port_id, hostx_get_window(a_screen_num), gc,
+    gc = xcb_generate_id(conn);
+    xcb_create_gc(conn,
+                  gc,
+                  hostx_get_window (a_screen_num),
+                  0, NULL);
+    xcb_xv_put_still(conn,
+                     a_port_id,
+                     hostx_get_window (a_screen_num),
+                     gc,
                      a_vid_x, a_vid_y, a_vid_w, a_vid_h,
                      a_drw_x, a_drw_y, a_drw_w, a_drw_h);
 
-    if (res != Success) {
-        EPHYR_LOG_ERROR("XvPutStill() failed: %d\n", res);
-        goto out;
-    }
-
-    is_ok = TRUE;
+    xcb_free_gc(conn, gc);
 
- out:
-    if (gc) {
-        XFreeGC(dpy, gc);
-        gc = NULL;
-    }
-    return is_ok;
+    return TRUE;
 }
 
 Bool
@@ -919,57 +722,38 @@ ephyrHostXVGetStill(int a_screen_num, int a_port_id,
                     int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h,
                     int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h)
 {
-    Bool is_ok = FALSE;
-    int res = FALSE;
-    GC gc = 0;
-    XGCValues gc_values;
-    Display *dpy = hostx_get_display();
+    xcb_gcontext_t gc;
+    xcb_connection_t *conn = hostx_get_xcbconn();
 
-    EPHYR_RETURN_VAL_IF_FAIL(dpy, FALSE);
+    EPHYR_RETURN_VAL_IF_FAIL(conn, FALSE);
 
-    gc = XCreateGC(dpy, hostx_get_window(a_screen_num), 0L, &gc_values);
-    if (!gc) {
-        EPHYR_LOG_ERROR("failed to create gc \n");
-        goto out;
-    }
-    res = XvGetStill(dpy, a_port_id, hostx_get_window(a_screen_num), gc,
+    gc = xcb_generate_id(conn);
+    xcb_create_gc(conn,
+                  gc,
+                  hostx_get_window (a_screen_num),
+                  0, NULL);
+    xcb_xv_get_still(conn,
+                     a_port_id,
+                     hostx_get_window (a_screen_num),
+                     gc,
                      a_vid_x, a_vid_y, a_vid_w, a_vid_h,
                      a_drw_x, a_drw_y, a_drw_w, a_drw_h);
+    xcb_free_gc(conn, gc);
 
-    if (res != Success) {
-        EPHYR_LOG_ERROR("XvGetStill() failed: %d\n", res);
-        goto out;
-    }
-
-    is_ok = TRUE;
-
- out:
-    if (gc) {
-        XFreeGC(dpy, gc);
-        gc = NULL;
-    }
-    return is_ok;
+    return TRUE;
 }
 
 Bool
 ephyrHostXVStopVideo(int a_screen_num, int a_port_id)
 {
-    int ret = 0;
-    Bool is_ok = FALSE;
-    Display *dpy = hostx_get_display();
+    xcb_connection_t *conn = hostx_get_xcbconn();
 
-    EPHYR_RETURN_VAL_IF_FAIL(dpy, FALSE);
+    EPHYR_RETURN_VAL_IF_FAIL(conn, FALSE);
 
     EPHYR_LOG("enter\n");
 
-    ret = XvStopVideo(dpy, a_port_id, hostx_get_window(a_screen_num));
-    if (ret != Success) {
-        EPHYR_LOG_ERROR("XvStopVideo() failed: %d \n", ret);
-        goto out;
-    }
-    is_ok = TRUE;
+    xcb_xv_stop_video(conn, a_port_id, hostx_get_window (a_screen_num));
 
- out:
     EPHYR_LOG("leave\n");
-    return is_ok;
+    return TRUE;
 }
diff --git a/hw/kdrive/ephyr/ephyrhostvideo.h b/hw/kdrive/ephyr/ephyrhostvideo.h
index 0d31772..b946add 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.h
+++ b/hw/kdrive/ephyr/ephyrhostvideo.h
@@ -28,8 +28,9 @@
 #ifndef __EPHYRHOSTVIDEO_H__
 #define __EPHYRHOSTVIDEO_H__
 
-typedef void *EphyrHostXVAdaptor;
 typedef struct _EphyrHostXVAdaptorArray EphyrHostXVAdaptorArray;
+#include <xcb/xv.h>
+#include <X11/Xdefs.h>
 
 typedef struct _EphyrHostVideoFormat {
     char depth;
@@ -48,13 +49,6 @@ typedef struct _EphyrHostEncoding {
     EphyrHostRational rate;
 } EphyrHostEncoding;
 
-typedef struct _EphyrHostAttribute {
-    int flags;
-    int min_value;
-    int max_value;
-    char *name;
-} EphyrHostAttribute;
-
 typedef struct _EphyrHostImageFormat {
     int id;                     /* Unique descriptor for the format */
     int type;                   /* XvRGB, XvYUV */
@@ -95,32 +89,32 @@ void ephyrHostFree(void *a_pointer);
 /*
  * host adaptor array
  */
-Bool ephyrHostXVQueryAdaptors(EphyrHostXVAdaptorArray ** a_adaptors);
-void ephyrHostXVAdaptorArrayDelete(EphyrHostXVAdaptorArray * a_adaptors);
-int ephyrHostXVAdaptorArrayGetSize(const EphyrHostXVAdaptorArray * a_this);
-EphyrHostXVAdaptor *ephyrHostXVAdaptorArrayAt(const EphyrHostXVAdaptorArray *
-                                              a_this, int a_index);
+Bool ephyrHostXVQueryAdaptors(xcb_xv_query_adaptors_reply_t **a_adaptors);
+void ephyrHostXVAdaptorArrayDelete(xcb_xv_query_adaptors_reply_t *a_adaptors);
+int ephyrHostXVAdaptorArrayGetSize(const xcb_xv_query_adaptors_reply_t *a_this);
+xcb_xv_adaptor_info_t* ephyrHostXVAdaptorArrayAt(const xcb_xv_query_adaptors_reply_t *a_this,
+                                                 int a_index);
 
 /*
  * host adaptor
  */
 
-char ephyrHostXVAdaptorGetType(const EphyrHostXVAdaptor * a_this);
-const char *ephyrHostXVAdaptorGetName(const EphyrHostXVAdaptor * a_this);
+char ephyrHostXVAdaptorGetType(const xcb_xv_adaptor_info_t *a_this);
+char* ephyrHostXVAdaptorGetName(const xcb_xv_adaptor_info_t *a_this);
 EphyrHostVideoFormat *ephyrHostXVAdaptorGetVideoFormats
-    (const EphyrHostXVAdaptor * a_this, int *a_nb_formats);
-int ephyrHostXVAdaptorGetNbPorts(const EphyrHostXVAdaptor * a_this);
-int ephyrHostXVAdaptorGetFirstPortID(const EphyrHostXVAdaptor * a_this);
+    (const xcb_xv_adaptor_info_t *a_this, int *a_nb_formats);
+int ephyrHostXVAdaptorGetNbPorts(const xcb_xv_adaptor_info_t *a_this);
+int ephyrHostXVAdaptorGetFirstPortID(const xcb_xv_adaptor_info_t *a_this);
 
-Bool ephyrHostXVAdaptorHasPutVideo(const EphyrHostXVAdaptor * a_this,
+Bool ephyrHostXVAdaptorHasPutVideo(const xcb_xv_adaptor_info_t *a_this,
                                    Bool *a_result);
-Bool ephyrHostXVAdaptorHasGetVideo(const EphyrHostXVAdaptor * a_this,
+Bool ephyrHostXVAdaptorHasGetVideo(const xcb_xv_adaptor_info_t *a_this,
                                    Bool *a_result);
-Bool ephyrHostXVAdaptorHasPutStill(const EphyrHostXVAdaptor * a_this,
+Bool ephyrHostXVAdaptorHasPutStill(const xcb_xv_adaptor_info_t *a_this,
                                    Bool *a_result);
-Bool ephyrHostXVAdaptorHasGetStill(const EphyrHostXVAdaptor * a_this,
+Bool ephyrHostXVAdaptorHasGetStill(const xcb_xv_adaptor_info_t *a_this,
                                    Bool *a_result);
-Bool ephyrHostXVAdaptorHasPutImage(const EphyrHostXVAdaptor * a_this,
+Bool ephyrHostXVAdaptorHasPutImage(const xcb_xv_adaptor_info_t *a_this,
                                    Bool *a_result);
 
 /*
@@ -137,10 +131,9 @@ void ephyrHostEncodingsDelete(EphyrHostEncoding * a_encodings,
  * attribute
  */
 Bool ephyrHostXVQueryPortAttributes(int a_port_id,
-                                    EphyrHostAttribute ** a_attributes,
-                                    int *a_num_attributes);
+                                    xcb_xv_query_port_attributes_reply_t **a_attributes);
 
-void ephyrHostAttributesDelete(EphyrHostAttribute * a_attributes);
+void ephyrHostAttributesDelete(xcb_xv_query_port_attributes_reply_t *a_attributes);
 
 /*
  * image format
diff --git a/hw/kdrive/ephyr/ephyrvideo.c b/hw/kdrive/ephyr/ephyrvideo.c
index dfc29f5..345c7b9 100644
--- a/hw/kdrive/ephyr/ephyrvideo.c
+++ b/hw/kdrive/ephyr/ephyrvideo.c
@@ -39,7 +39,7 @@
 #include "ephyrhostvideo.h"
 
 struct _EphyrXVPriv {
-    EphyrHostXVAdaptorArray *host_adaptors;
+    xcb_xv_query_adaptors_reply_t *host_adaptors;
     KdVideoAdaptorPtr adaptors;
     int num_adaptors;
 };
@@ -381,23 +381,29 @@ videoEncodingDup(EphyrHostEncoding * a_encodings, int a_num_encodings)
 }
 
 static KdAttributePtr
-portAttributesDup(EphyrHostAttribute * a_encodings, int a_num_encodings)
+portAttributesDup(const xcb_xv_query_port_attributes_reply_t *a_encodings)
 {
     int i = 0;
     KdAttributePtr result = NULL;
+    xcb_xv_attribute_info_iterator_t it;
 
-    EPHYR_RETURN_VAL_IF_FAIL(a_encodings && a_num_encodings, NULL);
+    EPHYR_RETURN_VAL_IF_FAIL(a_encodings, NULL);
 
-    result = calloc(a_num_encodings, sizeof(KdAttributeRec));
+    result = calloc(a_encodings->num_attributes, sizeof(KdAttributeRec));
     if (!result) {
         EPHYR_LOG_ERROR("failed to allocate attributes\n");
         return NULL;
     }
-    for (i = 0; i < a_num_encodings; i++) {
-        result[i].flags = a_encodings[i].flags;
-        result[i].min_value = a_encodings[i].min_value;
-        result[i].max_value = a_encodings[i].max_value;
-        result[i].name = strdup(a_encodings[i].name);
+    it = xcb_xv_query_port_attributes_attributes_iterator(a_encodings);
+    for (i = 0;
+         i < a_encodings->num_attributes;
+         xcb_xv_attribute_info_next(&it), i++) {
+        result[i].flags = it.data->flags;
+        result[i].min_value = it.data->min;
+        result[i].max_value = it.data->max;
+        result[i].name = malloc(it.data->size + 1);
+	memcpy (result[i].name, xcb_xv_attribute_info_name(it.data), it.data->size);
+	result[i].name[it.data->size] = '\0';
     }
     return result;
 }
@@ -405,13 +411,13 @@ portAttributesDup(EphyrHostAttribute * a_encodings, int a_num_encodings)
 static Bool
 ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this)
 {
-    EphyrHostXVAdaptor *cur_host_adaptor = NULL;
+    xcb_xv_adaptor_info_t *cur_host_adaptor = NULL;
     EphyrHostVideoFormat *video_formats = NULL;
     EphyrHostEncoding *encodings = NULL;
-    EphyrHostAttribute *attributes = NULL;
+    xcb_xv_query_port_attributes_reply_t *attributes = NULL;
     EphyrHostImageFormat *image_formats = NULL;
     int num_video_formats = 0, base_port_id = 0,
-        num_attributes = 0, num_formats = 0, i = 0, port_priv_offset = 0;
+        num_formats = 0, i = 0, port_priv_offset = 0;
     unsigned num_encodings = 0;
     Bool is_ok = FALSE;
 
@@ -458,10 +464,8 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this)
         a_this->adaptors[i].type |= XvWindowMask;
         a_this->adaptors[i].flags =
             VIDEO_OVERLAID_IMAGES | VIDEO_CLIP_TO_VIEWPORT;
-        if (ephyrHostXVAdaptorGetName(cur_host_adaptor))
-            a_this->adaptors[i].name =
-                strdup(ephyrHostXVAdaptorGetName(cur_host_adaptor));
-        else
+        a_this->adaptors[i].name = ephyrHostXVAdaptorGetName(cur_host_adaptor);
+        if (!a_this->adaptors[i].name)
             a_this->adaptors[i].name = strdup("Xephyr Video Overlay");
         base_port_id = ephyrHostXVAdaptorGetFirstPortID(cur_host_adaptor);
         if (base_port_id < 0) {
@@ -504,15 +508,14 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this)
             port_priv->xv_priv = a_this;
             a_this->adaptors[i].pPortPrivates[j].ptr = port_priv;
         }
-        if (!ephyrHostXVQueryPortAttributes(base_port_id,
-                                            &attributes, &num_attributes)) {
+        if (!ephyrHostXVQueryPortAttributes(base_port_id, &attributes)) {
             EPHYR_LOG_ERROR("failed to get port attribute "
                             "for adaptor %d\n", i);
             continue;
         }
         a_this->adaptors[i].pAttributes =
-            portAttributesDup(attributes, num_attributes);
-        a_this->adaptors[i].nAttributes = num_attributes;
+            portAttributesDup(attributes);
+        a_this->adaptors[i].nAttributes = attributes->num_attributes;
         /*make sure atoms of attrs names are created in xephyr */
         for (j = 0; j < a_this->adaptors[i].nAttributes; j++) {
             if (a_this->adaptors[i].pAttributes[j].name)
@@ -548,7 +551,7 @@ ephyrXVPrivSetAdaptorsHooks(EphyrXVPriv * a_this)
 {
     int i = 0;
     Bool has_it = FALSE;
-    EphyrHostXVAdaptor *cur_host_adaptor = NULL;
+    xcb_xv_adaptor_info_t *cur_host_adaptor = NULL;
 
     EPHYR_RETURN_VAL_IF_FAIL(a_this, FALSE);
 
commit 3ea75a59d5fec3c4099388724942e216f2344328
Author: Julien Cristau <jcristau at debian.org>
Date:   Mon Jun 21 17:20:32 2010 +0100

    Xephyr: use xcb for event handling
    
    v2: Rebase on indentation changes, squash in a simpler variant of the
        later event compression patch, fix server hang or segfault on
        window close by reimplementing the x_io_error_handler in the new
        XCB event loop (anholt).
    
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net> (v1)
    Signed-off-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index 3d3519b..07a2772 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -942,169 +942,195 @@ host_screen_from_window(Window w)
 int
 hostx_get_event(EphyrHostXEvent * ev)
 {
-    XEvent xev;
+    xcb_generic_event_t *xev;
     static int grabbed_screen = -1;
     static xcb_key_symbols_t *keysyms;
 
     if (!keysyms)
         keysyms = xcb_key_symbols_alloc(HostX.conn);
 
-    if (XPending(HostX.dpy)) {
-        XNextEvent(HostX.dpy, &xev);
-
-        switch (xev.type) {
-        case Expose:
-            /* Not so great event compression, but works ok */
-            while (XCheckTypedWindowEvent(HostX.dpy, xev.xexpose.window,
-                                          Expose, &xev));
-            {
-                struct EphyrHostScreen *host_screen =
-                    host_screen_from_window(xev.xexpose.window);
-                if (host_screen) {
-                    hostx_paint_rect(host_screen->info, 0, 0, 0, 0,
-                                     host_screen->win_width,
-                                     host_screen->win_height);
-                }
-                else {
-                    EPHYR_LOG_ERROR("failed to get host screen\n");
-                    ev->type = EPHYR_EV_EXPOSE;
-                    ev->data.expose.window = xev.xexpose.window;
-                    return 1;
-                }
-            }
-            return 0;
-
-        case MotionNotify:
-        {
-            struct EphyrHostScreen *host_screen =
-                host_screen_from_window(xev.xmotion.window);
-
-            ev->type = EPHYR_EV_MOUSE_MOTION;
-            ev->data.mouse_motion.x = xev.xmotion.x;
-            ev->data.mouse_motion.y = xev.xmotion.y;
-            ev->data.mouse_motion.window = xev.xmotion.window;
-            ev->data.mouse_motion.screen =
-                (host_screen ? host_screen->mynum : -1);
+    xev = xcb_poll_for_event(HostX.conn);
+    if (!xev) {
+        /* If our XCB connection has died (for example, our window was
+         * closed), exit now.
+         */
+        if (xcb_connection_has_error(HostX.conn)) {
+            CloseWellKnownConnections();
+            OsCleanup(1);
+            exit(1);
         }
-            return 1;
 
-        case ButtonPress:
-            ev->type = EPHYR_EV_MOUSE_PRESS;
-            ev->key_state = xev.xkey.state;
-            /* 
-             * This is a bit hacky. will break for button 5 ( defined as 0x10 )
-             * Check KD_BUTTON defines in kdrive.h 
-             */
-            ev->data.mouse_down.button_num = 1 << (xev.xbutton.button - 1);
-            return 1;
+        return 0;
+    }
 
-        case ButtonRelease:
-            ev->type = EPHYR_EV_MOUSE_RELEASE;
-            ev->key_state = xev.xkey.state;
-            ev->data.mouse_up.button_num = 1 << (xev.xbutton.button - 1);
-            return 1;
+    switch (xev->response_type & 0x7f) {
+    case XCB_EXPOSE: {
+        xcb_expose_event_t *expose = (xcb_expose_event_t *)xev;
+        struct EphyrHostScreen *host_screen =
+            host_screen_from_window(expose->window);
 
-        case KeyPress:
-        {
-            ev->type = EPHYR_EV_KEY_PRESS;
-            ev->key_state = xev.xkey.state;
-            ev->data.key_down.scancode = xev.xkey.keycode;
+        /* Wait for the last expose event in a series of cliprects
+         * to actually paint our screen.
+         */
+        if (expose->count != 0)
+            break;
+
+        if (host_screen) {
+            hostx_paint_rect(host_screen->info, 0, 0, 0, 0,
+                             host_screen->win_width,
+                             host_screen->win_height);
+        }
+        else {
+            EPHYR_LOG_ERROR("failed to get host screen\n");
+            ev->type = EPHYR_EV_EXPOSE;
+            ev->data.expose.window = expose->window;
+            free(xev);
             return 1;
         }
-        case KeyRelease:
-            if ((xcb_key_symbols_get_keysym(keysyms,xev.xkey.keycode, 0) == XK_Shift_L
-                 || xcb_key_symbols_get_keysym(keysyms,xev.xkey.keycode, 0) == XK_Shift_R)
-                && (xev.xkey.state & XCB_MOD_MASK_CONTROL)) {
-                struct EphyrHostScreen *host_screen =
-                    host_screen_from_window(xev.xexpose.window);
-
-                if (grabbed_screen != -1) {
-                    xcb_ungrab_keyboard(HostX.conn, XCB_TIME_CURRENT_TIME);
+        return 0;
+    }
+
+    case XCB_MOTION_NOTIFY: {
+        xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *)xev;
+        struct EphyrHostScreen *host_screen =
+            host_screen_from_window(motion->event);
+
+        ev->type = EPHYR_EV_MOUSE_MOTION;
+        ev->data.mouse_motion.x = motion->event_x;
+        ev->data.mouse_motion.y = motion->event_y;
+        ev->data.mouse_motion.window = motion->event;
+        ev->data.mouse_motion.screen =
+            (host_screen ? host_screen->mynum : -1);
+        free(xev);
+        return 1;
+    }
+
+    case XCB_BUTTON_PRESS: {
+        xcb_button_press_event_t *button = (xcb_button_press_event_t *)xev;
+        ev->type = EPHYR_EV_MOUSE_PRESS;
+        ev->key_state = button->state;
+        /* 
+         * This is a bit hacky. will break for button 5 ( defined as 0x10 )
+         * Check KD_BUTTON defines in kdrive.h 
+         */
+        ev->data.mouse_down.button_num = 1 << (button->detail - 1);
+        free(xev);
+        return 1;
+    }
+
+    case XCB_BUTTON_RELEASE: {
+        xcb_button_release_event_t *button = (xcb_button_release_event_t *)xev;
+        ev->type = EPHYR_EV_MOUSE_RELEASE;
+        ev->key_state = button->state;
+        ev->data.mouse_up.button_num = 1 << (button->detail-1);
+        free(xev);
+        return 1;
+    }
+
+    case XCB_KEY_PRESS: {
+        xcb_key_press_event_t *key = (xcb_key_press_event_t *)xev;
+        ev->type = EPHYR_EV_KEY_PRESS;
+        ev->key_state = key->state;
+        ev->data.key_down.scancode = key->detail;
+        free(xev);
+        return 1;
+    }
+
+    case XCB_KEY_RELEASE: {
+        xcb_key_release_event_t *key = (xcb_key_release_event_t *)xev;
+        if ((xcb_key_symbols_get_keysym(keysyms, key->detail, 0) == XK_Shift_L
+             || xcb_key_symbols_get_keysym(keysyms, key->detail, 0) == XK_Shift_R)
+            && (key->state & XCB_MOD_MASK_CONTROL)) {
+            struct EphyrHostScreen *host_screen =
+                host_screen_from_window(key->event);
+
+            if (grabbed_screen != -1) {
+                xcb_ungrab_keyboard(HostX.conn, XCB_TIME_CURRENT_TIME);
+                xcb_ungrab_pointer(HostX.conn, XCB_TIME_CURRENT_TIME);
+                grabbed_screen = -1;
+                hostx_set_win_title(host_screen->info,
+                                    "(ctrl+shift grabs mouse and keyboard)");
+            }
+            else {
+                /* Attempt grab */
+                xcb_grab_keyboard_cookie_t kbgrabc =
+                    xcb_grab_keyboard(HostX.conn,
+                                      True,
+                                      host_screen->win,
+                                      XCB_TIME_CURRENT_TIME,
+                                      XCB_GRAB_MODE_ASYNC,
+                                      XCB_GRAB_MODE_ASYNC);
+                xcb_grab_keyboard_reply_t *kbgrabr;
+                xcb_grab_pointer_cookie_t pgrabc =
+                    xcb_grab_pointer(HostX.conn,
+                                     True,
+                                     host_screen->win,
+                                     0,
+                                     XCB_GRAB_MODE_ASYNC,
+                                     XCB_GRAB_MODE_ASYNC,
+                                     host_screen->win,
+                                     XCB_NONE,
+                                     XCB_TIME_CURRENT_TIME);
+                xcb_grab_pointer_reply_t *pgrabr;
+                kbgrabr = xcb_grab_keyboard_reply(HostX.conn, kbgrabc, NULL);
+                if (!kbgrabr || kbgrabr->status != XCB_GRAB_STATUS_SUCCESS) {
+                    xcb_discard_reply(HostX.conn, pgrabc.sequence);
                     xcb_ungrab_pointer(HostX.conn, XCB_TIME_CURRENT_TIME);
-                    grabbed_screen = -1;
-                    hostx_set_win_title(host_screen->info,
-                                        "(ctrl+shift grabs mouse and keyboard)");
-                }
-                else {
-                    /* Attempt grab */
-                    xcb_grab_keyboard_cookie_t kbgrabc =
-                        xcb_grab_keyboard(HostX.conn,
-                                          True,
-                                          host_screen->win,
-                                          XCB_TIME_CURRENT_TIME,
-                                          XCB_GRAB_MODE_ASYNC,
-                                          XCB_GRAB_MODE_ASYNC);
-                    xcb_grab_keyboard_reply_t *kbgrabr;
-                    xcb_grab_pointer_cookie_t pgrabc =
-                        xcb_grab_pointer(HostX.conn,
-                                         True,
-                                         host_screen->win,
-                                         0,
-                                         XCB_GRAB_MODE_ASYNC,
-                                         XCB_GRAB_MODE_ASYNC,
-                                         host_screen->win,
-                                         XCB_NONE,
-                                         XCB_TIME_CURRENT_TIME);
-                    xcb_grab_pointer_reply_t *pgrabr;
-                    kbgrabr = xcb_grab_keyboard_reply(HostX.conn, kbgrabc, NULL);
-                    if (!kbgrabr || kbgrabr->status != XCB_GRAB_STATUS_SUCCESS) {
-                        xcb_discard_reply(HostX.conn, pgrabc.sequence);
-                        xcb_ungrab_pointer(HostX.conn, XCB_TIME_CURRENT_TIME);
-                    } else {
-                        pgrabr = xcb_grab_pointer_reply(HostX.conn, pgrabc, NULL);
-                        if (!pgrabr || pgrabr->status != XCB_GRAB_STATUS_SUCCESS)
-                            {
-                                xcb_ungrab_keyboard(HostX.conn,
-                                                    XCB_TIME_CURRENT_TIME);
-                            } else {
-                            grabbed_screen = host_screen->mynum;
-                            hostx_set_win_title
-                                (host_screen->info,
-                                 "(ctrl+shift releases mouse and keyboard)");
-                        }
+                } else {
+                    pgrabr = xcb_grab_pointer_reply(HostX.conn, pgrabc, NULL);
+                    if (!pgrabr || pgrabr->status != XCB_GRAB_STATUS_SUCCESS)
+                        {
+                            xcb_ungrab_keyboard(HostX.conn,
+                                                XCB_TIME_CURRENT_TIME);
+                        } else {
+                        grabbed_screen = host_screen->mynum;
+                        hostx_set_win_title
+                            (host_screen->info,
+                             "(ctrl+shift releases mouse and keyboard)");
                     }
                 }
             }
+        }
 
-            /* Still send the release event even if above has happened
-             * server will get confused with just an up event. 
-             * Maybe it would be better to just block shift+ctrls getting to
-             * kdrive all togeather. 
-             */
-            ev->type = EPHYR_EV_KEY_RELEASE;
-            ev->key_state = xev.xkey.state;
-            ev->data.key_up.scancode = xev.xkey.keycode;
-            return 1;
+        /* Still send the release event even if above has happened
+         * server will get confused with just an up event. 
+         * Maybe it would be better to just block shift+ctrls getting to
+         * kdrive all togeather. 
+         */
+        ev->type = EPHYR_EV_KEY_RELEASE;
+        ev->key_state = key->state;
+        ev->data.key_up.scancode = key->detail;
+        return 1;
+    }
 
-        case ConfigureNotify:
+    case ConfigureNotify:
         {
             struct EphyrHostScreen *host_screen;
+            xcb_configure_notify_event_t *configure =
+                (xcb_configure_notify_event_t *)xev;
 
-            /* event compression as for Expose events, cause
-             * we don't want to resize the framebuffer for
-             * every single change */
-            while (XCheckTypedWindowEvent(HostX.dpy, xev.xconfigure.window,
-                                          ConfigureNotify, &xev));
-            host_screen = host_screen_from_window(xev.xconfigure.window);
+            host_screen = host_screen_from_window(configure->window);
 
             if (!host_screen ||
                 (host_screen->win_pre_existing == None && !EphyrWantResize)) {
+                free(xev);
                 return 0;
             }
 
             ev->type = EPHYR_EV_CONFIGURE;
-            ev->data.configure.width = xev.xconfigure.width;
-            ev->data.configure.height = xev.xconfigure.height;
-            ev->data.configure.window = xev.xconfigure.window;
+            ev->data.configure.width = configure->width;
+            ev->data.configure.height = configure->height;
+            ev->data.configure.window = configure->window;
             ev->data.configure.screen = host_screen->mynum;
+            free(xev);
 
             return 1;
         }
-        default:
-            break;
+    default:
+        break;
 
-        }
     }
+    free(xev);
     return 0;
 }
 
commit ff26845252889f7cc3258a0d3aa116189acc6aae
Author: Julien Cristau <jcristau at debian.org>
Date:   Thu Jun 24 23:45:16 2010 +0100

    Xephyr: some more hostx.c xcb-ification
    
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index d984db9..3d3519b 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -368,9 +368,9 @@ hostx_init(void)
     HostX.conn = XGetXCBConnection(HostX.dpy);
     HostX.screen = DefaultScreen(HostX.dpy);
     screen = xcb_aux_get_screen(HostX.conn, HostX.screen);
-    HostX.winroot = RootWindow(HostX.dpy, HostX.screen);
+    HostX.winroot = screen->root;
     HostX.gc = xcb_generate_id(HostX.conn);
-    HostX.depth = DefaultDepth(HostX.dpy, HostX.screen);
+    HostX.depth = screen->root_depth;
     HostX.visual  = xcb_aux_find_visual_by_id(screen, screen->root_visual);
 
     xcb_create_gc(HostX.conn, HostX.gc, HostX.winroot, 0, NULL);
@@ -439,8 +439,8 @@ hostx_init(void)
                                  "(ctrl+shift grabs mouse and keyboard)");
 
             if (HostX.use_fullscreen) {
-                host_screen->win_width  = DisplayWidth(HostX.dpy, HostX.screen);
-                host_screen->win_height = DisplayHeight(HostX.dpy, HostX.screen);
+                host_screen->win_width  = screen->width_in_pixels;
+                host_screen->win_height = screen->height_in_pixels;
 
                 hostx_set_fullscreen_hint();
             }
@@ -1123,7 +1123,7 @@ hostx_get_xcbconn(void)
 int
 hostx_get_screen(void)
 {
-    return DefaultScreen(HostX.dpy);
+    return HostX.screen;
 }
 
 int
commit 9b55f76a265aab0d9943a40208a38800e5782ba5
Author: Julien Cristau <jcristau at debian.org>
Date:   Thu Jun 24 23:35:15 2010 +0100

    Xephyr: move HostX.visual to xcb
    
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index 4bcc902..d984db9 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -94,7 +94,7 @@ struct EphyrHostXVars {
     Display *dpy;
     xcb_connection_t *conn;
     int screen;
-    Visual *visual;
+    xcb_visualtype_t *visual;
     Window winroot;
     xcb_gcontext_t  gc;
     int depth;
@@ -371,7 +371,7 @@ hostx_init(void)
     HostX.winroot = RootWindow(HostX.dpy, HostX.screen);
     HostX.gc = xcb_generate_id(HostX.conn);
     HostX.depth = DefaultDepth(HostX.dpy, HostX.screen);
-    HostX.visual = DefaultVisual(HostX.dpy, HostX.screen);
+    HostX.visual  = xcb_aux_find_visual_by_id(screen, screen->root_visual);
 
     xcb_create_gc(HostX.conn, HostX.gc, HostX.winroot, 0, NULL);
     cookie_WINDOW_STATE = xcb_intern_atom(HostX.conn, False,
@@ -593,10 +593,10 @@ hostx_get_bpp(EphyrScreenInfo screen)
     if (!host_screen)
         return 0;
 
-    if (host_depth_matches_server(host_screen))
-        return HostX.visual->bits_per_rgb;
+    if (host_depth_matches_server (host_screen))
+        return HostX.visual->bits_per_rgb_value;
     else
-        return host_screen->server_depth;       /*XXX correct ? */
+        return host_screen->server_depth; /*XXX correct ?*/
 }
 
 void
commit 126312fb4a6e06024a306341e675163108426390
Author: Julien Cristau <jcristau at debian.org>
Date:   Thu Jun 24 23:26:48 2010 +0100

    Xephyr: replace XKeycodeToKeysym with xcb-keysyms
    
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Julien Cristau <jcristau at debian.org>

diff --git a/configure.ac b/configure.ac
index 2c9585d..db7ef7c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2116,7 +2116,7 @@ if test "$KDRIVE" = yes; then
        AC_DEFINE(KDRIVE_MOUSE, 1, [Enable KDrive mouse driver])
     fi
 
-    XEPHYR_REQUIRED_LIBS="x11 >= 1.6 $LIBXEXT xau xdmcp xcb x11-xcb xcb-shape xcb-aux xcb-image xcb-icccm xcb-shm"
+    XEPHYR_REQUIRED_LIBS="x11 >= 1.6 $LIBXEXT xau xdmcp xcb x11-xcb xcb-shape xcb-aux xcb-image xcb-icccm xcb-shm xcb-keysyms"
     if test "x$XV" = xyes; then
         XEPHYR_REQUIRED_LIBS="$XEPHYR_REQUIRED_LIBS xv"
     fi
diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index 1261487..4bcc902 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -62,6 +62,7 @@
 #include <xcb/shm.h>
 #include <xcb/xcb_image.h>
 #include <xcb/shape.h>
+#include <xcb/xcb_keysyms.h>
 #ifdef XF86DRI
 #include <xcb/xf86dri.h>
 #include <xcb/glx.h>
@@ -943,6 +944,10 @@ hostx_get_event(EphyrHostXEvent * ev)
 {
     XEvent xev;
     static int grabbed_screen = -1;
+    static xcb_key_symbols_t *keysyms;
+
+    if (!keysyms)
+        keysyms = xcb_key_symbols_alloc(HostX.conn);
 
     if (XPending(HostX.dpy)) {
         XNextEvent(HostX.dpy, &xev);
@@ -1007,11 +1012,9 @@ hostx_get_event(EphyrHostXEvent * ev)
             return 1;
         }
         case KeyRelease:
-
-            if ((XKeycodeToKeysym(HostX.dpy, xev.xkey.keycode, 0) == XK_Shift_L
-                 || XKeycodeToKeysym(HostX.dpy, xev.xkey.keycode,
-                                     0) == XK_Shift_R)
-                && (xev.xkey.state & ControlMask)) {
+            if ((xcb_key_symbols_get_keysym(keysyms,xev.xkey.keycode, 0) == XK_Shift_L
+                 || xcb_key_symbols_get_keysym(keysyms,xev.xkey.keycode, 0) == XK_Shift_R)
+                && (xev.xkey.state & XCB_MOD_MASK_CONTROL)) {
                 struct EphyrHostScreen *host_screen =
                     host_screen_from_window(xev.xexpose.window);
 
commit 8543d3fdfd47d2a0423f3ef8e7429c23c5d6b053
Author: Julien Cristau <jcristau at debian.org>
Date:   Thu Jun 24 23:17:32 2010 +0100

    Xephyr: delete unused hostx_get_extension_info function
    
    v2: Also remove the prototype (anholt)
    
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net> (v1)
    Signed-off-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index 2b69b0e..1261487 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -1158,21 +1158,6 @@ hostx_get_window_attributes(int a_window, EphyrHostWindowAttributes * a_attrs)
 }
 
 int
-hostx_get_extension_info(const char *a_ext_name,
-                         int *a_major_opcode,
-                         int *a_first_event, int *a_first_error)
-{
-    if (!a_ext_name || !a_major_opcode || !a_first_event || !a_first_error)
-        return 0;
-    if (!XQueryExtension(HostX.dpy,
-                         a_ext_name,
-                         a_major_opcode, a_first_event, a_first_error)) {
-        return 0;
-    }
-    return 1;
-}
-
-int
 hostx_get_visuals_info(EphyrHostVisualInfo ** a_visuals, int *a_num_entries)
 {
     Bool is_ok = False;
diff --git a/hw/kdrive/ephyr/hostx.h b/hw/kdrive/ephyr/hostx.h
index c065f2d..1c01f8b 100644
--- a/hw/kdrive/ephyr/hostx.h
+++ b/hw/kdrive/ephyr/hostx.h
@@ -220,11 +220,6 @@ int
  hostx_get_window_attributes(int a_window, EphyrHostWindowAttributes * a_attr);
 
 int
-
-hostx_get_extension_info(const char *a_ext_name,
-                         int *a_major_opcode,
-                         int *a_first_even, int *a_first_error);
-int
  hostx_get_visuals_info(EphyrHostVisualInfo ** a_visuals, int *a_num_entries);
 
 int hostx_create_window(int a_screen_number,
commit d72c11b9df4a98fd80cb6635d34964483e33bc41
Author: Julien Cristau <jcristau at debian.org>
Date:   Mon Jun 21 14:25:11 2010 +0100

    Xephyr: delete unused proxy code
    
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/ephyrhostproxy.c b/hw/kdrive/ephyr/ephyrhostproxy.c
deleted file mode 100644
index a4f25c1..0000000
--- a/hw/kdrive/ephyr/ephyrhostproxy.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Xephyr - A kdrive X server thats runs in a host X window.
- *          Authored by Matthew Allum <mallum at openedhand.com>
- * 
- * Copyright © 2007 OpenedHand Ltd 
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of OpenedHand Ltd not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission. OpenedHand Ltd makes no
- * representations about the suitability of this software for any purpose.  It
- * is provided "as is" without express or implied warranty.
- *
- * OpenedHand Ltd DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL OpenedHand Ltd BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- *
- * Authors:
- *    Dodji Seketeli <dodji at openedhand.com>
- */
-
-#ifdef HAVE_CONFIG_H
-#include <kdrive-config.h>
-#endif
-
-#include <X11/Xlibint.h>
-#define _HAVE_XALLOC_DECLS
-#include "ephyrlog.h"
-#include "ephyrhostproxy.h"
-#include "hostx.h"
-
-/* byte swap a short */
-#define swaps(x, n) { \
-    n = ((char *) (x))[0];\
-    ((char *) (x))[0] = ((char *) (x))[1];\
-    ((char *) (x))[1] = n; }
-
-#define GetXReq(req) \
-    WORD64ALIGN ;\
-    if ((dpy->bufptr + SIZEOF(xReq)) > dpy->bufmax)\
-            _XFlush(dpy);\
-    req = (xReq *)(dpy->last_req = dpy->bufptr);\
-    dpy->bufptr += SIZEOF(xReq);\
-    dpy->request++
-
-Bool
-ephyrHostProxyDoForward(pointer a_request_buffer,
-                        struct XReply *a_reply, Bool a_do_swap)
-{
-    Bool is_ok = FALSE;
-    int n = 0;
-    Display *dpy = hostx_get_display();
-    xReq *in_req = (xReq *) a_request_buffer;
-    xReq *forward_req = NULL;
-    struct XReply reply;
-
-    EPHYR_RETURN_VAL_IF_FAIL(in_req && dpy, FALSE);
-
-    EPHYR_LOG("enter\n");
-
-    if (a_do_swap) {
-        swaps(&in_req->length);
-    }
-    EPHYR_LOG("Req {type:%d, data:%d, length:%d}\n",
-              in_req->reqType, in_req->data, in_req->length);
-    GetXReq(forward_req);
-    memmove(forward_req, in_req, 4);
-
-    if (!_XReply(dpy, (xReply *) &reply, 0, FALSE)) {
-        EPHYR_LOG_ERROR("failed to get reply\n");
-        goto out;
-    }
-    EPHYR_LOG("XReply{type:%d, foo:%d, seqnum:%d, length:%d}\n",
-              reply.type, reply.foo, reply.sequence_number, reply.length);
-
-    if (a_reply) {
-        memmove(a_reply, &reply, sizeof(reply));
-    }
-    is_ok = TRUE;
-
- out:
-    EPHYR_LOG("leave\n");
-    return is_ok;
-}
diff --git a/hw/kdrive/ephyr/ephyrhostproxy.h b/hw/kdrive/ephyr/ephyrhostproxy.h
deleted file mode 100644
index 1372160..0000000
--- a/hw/kdrive/ephyr/ephyrhostproxy.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Xephyr - A kdrive X server thats runs in a host X window.
- *          Authored by Matthew Allum <mallum at openedhand.com>
- * 
- * Copyright © 2007 OpenedHand Ltd 
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of OpenedHand Ltd not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission. OpenedHand Ltd makes no
- * representations about the suitability of this software for any purpose.  It
- * is provided "as is" without express or implied warranty.
- *
- * OpenedHand Ltd DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL OpenedHand Ltd BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- *
- * Authors:
- *    Dodji Seketeli <dodji at openedhand.com>
- */
-
-#ifndef __EPHYRHOSTPROXY_H__
-#define __EPHYRHOSTPROXY_H__
-
-struct XReply {
-    int8_t type;                /*X_Reply */
-    int8_t foo;
-    int16_t sequence_number;
-    int32_t length;
-    /*following is some data up to 32 bytes lenght */
-    int32_t pad0;
-    int32_t pad1;
-    int32_t pad2;
-    int32_t pad3;
-    int32_t pad4;
-    int32_t pad5;
-};
-
-Bool
-
-ephyrHostProxyDoForward(pointer a_request_buffer,
-                        struct XReply *a_reply, Bool a_do_swap);
-
-#endif /*__EPHYRHOSTPROXY_H__*/
diff --git a/hw/kdrive/ephyr/ephyrproxyext.c b/hw/kdrive/ephyr/ephyrproxyext.c
deleted file mode 100644
index c24238c..0000000
--- a/hw/kdrive/ephyr/ephyrproxyext.c
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Xephyr - A kdrive X server thats runs in a host X window.
- *          Authored by Matthew Allum <mallum at openedhand.com>
- * 
- * Copyright © 2007 OpenedHand Ltd 
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of OpenedHand Ltd not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission. OpenedHand Ltd makes no
- * representations about the suitability of this software for any purpose.  It
- * is provided "as is" without express or implied warranty.
- *
- * OpenedHand Ltd DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL OpenedHand Ltd BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- *
- * Authors:
- *    Dodji Seketeli <dodji at openedhand.com>
- */
-
-/*
- * \file
- * This file defines a proxy extension that forwards requests.
- * When a request to extension FOO is sent to Xephyr, that request is forwared
- * to the host X, without even trying to know what the request means.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <kdrive-config.h>
-#endif
-
-#include "misc.h"
-#include "dixstruct.h"
-#include "extnsionst.h"
-#include "ephyrproxyext.h"
-#define _HAVE_XALLOC_DECLS
-#include "ephyrlog.h"
-#include "ephyrhostproxy.h"
-#include "hostx.h"
-
-static Bool ephyrProxyGetHostExtensionInfo(const char *a_ext_name,
-                                           int *a_major_opcode,
-                                           int *a_first_event,
-                                           int *a_first_error);
-
-static int ephyrProxyProcDispatch(ClientPtr client);
-
-static Bool
-ephyrProxyGetHostExtensionInfo(const char *a_ext_name,
-                               int *a_major_opcode,
-                               int *a_first_event, int *a_first_error)
-{
-    return hostx_get_extension_info(a_ext_name, a_major_opcode,
-                                    a_first_event, a_first_error);
-}
-
-static int
-ephyrProxyProcDispatch(ClientPtr a_client)
-{
-    int res = BadImplementation;
-    struct XReply reply;
-
-    if (!ephyrHostProxyDoForward(a_client->requestBuffer, &reply, FALSE)) {
-        EPHYR_LOG_ERROR("forwarding failed\n");
-        goto out;
-    }
-    reply.sequence_number = a_client->sequence;
-    res = Success;
-
-    WriteToClient(a_client, 32, &reply);
-
- out:
-    return res;
-}
-
-static void
-ephyrProxyProcReset(ExtensionEntry * a_entry)
-{
-}
-
-Bool
-ephyrProxyExtensionInit(const char *a_extension_name)
-{
-    Bool is_ok = FALSE;
-    int major_opcode = 0, first_event = 0, first_error = 0;
-    ExtensionEntry *ext = NULL;
-
-    if (!ephyrProxyGetHostExtensionInfo(a_extension_name,
-                                        &major_opcode,
-                                        &first_event, &first_error)) {
-        EPHYR_LOG("failed to query extension %s from host\n", a_extension_name);
-        goto out;
-    }
-    ext = AddExtension((char *) a_extension_name, 0, 0,
-                       ephyrProxyProcDispatch,
-                       ephyrProxyProcDispatch,
-                       ephyrProxyProcReset, StandardMinorOpcode);
-    if (!ext) {
-        EPHYR_LOG_ERROR("failed to add the extension\n");
-        goto out;
-    }
-    is_ok = TRUE;
-
- out:
-    EPHYR_LOG("leave\n");
-    return is_ok;
-}
diff --git a/hw/kdrive/ephyr/ephyrproxyext.h b/hw/kdrive/ephyr/ephyrproxyext.h
deleted file mode 100644
index 018b69b..0000000
--- a/hw/kdrive/ephyr/ephyrproxyext.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Xephyr - A kdrive X server thats runs in a host X window.
- *          Authored by Matthew Allum <mallum at openedhand.com>
- * 
- * Copyright © 2007 OpenedHand Ltd 
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of OpenedHand Ltd not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission. OpenedHand Ltd makes no
- * representations about the suitability of this software for any purpose.  It
- * is provided "as is" without express or implied warranty.
- *
- * OpenedHand Ltd DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL OpenedHand Ltd BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- *
- * Authors:
- *    Dodji Seketeli <dodji at openedhand.com>
- */
-#ifndef __EPHYRPROXYEXT_H__
-#define __EPHYRPROXYEXT_H__
-
-Bool ephyrProxyExtensionInit(const char *a_extension_name);
-
-#endif /*__EPHYRPROXYEXT_H__*/
commit a71ea3f96769da157dde82a591e43264820772ac
Author: Julien Cristau <jcristau at debian.org>
Date:   Sun Jun 20 23:34:54 2010 +0100

    Xephyr: xcb-ify visual list construction
    
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index 2ebf978..2b69b0e 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -1175,43 +1175,50 @@ hostx_get_extension_info(const char *a_ext_name,
 int
 hostx_get_visuals_info(EphyrHostVisualInfo ** a_visuals, int *a_num_entries)
 {
-    Display *dpy = hostx_get_display();
     Bool is_ok = False;
-    XVisualInfo templ, *visuals = NULL;
     EphyrHostVisualInfo *host_visuals = NULL;
-    int nb_items = 0, i = 0;
+    int nb_items = 0, i = 0, screen_num;
+    xcb_screen_iterator_t screens;
+    xcb_depth_iterator_t depths;
 
-    EPHYR_RETURN_VAL_IF_FAIL(a_visuals && a_num_entries && dpy, False);
+    EPHYR_RETURN_VAL_IF_FAIL(a_visuals && a_num_entries, False);
     EPHYR_LOG("enter\n");
-    memset(&templ, 0, sizeof(templ));
-    visuals = XGetVisualInfo(dpy, VisualNoMask, &templ, &nb_items);
-    if (!visuals) {
-        EPHYR_LOG_ERROR("host does not advertise any visual\n");
-        goto out;
+
+    screens = xcb_setup_roots_iterator(xcb_get_setup(HostX.conn));
+    for (screen_num = 0; screens.rem; screen_num++, xcb_screen_next(&screens)) {
+        depths = xcb_screen_allowed_depths_iterator(screens.data);
+        for (; depths.rem; xcb_depth_next(&depths)) {
+            xcb_visualtype_t *visuals = xcb_depth_visuals(depths.data);
+            EphyrHostVisualInfo *tmp_visuals =
+                realloc(host_visuals,
+                        (nb_items + depths.data->visuals_len)
+                        * sizeof(EphyrHostVisualInfo));
+            if (!tmp_visuals) {
+                goto out;
+            }
+            host_visuals = tmp_visuals;
+            for (i = 0; i < depths.data->visuals_len; i++) {
+                host_visuals[nb_items + i].visualid = visuals[i].visual_id;
+                host_visuals[nb_items + i].screen = screen_num;
+                host_visuals[nb_items + i].depth = depths.data->depth;
+                host_visuals[nb_items + i].class = visuals[i]._class;
+                host_visuals[nb_items + i].red_mask = visuals[i].red_mask;
+                host_visuals[nb_items + i].green_mask = visuals[i].green_mask;
+                host_visuals[nb_items + i].blue_mask = visuals[i].blue_mask;
+                host_visuals[nb_items + i].colormap_size = visuals[i].colormap_entries;
+                host_visuals[nb_items + i].bits_per_rgb = visuals[i].bits_per_rgb_value;
+            }
+            nb_items += depths.data->visuals_len;
+        }
     }
+
     EPHYR_LOG("host advertises %d visuals\n", nb_items);
-    host_visuals = calloc(nb_items, sizeof(EphyrHostVisualInfo));
-    for (i = 0; i < nb_items; i++) {
-        host_visuals[i].visualid = visuals[i].visualid;
-        host_visuals[i].screen = visuals[i].screen;
-        host_visuals[i].depth = visuals[i].depth;
-        host_visuals[i].class = visuals[i].class;
-        host_visuals[i].red_mask = visuals[i].red_mask;
-        host_visuals[i].green_mask = visuals[i].green_mask;
-        host_visuals[i].blue_mask = visuals[i].blue_mask;
-        host_visuals[i].colormap_size = visuals[i].colormap_size;
-        host_visuals[i].bits_per_rgb = visuals[i].bits_per_rgb;
-    }
     *a_visuals = host_visuals;
     *a_num_entries = nb_items;
     host_visuals = NULL;
 
     is_ok = TRUE;
- out:
-    if (visuals) {
-        XFree(visuals);
-        visuals = NULL;
-    }
+out:
     free(host_visuals);
     host_visuals = NULL;
     EPHYR_LOG("leave\n");
commit ac2b0348c00d692ec1bd8d6c8ab99e9198e755a7
Author: Julien Cristau <jcristau at debian.org>
Date:   Sun Jun 20 23:34:39 2010 +0100

    Xephyr: xcb-ify pointer/keyboard grab
    
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index 699805b..2ebf978 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -1016,30 +1016,49 @@ hostx_get_event(EphyrHostXEvent * ev)
                     host_screen_from_window(xev.xexpose.window);
 
                 if (grabbed_screen != -1) {
-                    XUngrabKeyboard(HostX.dpy, CurrentTime);
-                    XUngrabPointer(HostX.dpy, CurrentTime);
+                    xcb_ungrab_keyboard(HostX.conn, XCB_TIME_CURRENT_TIME);
+                    xcb_ungrab_pointer(HostX.conn, XCB_TIME_CURRENT_TIME);
                     grabbed_screen = -1;
                     hostx_set_win_title(host_screen->info,
                                         "(ctrl+shift grabs mouse and keyboard)");
                 }
                 else {
                     /* Attempt grab */
-                    if (XGrabKeyboard(HostX.dpy, host_screen->win, True,
-                                      GrabModeAsync,
-                                      GrabModeAsync, CurrentTime) == 0) {
-                        if (XGrabPointer(HostX.dpy, host_screen->win, True,
-                                         NoEventMask,
-                                         GrabModeAsync,
-                                         GrabModeAsync,
-                                         host_screen->win, None,
-                                         CurrentTime) == 0) {
+                    xcb_grab_keyboard_cookie_t kbgrabc =
+                        xcb_grab_keyboard(HostX.conn,
+                                          True,
+                                          host_screen->win,
+                                          XCB_TIME_CURRENT_TIME,
+                                          XCB_GRAB_MODE_ASYNC,
+                                          XCB_GRAB_MODE_ASYNC);
+                    xcb_grab_keyboard_reply_t *kbgrabr;
+                    xcb_grab_pointer_cookie_t pgrabc =
+                        xcb_grab_pointer(HostX.conn,
+                                         True,
+                                         host_screen->win,
+                                         0,
+                                         XCB_GRAB_MODE_ASYNC,
+                                         XCB_GRAB_MODE_ASYNC,
+                                         host_screen->win,
+                                         XCB_NONE,
+                                         XCB_TIME_CURRENT_TIME);
+                    xcb_grab_pointer_reply_t *pgrabr;
+                    kbgrabr = xcb_grab_keyboard_reply(HostX.conn, kbgrabc, NULL);
+                    if (!kbgrabr || kbgrabr->status != XCB_GRAB_STATUS_SUCCESS) {
+                        xcb_discard_reply(HostX.conn, pgrabc.sequence);
+                        xcb_ungrab_pointer(HostX.conn, XCB_TIME_CURRENT_TIME);
+                    } else {
+                        pgrabr = xcb_grab_pointer_reply(HostX.conn, pgrabc, NULL);
+                        if (!pgrabr || pgrabr->status != XCB_GRAB_STATUS_SUCCESS)
+                            {
+                                xcb_ungrab_keyboard(HostX.conn,
+                                                    XCB_TIME_CURRENT_TIME);
+                            } else {
                             grabbed_screen = host_screen->mynum;
                             hostx_set_win_title
                                 (host_screen->info,
                                  "(ctrl+shift releases mouse and keyboard)");
                         }
-                        else    /* Failed pointer grabm  ungrab keyboard */
-                            XUngrabKeyboard(HostX.dpy, CurrentTime);
                     }
                 }
             }
commit 1f93e6b350d1b9a058009052a666a2e8796708cb
Author: Julien Cristau <jcristau at debian.org>
Date:   Sun Jun 20 23:34:03 2010 +0100

    Xephyr: no need for XDisplayKeycodes
    
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index f4948b9..699805b 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -910,7 +910,8 @@ hostx_load_keymap(void)
 {
     int min_keycode, max_keycode;
 
-    XDisplayKeycodes(HostX.dpy, &min_keycode, &max_keycode);
+    min_keycode = xcb_get_setup(HostX.conn)->min_keycode;
+    max_keycode = xcb_get_setup(HostX.conn)->max_keycode;
 
     EPHYR_DBG("min: %d, max: %d", min_keycode, max_keycode);
 
commit 73398e5bf61c30e69a40a19a1057c2263fbb91ef
Author: Julien Cristau <jcristau at debian.org>
Date:   Thu Jun 24 23:00:38 2010 +0100

    Xephyr: use xcb-shape instead of XShape*
    
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index 2ecda14..f4948b9 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -54,7 +54,6 @@
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include <X11/keysym.h>
-#include <X11/extensions/shape.h>
 #include <xcb/xcb.h>
 #include <xcb/xproto.h>
 #include <X11/Xlib-xcb.h>
@@ -1300,15 +1299,16 @@ hostx_set_window_bounding_rectangles(int a_window,
                                      EphyrRect * a_rects, int a_num_rects)
 {
     Bool is_ok = FALSE;
-    Display *dpy = hostx_get_display();
     int i = 0;
-    XRectangle *rects = NULL;
+    xcb_rectangle_t *rects = NULL;
 
-    EPHYR_RETURN_VAL_IF_FAIL(dpy && a_rects, FALSE);
+    EPHYR_RETURN_VAL_IF_FAIL(a_rects, FALSE);
 
     EPHYR_LOG("enter. num rects:%d\n", a_num_rects);
 
-    rects = calloc(a_num_rects, sizeof(XRectangle));
+    rects = calloc(a_num_rects, sizeof (xcb_rectangle_t));
+    if (!rects)
+        goto out;
     for (i = 0; i < a_num_rects; i++) {
         rects[i].x = a_rects[i].x1;
         rects[i].y = a_rects[i].y1;
@@ -1317,11 +1317,17 @@ hostx_set_window_bounding_rectangles(int a_window,
         EPHYR_LOG("borders clipped to rect[x:%d,y:%d,w:%d,h:%d]\n",
                   rects[i].x, rects[i].y, rects[i].width, rects[i].height);
     }
-    /*this aways returns 1 */
-    XShapeCombineRectangles(dpy, a_window, ShapeBounding, 0, 0,
-                            rects, a_num_rects, ShapeSet, YXBanded);
+    xcb_shape_rectangles(HostX.conn,
+                         XCB_SHAPE_SO_SET,
+                         XCB_SHAPE_SK_BOUNDING,
+                         XCB_CLIP_ORDERING_YX_BANDED,
+                         a_window,
+                         0, 0,
+                         a_num_rects,
+                         rects);
     is_ok = TRUE;
 
+out:
     free(rects);
     rects = NULL;
     EPHYR_LOG("leave\n");
@@ -1335,13 +1341,15 @@ hostx_set_window_clipping_rectangles(int a_window,
     Bool is_ok = FALSE;
     Display *dpy = hostx_get_display();
     int i = 0;
-    XRectangle *rects = NULL;
+    xcb_rectangle_t *rects = NULL;
 
     EPHYR_RETURN_VAL_IF_FAIL(dpy && a_rects, FALSE);
 
     EPHYR_LOG("enter. num rects:%d\n", a_num_rects);
 
-    rects = calloc(a_num_rects, sizeof(XRectangle));
+    rects = calloc(a_num_rects, sizeof (xcb_rectangle_t));
+    if (!rects)
+        goto out;
     for (i = 0; i < a_num_rects; i++) {
         rects[i].x = a_rects[i].x1;
         rects[i].y = a_rects[i].y1;
@@ -1350,11 +1358,17 @@ hostx_set_window_clipping_rectangles(int a_window,
         EPHYR_LOG("clipped to rect[x:%d,y:%d,w:%d,h:%d]\n",
                   rects[i].x, rects[i].y, rects[i].width, rects[i].height);
     }
-    /*this aways returns 1 */
-    XShapeCombineRectangles(dpy, a_window, ShapeClip, 0, 0,
-                            rects, a_num_rects, ShapeSet, YXBanded);
+    xcb_shape_rectangles(HostX.conn,
+                         XCB_SHAPE_SO_SET,
+                         XCB_SHAPE_SK_CLIP,
+                         XCB_CLIP_ORDERING_YX_BANDED,
+                         a_window,
+                         0, 0,
+                         a_num_rects,
+                         rects);
     is_ok = TRUE;
 
+out:
     free(rects);
     rects = NULL;
     EPHYR_LOG("leave\n");
commit a2b73da78de4e627965213d24a6c33f243a60eb6
Author: Julien Cristau <jcristau at debian.org>
Date:   Sun Jun 20 00:05:40 2010 +0100

    Xephyr: start converting hostx.c over to xcb
    
    v2: Dropped the hostx_load_keymap changes, now that that function is
        gutted (anholt).
    
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net> (v1)
    Signed-off-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/configure.ac b/configure.ac
index d27ca23..2c9585d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2116,12 +2116,12 @@ if test "$KDRIVE" = yes; then
        AC_DEFINE(KDRIVE_MOUSE, 1, [Enable KDrive mouse driver])
     fi
 
-    XEPHYR_REQUIRED_LIBS="x11 >= 1.6 $LIBXEXT xau xdmcp"
+    XEPHYR_REQUIRED_LIBS="x11 >= 1.6 $LIBXEXT xau xdmcp xcb x11-xcb xcb-shape xcb-aux xcb-image xcb-icccm xcb-shm"
     if test "x$XV" = xyes; then
         XEPHYR_REQUIRED_LIBS="$XEPHYR_REQUIRED_LIBS xv"
     fi
     if test "x$DRI" = xyes && test "x$GLX" = xyes; then
-        XEPHYR_REQUIRED_LIBS="$XEPHYR_REQUIRED_LIBS $LIBGL libdrm"
+        XEPHYR_REQUIRED_LIBS="$XEPHYR_REQUIRED_LIBS $LIBGL libdrm xcb-glx xcb-xf86dri"
     fi
 
     if test "x$XEPHYR" = xauto; then
diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index f46770f..2ecda14 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -53,20 +53,22 @@
 
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
-#include <X11/Xatom.h>
 #include <X11/keysym.h>
-#include <X11/extensions/XShm.h>
 #include <X11/extensions/shape.h>
+#include <xcb/xcb.h>
+#include <xcb/xproto.h>
+#include <X11/Xlib-xcb.h>
+#include <xcb/xcb_icccm.h>
+#include <xcb/xcb_aux.h>
+#include <xcb/shm.h>
+#include <xcb/xcb_image.h>
+#include <xcb/shape.h>
 #ifdef XF86DRI
-#include <GL/glx.h>
-#endif                          /* XF86DRI */
+#include <xcb/xf86dri.h>
+#include <xcb/glx.h>
+#endif /* XF86DRI */
 #include "ephyrlog.h"
 
-#ifdef XF86DRI
-extern Bool XF86DRIQueryExtension(Display * dpy,
-                                  int *event_basep, int *error_basep);
-#endif
-
 /*  
  * All xlib calls go here, which gets built as its own .a .
  * Mixing kdrive and xlib headers causes all sorts of types
@@ -77,11 +79,11 @@ struct EphyrHostScreen {
     Window win;
     Window win_pre_existing;    /* Set via -parent option like xnest */
     Window peer_win;            /* Used for GL; should be at most one */
-    XImage *ximg;
+    xcb_image_t    *ximg;
     int win_width, win_height;
     int server_depth;
     unsigned char *fb_data;     /* only used when host bpp != server bpp */
-    XShmSegmentInfo shminfo;
+    xcb_shm_segment_info_t shminfo;
 
     void *info;                 /* Pointer to the screen this is associated with */
     int mynum;                  /* Screen number */
@@ -90,10 +92,11 @@ struct EphyrHostScreen {
 struct EphyrHostXVars {
     char *server_dpy_name;
     Display *dpy;
+    xcb_connection_t *conn;
     int screen;
     Visual *visual;
     Window winroot;
-    GC gc;
+    xcb_gcontext_t  gc;
     int depth;
     Bool use_host_cursor;
     Bool use_fullscreen;
@@ -126,11 +129,6 @@ char *ephyrTitle = NULL;
 static void
  hostx_set_fullscreen_hint(void);
 
-/* X Error traps */
-
-static int trapped_error_code = 0;
-static int (*old_error_handler) (Display * d, XErrorEvent * e);
-
 #define host_depth_matches_server(_vars) (HostX.depth == (_vars)->server_depth)
 
 static struct EphyrHostScreen *
@@ -146,27 +144,6 @@ host_screen_from_screen_info(EphyrScreenInfo * screen)
     return NULL;
 }
 
-static int
-error_handler(Display * display, XErrorEvent * error)
-{
-    trapped_error_code = error->error_code;
-    return 0;
-}
-
-static void
-hostx_errors_trap(void)
-{
-    trapped_error_code = 0;
-    old_error_handler = XSetErrorHandler(error_handler);
-}
-
-static int
-hostx_errors_untrap(void)
-{
-    XSetErrorHandler(old_error_handler);
-    return trapped_error_code;
-}
-
 int
 hostx_want_screen_size(EphyrScreenInfo screen, int *width, int *height)
 {
@@ -223,9 +200,13 @@ hostx_set_win_title(EphyrScreenInfo screen, const char *extra_text)
         return;
 
     if (ephyrTitle) {
-        XStoreName(HostX.dpy, host_screen->win, ephyrTitle);
-    }
-    else {
+        xcb_icccm_set_wm_name(HostX.conn,
+                              host_screen->win,
+                              XCB_ATOM_STRING,
+                              8,
+                              strlen(ephyrTitle),
+                              ephyrTitle);
+    } else {
 #define BUF_LEN 256
         char buf[BUF_LEN + 1];
 
@@ -234,7 +215,12 @@ hostx_set_win_title(EphyrScreenInfo screen, const char *extra_text)
                  HostX.server_dpy_name,
                  host_screen->mynum, (extra_text != NULL) ? extra_text : "");
 
-        XStoreName(HostX.dpy, host_screen->win, buf);
+        xcb_icccm_set_wm_name(HostX.conn,
+                              host_screen->win,
+                              XCB_ATOM_STRING,
+                              8,
+                              strlen(buf),
+                              buf);
     }
 }
 
@@ -275,21 +261,34 @@ hostx_want_fullscreen(void)
     return HostX.use_fullscreen;
 }
 
+static xcb_intern_atom_cookie_t cookie_WINDOW_STATE,
+				cookie_WINDOW_STATE_FULLSCREEN;
+
 static void
 hostx_set_fullscreen_hint(void)
 {
-    Atom atom_WINDOW_STATE, atom_WINDOW_STATE_FULLSCREEN;
+    xcb_atom_t atom_WINDOW_STATE, atom_WINDOW_STATE_FULLSCREEN;
     int index;
+    xcb_intern_atom_reply_t *reply;
+
+    reply = xcb_intern_atom_reply(HostX.conn, cookie_WINDOW_STATE, NULL);
+    atom_WINDOW_STATE = reply->atom;
+    free(reply);
 
-    atom_WINDOW_STATE = XInternAtom(HostX.dpy, "_NET_WM_STATE", False);
-    atom_WINDOW_STATE_FULLSCREEN
-        = XInternAtom(HostX.dpy, "_NET_WM_STATE_FULLSCREEN", False);
+    reply = xcb_intern_atom_reply(HostX.conn, cookie_WINDOW_STATE_FULLSCREEN,
+                                  NULL);
+    atom_WINDOW_STATE_FULLSCREEN = reply->atom;
+    free(reply);
 
     for (index = 0; index < HostX.n_screens; index++) {
-        XChangeProperty(HostX.dpy, HostX.screens[index].win,
-                        atom_WINDOW_STATE, XA_ATOM, 32,
-                        PropModeReplace,
-                        (unsigned char *) &atom_WINDOW_STATE_FULLSCREEN, 1);
+        xcb_change_property(HostX.conn,
+                            PropModeReplace,
+                            HostX.screens[index].win,
+                            atom_WINDOW_STATE,
+                            XCB_ATOM_ATOM,
+                            32,
+                            1,
+                            &atom_WINDOW_STATE_FULLSCREEN);
     }
 }
 
@@ -336,22 +335,26 @@ x_io_error_handler(Display * dpy)
 int
 hostx_init(void)
 {
-    XSetWindowAttributes attr;
-    Cursor empty_cursor;
-    Pixmap cursor_pxm;
-    XColor col;
+    uint32_t attr;
+    xcb_cursor_t empty_cursor;
+    xcb_pixmap_t cursor_pxm;
+    uint16_t red, green, blue;
+    uint32_t pixel;
     int index;
     char *tmpstr;
-    XClassHint *class_hint;
-
-    attr.event_mask =
-        ButtonPressMask
-        | ButtonReleaseMask
-        | PointerMotionMask
-        | KeyPressMask
-        | KeyReleaseMask
-        | ExposureMask
-        | StructureNotifyMask;
+    char *class_hint;
+    size_t class_len;
+    const xcb_query_extension_reply_t *shm_rep;
+    xcb_screen_t *screen;
+
+    attr =
+        XCB_EVENT_MASK_BUTTON_PRESS
+        | XCB_EVENT_MASK_BUTTON_RELEASE
+        | XCB_EVENT_MASK_POINTER_MOTION
+        | XCB_EVENT_MASK_KEY_PRESS
+        | XCB_EVENT_MASK_KEY_RELEASE
+        | XCB_EVENT_MASK_EXPOSURE
+        | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
 
     EPHYR_DBG("mark");
 
@@ -362,137 +365,190 @@ hostx_init(void)
 
     XSetIOErrorHandler(x_io_error_handler);
 
+    HostX.conn = XGetXCBConnection(HostX.dpy);
     HostX.screen = DefaultScreen(HostX.dpy);
+    screen = xcb_aux_get_screen(HostX.conn, HostX.screen);
     HostX.winroot = RootWindow(HostX.dpy, HostX.screen);
-    HostX.gc = XCreateGC(HostX.dpy, HostX.winroot, 0, NULL);
+    HostX.gc = xcb_generate_id(HostX.conn);
     HostX.depth = DefaultDepth(HostX.dpy, HostX.screen);
     HostX.visual = DefaultVisual(HostX.dpy, HostX.screen);
 
-    class_hint = XAllocClassHint();
+    xcb_create_gc(HostX.conn, HostX.gc, HostX.winroot, 0, NULL);
+    cookie_WINDOW_STATE = xcb_intern_atom(HostX.conn, False,
+                                          strlen("_NET_WM_STATE"),
+                                          "_NET_WM_STATE");
+    cookie_WINDOW_STATE_FULLSCREEN =
+        xcb_intern_atom(HostX.conn, False,
+                        strlen("_NET_WM_STATE_FULLSCREEN"),
+                        "_NET_WM_STATE_FULLSCREEN");
 
     for (index = 0; index < HostX.n_screens; index++) {
         struct EphyrHostScreen *host_screen = &HostX.screens[index];
 
+        host_screen->win = xcb_generate_id(HostX.conn);
         host_screen->server_depth = HostX.depth;
-        if (host_screen->win_pre_existing != None) {
-            Status result;
-            XWindowAttributes prewin_attr;
-
-            /* Get screen size from existing window */
-
-            hostx_errors_trap();
 
-            result = XGetWindowAttributes(HostX.dpy,
-                                          host_screen->win_pre_existing,
-                                          &prewin_attr);
+        if (host_screen->win_pre_existing != XCB_WINDOW_NONE) {
+            xcb_get_geometry_reply_t *prewin_geom;
+            xcb_get_geometry_cookie_t cookie;
+            xcb_generic_error_t *e = NULL;
 
-            if (hostx_errors_untrap() || !result) {
-                fprintf(stderr, "\nXephyr -parent window' does not exist!\n");
-                exit(1);
+            /* Get screen size from existing window */
+            cookie = xcb_get_geometry(HostX.conn,
+                                      host_screen->win_pre_existing);
+            prewin_geom = xcb_get_geometry_reply(HostX.conn, cookie, &e);
+
+            if (e) {
+                free(e);
+                free(prewin_geom);
+                fprintf (stderr, "\nXephyr -parent window' does not exist!\n");
+                exit (1);
             }
 
-            host_screen->win_width = prewin_attr.width;
-            host_screen->win_height = prewin_attr.height;
-
-            host_screen->win = XCreateWindow(HostX.dpy,
-                                             host_screen->win_pre_existing,
-                                             0, 0,
-                                             host_screen->win_width,
-                                             host_screen->win_height,
-                                             0,
-                                             CopyFromParent,
-                                             CopyFromParent,
-                                             CopyFromParent,
-                                             CWEventMask, &attr);
+            host_screen->win_width  = prewin_geom->width;
+            host_screen->win_height = prewin_geom->height;
+
+            free(prewin_geom);
+
+            xcb_create_window(HostX.conn,
+                              XCB_COPY_FROM_PARENT,
+                              host_screen->win,
+                              host_screen->win_pre_existing,
+                              0,0,
+                              host_screen->win_width,
+                              host_screen->win_height,
+                              0,
+                              XCB_WINDOW_CLASS_COPY_FROM_PARENT,
+                              XCB_COPY_FROM_PARENT,
+                              XCB_CW_EVENT_MASK,
+                              &attr);
         }
         else {
-            host_screen->win = XCreateWindow(HostX.dpy, HostX.winroot, 0, 0, 100, 100,  /* will resize */
-                                             0,
-                                             CopyFromParent,
-                                             CopyFromParent,
-                                             CopyFromParent,
-                                             CWEventMask, &attr);
-
-            hostx_set_win_title(host_screen->info,
-                                "(ctrl+shift grabs mouse and keyboard)");
+            xcb_create_window(HostX.conn,
+                              XCB_COPY_FROM_PARENT,
+                              host_screen->win,
+                              HostX.winroot,
+                              0,0,100,100, /* will resize */
+                              0,
+                              XCB_WINDOW_CLASS_COPY_FROM_PARENT,
+                              XCB_COPY_FROM_PARENT,
+                              XCB_CW_EVENT_MASK,
+                              &attr);
+
+            hostx_set_win_title (host_screen->info,
+                                 "(ctrl+shift grabs mouse and keyboard)");
 
             if (HostX.use_fullscreen) {
-                host_screen->win_width = DisplayWidth(HostX.dpy, HostX.screen);
-                host_screen->win_height =
-                    DisplayHeight(HostX.dpy, HostX.screen);
+                host_screen->win_width  = DisplayWidth(HostX.dpy, HostX.screen);
+                host_screen->win_height = DisplayHeight(HostX.dpy, HostX.screen);
 
                 hostx_set_fullscreen_hint();
             }
 
+            tmpstr = getenv("RESOURCE_NAME");
+            if (tmpstr && (!ephyrResNameFromCmd))
+                ephyrResName = tmpstr;
+            class_len = strlen(ephyrResName) + 1 + strlen("Xephyr") + 1;
+            class_hint = malloc(class_len);
             if (class_hint) {
-                tmpstr = getenv("RESOURCE_NAME");
-                if (tmpstr && (!ephyrResNameFromCmd))
-                    ephyrResName = tmpstr;
-                class_hint->res_name = ephyrResName;
-                class_hint->res_class = "Xephyr";
-                XSetClassHint(hostx_get_display(), host_screen->win,
-                              class_hint);
-
+                strcpy(class_hint, ephyrResName);
+                strcpy(class_hint + strlen(ephyrResName) + 1, "Xephyr");
+                xcb_change_property(HostX.conn,
+                                    XCB_PROP_MODE_REPLACE,
+                                    host_screen->win,
+                                    XCB_ATOM_WM_CLASS,
+                                    XCB_ATOM_STRING,
+                                    8,
+                                    class_len,
+                                    class_hint);
+                free(class_hint);
             }
-
         }
     }
 
-    if (class_hint)
-        XFree(class_hint);
+    if (!xcb_aux_parse_color("red", &red, &green, &blue)) {
+        xcb_lookup_color_cookie_t c =
+            xcb_lookup_color(HostX.conn, screen->default_colormap, 3, "red");
+        xcb_lookup_color_reply_t *reply =
+            xcb_lookup_color_reply(HostX.conn, c, NULL);
+        red = reply->exact_red;
+        green = reply->exact_green;
+        blue = reply->exact_blue;
+        free(reply);
+    }
 
-    XParseColor(HostX.dpy, DefaultColormap(HostX.dpy, HostX.screen),
-                "red", &col);
-    XAllocColor(HostX.dpy, DefaultColormap(HostX.dpy, HostX.screen), &col);
-    XSetForeground(HostX.dpy, HostX.gc, col.pixel);
+    {
+        xcb_alloc_color_cookie_t c = xcb_alloc_color(HostX.conn,
+                                                     screen->default_colormap,
+                                                     red, green, blue);
+        xcb_alloc_color_reply_t *r = xcb_alloc_color_reply(HostX.conn, c, NULL);
+        red = r->red;
+        green = r->green;
+        blue = r->blue;
+        pixel = r->pixel;
+        free(r);
+    }
+
+    xcb_change_gc(HostX.conn, HostX.gc, XCB_GC_FOREGROUND, &pixel);
 
-    if (!hostx_want_host_cursor()) {
+    if (!hostx_want_host_cursor ()) {
         /* Ditch the cursor, we provide our 'own' */
-        cursor_pxm = XCreatePixmap(HostX.dpy, HostX.winroot, 1, 1, 1);
-        memset(&col, 0, sizeof(col));
-        empty_cursor = XCreatePixmapCursor(HostX.dpy,
-                                           cursor_pxm, cursor_pxm,
-                                           &col, &col, 1, 1);
+        cursor_pxm = xcb_generate_id(HostX.conn);
+        xcb_create_pixmap(HostX.conn, 1, cursor_pxm, HostX.winroot, 1, 1);
+        empty_cursor = xcb_generate_id(HostX.conn);
+        xcb_create_cursor(HostX.conn,
+                          empty_cursor,
+                          cursor_pxm, cursor_pxm,
+                          0,0,0,
+                          0,0,0,
+                          1,1);
         for (index = 0; index < HostX.n_screens; index++) {
-            XDefineCursor(HostX.dpy, HostX.screens[index].win, empty_cursor);
+            xcb_change_window_attributes(HostX.conn,
+                                         HostX.screens[index].win,
+                                         XCB_CW_CURSOR,
+                                         &empty_cursor);
         }
-        XFreePixmap(HostX.dpy, cursor_pxm);
+        xcb_free_pixmap(HostX.conn, cursor_pxm);
     }
 
     for (index = 0; index < HostX.n_screens; index++) {
         HostX.screens[index].ximg = NULL;
     }
-    /* Try to get share memory ximages for a little bit more speed */
 
-    if (!XShmQueryExtension(HostX.dpy) || getenv("XEPHYR_NO_SHM")) {
+    /* Try to get share memory ximages for a little bit more speed */
+    shm_rep = xcb_get_extension_data(HostX.conn, &xcb_shm_id);
+    if (!shm_rep || !shm_rep->present || getenv("XEPHYR_NO_SHM")) {
         fprintf(stderr, "\nXephyr unable to use SHM XImages\n");
         HostX.have_shm = False;
     }
     else {
-        /* Really really check we have shm - better way ? */
-        XShmSegmentInfo shminfo;
+        /* Really really check we have shm - better way ?*/
+        xcb_shm_segment_info_t shminfo;
+        xcb_generic_error_t *e;
+        xcb_void_cookie_t cookie;
+        xcb_shm_seg_t shmseg;
 
         HostX.have_shm = True;
 
-        shminfo.shmid = shmget(IPC_PRIVATE, 1, IPC_CREAT | 0777);
-        shminfo.shmaddr = shmat(shminfo.shmid, 0, 0);
-        shminfo.readOnly = True;
+        shminfo.shmid = shmget(IPC_PRIVATE, 1, IPC_CREAT|0777);
+        shminfo.shmaddr = shmat(shminfo.shmid,0,0);
 
-        hostx_errors_trap();
+        shmseg = xcb_generate_id(HostX.conn);
+        cookie = xcb_shm_attach_checked(HostX.conn, shmseg, shminfo.shmid,
+                                        True);
+        e = xcb_request_check(HostX.conn, cookie);
 
-        XShmAttach(HostX.dpy, &shminfo);
-        XSync(HostX.dpy, False);
-
-        if (hostx_errors_untrap()) {
+        if (e) {
             fprintf(stderr, "\nXephyr unable to use SHM XImages\n");
             HostX.have_shm = False;
+            free(e);
         }
 
         shmdt(shminfo.shmaddr);
         shmctl(shminfo.shmid, IPC_RMID, 0);
     }
 
-    XFlush(HostX.dpy);
+    xcb_flush(HostX.conn);
 
     /* Setup the pause time between paints when debugging updates */
 
@@ -622,9 +678,7 @@ hostx_screen_init(EphyrScreenInfo screen,
                   int width, int height, int buffer_height,
                   int *bytes_per_line, int *bits_per_pixel)
 {
-    int bitmap_pad;
     Bool shm_success = False;
-    XSizeHints *size_hints;
 
     struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
 
@@ -642,8 +696,8 @@ hostx_screen_init(EphyrScreenInfo screen,
          */
 
         if (HostX.have_shm) {
-            XShmDetach(HostX.dpy, &host_screen->shminfo);
-            XDestroyImage(host_screen->ximg);
+            xcb_shm_detach(HostX.conn, host_screen->shminfo.shmseg);
+            xcb_image_destroy (host_screen->ximg);
             shmdt(host_screen->shminfo.shmaddr);
             shmctl(host_screen->shminfo.shmid, IPC_RMID, 0);
         }
@@ -651,70 +705,78 @@ hostx_screen_init(EphyrScreenInfo screen,
             free(host_screen->ximg->data);
             host_screen->ximg->data = NULL;
 
-            XDestroyImage(host_screen->ximg);
+            xcb_image_destroy(host_screen->ximg);
         }
     }
 
     if (HostX.have_shm) {
-        host_screen->ximg =
-            XShmCreateImage(HostX.dpy, HostX.visual, HostX.depth, ZPixmap, NULL,
-                            &host_screen->shminfo, width, buffer_height);
+        host_screen->ximg = xcb_image_create_native(HostX.conn,
+                                                    width,
+                                                    buffer_height,
+                                                    XCB_IMAGE_FORMAT_Z_PIXMAP,
+                                                    HostX.depth,
+                                                    NULL,
+                                                    ~0,
+                                                    NULL);
 
         host_screen->shminfo.shmid =
             shmget(IPC_PRIVATE,
-                   host_screen->ximg->bytes_per_line * buffer_height,
+                   host_screen->ximg->stride * buffer_height,
                    IPC_CREAT | 0777);
         host_screen->ximg->data = shmat(host_screen->shminfo.shmid, 0, 0);
         host_screen->shminfo.shmaddr = host_screen->ximg->data;
 
-        if (host_screen->ximg->data == (char *) -1) {
+        if (host_screen->ximg->data == (uint8_t *) -1) {
             EPHYR_DBG
                 ("Can't attach SHM Segment, falling back to plain XImages");
             HostX.have_shm = False;
-            XDestroyImage(host_screen->ximg);
+            xcb_image_destroy (host_screen->ximg);
             shmctl(host_screen->shminfo.shmid, IPC_RMID, 0);
         }
         else {
             EPHYR_DBG("SHM segment attached %p", host_screen->shminfo.shmaddr);
-            host_screen->shminfo.readOnly = False;
-            XShmAttach(HostX.dpy, &host_screen->shminfo);
+            host_screen->shminfo.shmseg = xcb_generate_id(HostX.conn);
+            xcb_shm_attach(HostX.conn,
+                           host_screen->shminfo.shmseg,
+                           host_screen->shminfo.shmid,
+                           False);
             shm_success = True;
         }
     }
 
     if (!shm_success) {
-        bitmap_pad = (HostX.depth > 16) ? 32 : ((HostX.depth > 8) ? 16 : 8);
-
         EPHYR_DBG("Creating image %dx%d for screen host_screen=%p\n",
                   width, buffer_height, host_screen);
-        host_screen->ximg = XCreateImage(HostX.dpy,
-                                         HostX.visual,
-                                         HostX.depth,
-                                         ZPixmap, 0, 0,
-                                         width, buffer_height, bitmap_pad, 0);
+        host_screen->ximg = xcb_image_create_native(HostX.conn,
+                                                    width,
+                                                    buffer_height,
+                                                    XCB_IMAGE_FORMAT_Z_PIXMAP,
+                                                    HostX.depth,
+                                                    NULL,
+                                                    ~0,
+                                                    NULL);
 
         host_screen->ximg->data =
-            malloc(host_screen->ximg->bytes_per_line * buffer_height);
+            malloc(host_screen->ximg->stride * buffer_height);
     }
 
-    *bytes_per_line = host_screen->ximg->bytes_per_line;
-    *bits_per_pixel = host_screen->ximg->bits_per_pixel;
-
-    XResizeWindow(HostX.dpy, host_screen->win, width, height);
+    *bytes_per_line = host_screen->ximg->stride;
+    *bits_per_pixel = host_screen->ximg->bpp;
 
-    /* Ask the WM to keep our size static */
     if (host_screen->win_pre_existing == None && !EphyrWantResize) {
-        size_hints = XAllocSizeHints();
-        size_hints->max_width = size_hints->min_width = width;
-        size_hints->max_height = size_hints->min_height = height;
-        size_hints->flags = PMinSize | PMaxSize;
-        XSetWMNormalHints(HostX.dpy, host_screen->win, size_hints);
-        XFree(size_hints);
+        /* Ask the WM to keep our size static */
+        xcb_size_hints_t size_hints = {0};
+        size_hints.max_width = size_hints.min_width = width;
+        size_hints.max_height = size_hints.min_height = height;
+        size_hints.flags = (XCB_ICCCM_SIZE_HINT_P_MIN_SIZE |
+                            XCB_ICCCM_SIZE_HINT_P_MAX_SIZE);
+        xcb_icccm_set_wm_normal_hints(HostX.conn, host_screen->win,
+                                      &size_hints);
     }
 
-    XMapWindow(HostX.dpy, host_screen->win);
+    xcb_map_window(HostX.conn, host_screen->win);
 
-    XSync(HostX.dpy, False);
+    xcb_aux_sync(HostX.conn);
 
     host_screen->win_width = width;
     host_screen->win_height = height;
@@ -787,14 +849,15 @@ hostx_paint_rect(EphyrScreenInfo screen,
 
                     host_pixel = (r << 16) | (g << 8) | (b);
 
-                    XPutPixel(host_screen->ximg, x, y, host_pixel);
+                    xcb_image_put_pixel(host_screen->ximg, x, y, host_pixel);
                     break;
                 }
                 case 8:
                 {
                     unsigned char pixel =
                         *(unsigned char *) (host_screen->fb_data + idx);
-                    XPutPixel(host_screen->ximg, x, y, HostX.cmap[pixel]);
+                    xcb_image_put_pixel(host_screen->ximg, x, y,
+                                        HostX.cmap[pixel]);
                     break;
                 }
                 default:
@@ -804,16 +867,17 @@ hostx_paint_rect(EphyrScreenInfo screen,
     }
 
     if (HostX.have_shm) {
-        XShmPutImage(HostX.dpy, host_screen->win,
-                     HostX.gc, host_screen->ximg,
-                     sx, sy, dx, dy, width, height, False);
+        xcb_image_shm_put(HostX.conn, host_screen->win,
+                          HostX.gc, host_screen->ximg,
+                          host_screen->shminfo,
+                          sx, sy, dx, dy, width, height, False);
     }
     else {
-        XPutImage(HostX.dpy, host_screen->win, HostX.gc, host_screen->ximg,
-                  sx, sy, dx, dy, width, height);
+        xcb_image_put(HostX.conn, host_screen->win, HostX.gc, host_screen->ximg,
+                      dx, dy, 0);
     }
 
-    XSync(HostX.dpy, False);
+    xcb_aux_sync(HostX.conn);
 }
 
 static void
@@ -821,6 +885,9 @@ hostx_paint_debug_rect(struct EphyrHostScreen *host_screen,
                        int x, int y, int width, int height)
 {
     struct timespec tspec;
+    xcb_rectangle_t rect = { .x = x, .y = y, .width = width, .height = height };
+    xcb_void_cookie_t cookie;
+    xcb_generic_error_t *e;
 
     tspec.tv_sec = HostX.damage_debug_msec / (1000000);
     tspec.tv_nsec = (HostX.damage_debug_msec % 1000000) * 1000;
@@ -830,8 +897,10 @@ hostx_paint_debug_rect(struct EphyrHostScreen *host_screen,
 
     /* fprintf(stderr, "Xephyr updating: %i+%i %ix%i\n", x, y, width, height); */
 
-    XFillRectangle(HostX.dpy, host_screen->win, HostX.gc, x, y, width, height);
-    XSync(HostX.dpy, False);
+    cookie = xcb_poly_fill_rectangle_checked(HostX.conn, host_screen->win,
+                                             HostX.gc, 1, &rect);
+    e = xcb_request_check(HostX.conn, cookie);
+    free(e);
 
     /* nanosleep seems to work better than usleep for me... */
     nanosleep(&tspec, NULL);
@@ -1023,6 +1092,18 @@ hostx_get_display(void)
     return HostX.dpy;
 }
 
+xcb_connection_t *
+hostx_get_xcbconn(void)
+{
+    return HostX.conn;
+}
+
+int
+hostx_get_screen(void)
+{
+    return DefaultScreen(HostX.dpy);
+}
+
 int
 hostx_get_window(int a_screen_number)
 {
@@ -1036,19 +1117,24 @@ hostx_get_window(int a_screen_number)
 int
 hostx_get_window_attributes(int a_window, EphyrHostWindowAttributes * a_attrs)
 {
-    XWindowAttributes attrs;
-
-    memset(&attrs, 0, sizeof(attrs));
-
-    if (!XGetWindowAttributes(hostx_get_display(), a_window, &attrs)) {
-        return FALSE;
-    }
-    a_attrs->x = attrs.x;
-    a_attrs->y = attrs.y;
-    a_attrs->width = attrs.width;
-    a_attrs->height = attrs.height;
-    if (attrs.visual)
-        a_attrs->visualid = attrs.visual->visualid;
+    xcb_get_geometry_cookie_t geom_cookie;
+    xcb_get_window_attributes_cookie_t attr_cookie;
+    xcb_get_geometry_reply_t *geom_reply;
+    xcb_get_window_attributes_reply_t *attr_reply;
+
+    geom_cookie = xcb_get_geometry(HostX.conn, a_window);
+    attr_cookie = xcb_get_window_attributes(HostX.conn, a_window);
+    geom_reply = xcb_get_geometry_reply(HostX.conn, geom_cookie, NULL);
+    attr_reply = xcb_get_window_attributes_reply(HostX.conn, attr_cookie, NULL);
+
+    a_attrs->x = geom_reply->x;
+    a_attrs->y = geom_reply->y;
+    a_attrs->width = geom_reply->width;
+    a_attrs->height = geom_reply->height;
+    a_attrs->visualid = attr_reply->visual;
+
+    free(geom_reply);
+    free(attr_reply);
     return TRUE;
 }
 
@@ -1120,54 +1206,56 @@ hostx_create_window(int a_screen_number,
                     int a_visual_id, int *a_host_peer /*out parameter */ )
 {
     Bool is_ok = FALSE;
-    Display *dpy = hostx_get_display();
-    XVisualInfo *visual_info = NULL, visual_info_templ;
-    int visual_mask = VisualIDMask;
-    Window win = None;
-    int nb_visuals = 0, winmask = 0;
-    XSetWindowAttributes attrs;
-
-    EPHYR_RETURN_VAL_IF_FAIL(dpy && a_geometry, FALSE);
+    xcb_window_t win;
+    int winmask = 0;
+    uint32_t attrs[2];
+    xcb_screen_t *screen = xcb_aux_get_screen(HostX.conn, hostx_get_screen());
+    xcb_visualtype_t *visual;
+    int depth = 0;
+    EPHYR_RETURN_VAL_IF_FAIL(screen && a_geometry, FALSE);
 
     EPHYR_LOG("enter\n");
 
-    /*get visual */
-    memset(&visual_info, 0, sizeof(visual_info));
-    visual_info_templ.visualid = a_visual_id;
-    visual_info = XGetVisualInfo(dpy, visual_mask,
-                                 &visual_info_templ, &nb_visuals);
-    if (!visual_info) {
-        EPHYR_LOG_ERROR("argh, could not find a remote visual with id:%d\n",
-                        a_visual_id);
-        goto out;
-    }
-    memset(&attrs, 0, sizeof(attrs));
-    attrs.colormap = XCreateColormap(dpy,
-                                     RootWindow(dpy,
-                                                visual_info->screen),
-                                     visual_info->visual, AllocNone);
-    attrs.event_mask = ButtonPressMask
-        | ButtonReleaseMask
-        | PointerMotionMask | KeyPressMask | KeyReleaseMask | ExposureMask;
-    winmask = CWColormap | CWEventMask;
-
-    win = XCreateWindow(dpy, hostx_get_window(a_screen_number),
-                        a_geometry->x, a_geometry->y,
-                        a_geometry->width, a_geometry->height, 0,
-                        visual_info->depth, CopyFromParent,
-                        visual_info->visual, winmask, &attrs);
-    if (win == None) {
-        EPHYR_LOG_ERROR("failed to create peer window\n");
+    visual = xcb_aux_find_visual_by_id(screen, a_visual_id);
+    if (!visual) {
+        EPHYR_LOG_ERROR ("argh, could not find a remote visual with id:%d\n",
+                         a_visual_id);
         goto out;
     }
-    if (HostX.screens[a_screen_number].peer_win == None) {
+    depth = xcb_aux_get_depth_of_visual(screen, a_visual_id);
+
+    winmask = XCB_CW_EVENT_MASK | XCB_CW_COLORMAP;
+    attrs[0] = XCB_EVENT_MASK_BUTTON_PRESS
+              |XCB_EVENT_MASK_BUTTON_RELEASE
+              |XCB_EVENT_MASK_POINTER_MOTION
+              |XCB_EVENT_MASK_KEY_PRESS
+              |XCB_EVENT_MASK_KEY_RELEASE
+              |XCB_EVENT_MASK_EXPOSURE;
+    attrs[1] = xcb_generate_id(HostX.conn);
+    xcb_create_colormap(HostX.conn,
+                        XCB_COLORMAP_ALLOC_NONE,
+                        attrs[1],
+                        hostx_get_window(a_screen_number),
+                        a_visual_id);
+
+    win = xcb_generate_id(HostX.conn);
+    xcb_create_window(HostX.conn,
+                      depth,
+                      win,
+                      hostx_get_window (a_screen_number),
+                      a_geometry->x, a_geometry->y,
+                      a_geometry->width, a_geometry->height, 0,
+                      XCB_WINDOW_CLASS_COPY_FROM_PARENT,
+                      a_visual_id, winmask, attrs);
+
+    if (HostX.screens[a_screen_number].peer_win == XCB_NONE) {
         HostX.screens[a_screen_number].peer_win = win;
     }
     else {
         EPHYR_LOG_ERROR("multiple peer windows created for same screen\n");
     }
-    XFlush(dpy);
-    XMapWindow(dpy, win);
+    xcb_flush(HostX.conn);
+    xcb_map_window(HostX.conn, win);
     *a_host_peer = win;
     is_ok = TRUE;
  out:
@@ -1178,26 +1266,31 @@ hostx_create_window(int a_screen_number,
 int
 hostx_destroy_window(int a_win)
 {
-    Display *dpy = hostx_get_display();
-
-    EPHYR_RETURN_VAL_IF_FAIL(dpy, FALSE);
-    XDestroyWindow(dpy, a_win);
-    XFlush(dpy);
+    xcb_destroy_window(HostX.conn, a_win);
+    xcb_flush(HostX.conn);
     return TRUE;
 }
 
 int
 hostx_set_window_geometry(int a_win, EphyrBox * a_geo)
 {
-    Display *dpy = hostx_get_display();
+    uint32_t mask = XCB_CONFIG_WINDOW_X
+                  | XCB_CONFIG_WINDOW_Y
+                  | XCB_CONFIG_WINDOW_WIDTH
+                  | XCB_CONFIG_WINDOW_HEIGHT;
+    uint32_t values[4];
 
-    EPHYR_RETURN_VAL_IF_FAIL(dpy && a_geo, FALSE);
+    EPHYR_RETURN_VAL_IF_FAIL(a_geo, FALSE);
 
     EPHYR_LOG("enter. x,y,w,h:(%d,%d,%d,%d)\n",
               a_geo->x, a_geo->y, a_geo->width, a_geo->height);
 
-    XMoveWindow(dpy, a_win, a_geo->x, a_geo->y);
-    XResizeWindow(dpy, a_win, a_geo->width, a_geo->height);
+    values[0] = a_geo->x;
+    values[1] = a_geo->y;
+    values[2] = a_geo->width;
+    values[3] = a_geo->height;
+    xcb_configure_window(HostX.conn, a_win, mask, values);
+
     EPHYR_LOG("leave\n");
     return TRUE;
 }
@@ -1271,13 +1364,10 @@ hostx_set_window_clipping_rectangles(int a_window,
 int
 hostx_has_xshape(void)
 {
-    int event_base = 0, error_base = 0;
-    Display *dpy = hostx_get_display();
+    const xcb_query_extension_reply_t *rep;
 
-    if (!XShapeQueryExtension(dpy, &event_base, &error_base)) {
-        return FALSE;
-    }
-    return TRUE;
+    rep = xcb_get_extension_data(HostX.conn, &xcb_shape_id);
+    return rep && rep->present;
 }
 
 #ifdef XF86DRI
@@ -1296,7 +1386,6 @@ hostx_allocate_resource_id_peer(int a_local_resource_id,
 {
     int i = 0;
     ResourcePair *peer = NULL;
-    Display *dpy = hostx_get_display();
 
     /*
      * first make sure a resource peer
@@ -1321,7 +1410,7 @@ hostx_allocate_resource_id_peer(int a_local_resource_id,
             }
         }
         if (peer) {
-            peer->remote_id = XAllocID(dpy);
+            peer->remote_id = xcb_generate_id(HostX.conn);
             peer->local_id = a_local_resource_id;
             peer->is_valid = TRUE;
         }
@@ -1356,28 +1445,21 @@ hostx_get_resource_id_peer(int a_local_resource_id, int *a_remote_resource_id)
 int
 hostx_has_dri(void)
 {
-    int event_base = 0, error_base = 0;
-    Display *dpy = hostx_get_display();
+    const xcb_query_extension_reply_t *dri;
 
-    if (!dpy)
-        return FALSE;
+    dri = xcb_get_extension_data(HostX.conn, &xcb_xf86dri_id);
 
-    if (!XF86DRIQueryExtension(dpy, &event_base, &error_base)) {
-        return FALSE;
-    }
-    return TRUE;
+    return dri && dri->present;
 }
 
 int
 hostx_has_glx(void)
 {
-    Display *dpy = hostx_get_display();
-    int event_base = 0, error_base = 0;
+    const xcb_query_extension_reply_t *glx;
 
-    if (!glXQueryExtension(dpy, &event_base, &error_base)) {
-        return FALSE;
-    }
-    return TRUE;
+    glx = xcb_get_extension_data(HostX.conn, &xcb_glx_id);
+
+    return glx && glx->present;
 }
 
 #endif                          /* XF86DRI */
diff --git a/hw/kdrive/ephyr/hostx.h b/hw/kdrive/ephyr/hostx.h
index f165606..c065f2d 100644
--- a/hw/kdrive/ephyr/hostx.h
+++ b/hw/kdrive/ephyr/hostx.h
@@ -28,6 +28,7 @@
 
 #include <X11/X.h>
 #include <X11/Xmd.h>
+#include <xcb/xcb.h>
 
 #define EPHYR_WANT_DEBUG 0
 
@@ -206,6 +207,12 @@ int
 
 void *hostx_get_display(void);
 
+xcb_connection_t *
+hostx_get_xcbconn(void);
+
+int
+hostx_get_screen(void);
+
 int
  hostx_get_window(int a_screen_number);
 
commit 762606b4cdfb57c5202ae128ce4dbb8afe172d4e
Author: Julien Cristau <jcristau at debian.org>
Date:   Fri Jun 25 17:59:13 2010 +0100

    Xephyr: stop loading the host's keymap
    
    This isn't used anywhere.
    
    v2: Rebase to the top of the patch series (anholt)
    
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net> (v1)
    Signed-off-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index 02d4970..b34b5cc 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -1091,7 +1091,7 @@ EphyrKeyboardInit(KdKeyboardInfo * ki)
     ki->driverPrivate = (EphyrKbdPrivate *)
         calloc(sizeof(EphyrKbdPrivate), 1);
     hostx_load_keymap();
-    if (!ephyrKeySyms.map) {
+    if (!ephyrKeySyms.minKeyCode) {
         ErrorF("Couldn't load keymap from host\n");
         return BadAlloc;
     }
diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index 5071289..f46770f 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -840,45 +840,14 @@ hostx_paint_debug_rect(struct EphyrHostScreen *host_screen,
 void
 hostx_load_keymap(void)
 {
-    XID *keymap;
-    int host_width, min_keycode, max_keycode, width;
-    int i, j;
+    int min_keycode, max_keycode;
 
     XDisplayKeycodes(HostX.dpy, &min_keycode, &max_keycode);
 
     EPHYR_DBG("min: %d, max: %d", min_keycode, max_keycode);
 
-    keymap = XGetKeyboardMapping(HostX.dpy,
-                                 min_keycode,
-                                 max_keycode - min_keycode + 1, &host_width);
-
-    /* Try and copy the hosts keymap into our keymap to avoid loads
-     * of messing around.
-     *
-     * kdrive cannot can have more than 4 keysyms per keycode
-     * so we only copy at most the first 4 ( xorg has 6 per keycode, XVNC 2 )
-     */
-    width = (host_width > 4) ? 4 : host_width;
-
-    ephyrKeySyms.map = (CARD32 *) calloc(sizeof(CARD32),
-                                         (max_keycode - min_keycode + 1) *
-                                         width);
-    if (!ephyrKeySyms.map)
-        goto out;
-
-    for (i = 0; i < (max_keycode - min_keycode + 1); i++)
-        for (j = 0; j < width; j++)
-            ephyrKeySyms.map[(i * width) + j] =
-                (CARD32) keymap[(i * host_width) + j];
-
-    EPHYR_DBG("keymap width, host:%d kdrive:%d", host_width, width);
-
     ephyrKeySyms.minKeyCode = min_keycode;
     ephyrKeySyms.maxKeyCode = max_keycode;
-    ephyrKeySyms.mapWidth = width;
-
- out:
-    XFree(keymap);
 }
 
 static struct EphyrHostScreen *
diff --git a/hw/kdrive/ephyr/hostx.h b/hw/kdrive/ephyr/hostx.h
index f47297c..f165606 100644
--- a/hw/kdrive/ephyr/hostx.h
+++ b/hw/kdrive/ephyr/hostx.h
@@ -51,12 +51,9 @@ typedef enum EphyrHostXEventType {
     EPHYR_EV_CONFIGURE,
 } EphyrHostXEventType;
 
-/* I can't believe it's not a KeySymsRec. */
 typedef struct {
     int minKeyCode;
     int maxKeyCode;
-    int mapWidth;
-    CARD32 *map;
 } EphyrKeySyms;
 
 struct EphyrHostXEvent {


More information about the xorg-commit mailing list