[Xquartz-changes] xserver: Branch 'master' - 108 commits

Jeremy Huddleston jeremyhu at freedesktop.org
Sun Oct 6 09:21:32 PDT 2013


 Xext/panoramiX.c                        |    6 
 Xext/security.c                         |   11 
 composite/compalloc.c                   |    4 
 config/udev.c                           |    4 
 configure.ac                            |   12 
 damageext/damageext.c                   |   42 -
 dbe/Makefile.am                         |    3 
 dbe/dbe.c                               |   81 --
 dbe/dbestruct.h                         |   21 
 dbe/midbe.c                             |  126 ---
 dbe/midbestr.h                          |   75 -
 dix/cursor.c                            |    6 
 dix/dispatch.c                          |   88 --
 dix/pixmap.c                            |    1 
 dix/privates.c                          |    1 
 dix/window.c                            |    6 
 exa/exa_classic.c                       |    1 
 exa/exa_migration_mixed.c               |    1 
 exa/exa_mixed.c                         |    2 
 fb/fb.h                                 |   34 
 fb/fbcopy.c                             |   27 
 glx/glxcmds.c                           |  103 +-
 glx/glxcontext.h                        |    1 
 glx/glxdri2.c                           |    3 
 glx/glxext.c                            |    4 
 glx/glxscreens.c                        |   17 
 glx/glxscreens.h                        |    5 
 hw/dmx/Makefile.am                      |    2 
 hw/dmx/dmx.h                            |    4 
 hw/dmx/dmxcursor.c                      |    2 
 hw/dmx/dmxinit.c                        |   10 
 hw/dmx/dmxpict.c                        |    4 
 hw/dmx/dmxscrinit.c                     |  255 ++----
 hw/dmx/dmxshadow.c                      |   70 -
 hw/dmx/dmxshadow.h                      |   46 -
 hw/dmx/glxProxy/Makefile.am             |    1 
 hw/dmx/glxProxy/glxcmds.c               |    2 
 hw/dmx/glxProxy/glxext.c                |    6 
 hw/dmx/glxProxy/glxserver.h             |    2 
 hw/dmx/glxProxy/glxutil.c               |   37 
 hw/dmx/glxProxy/glxutil.h               |    2 
 hw/dmx/input/dmxbackend.c               |    6 
 hw/dmx/input/dmxcommon.c                |    5 
 hw/dmx/input/usb-private.h              |    4 
 hw/dmx/man/Xdmx.man                     |   10 
 hw/kdrive/ephyr/Makefile.am             |   91 --
 hw/kdrive/ephyr/XF86dri.c               |  654 -----------------
 hw/kdrive/ephyr/ephyr.c                 |  444 ++++++++---
 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             |   33 
 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 ---
 hw/xfree86/Makefile.am                  |   19 
 hw/xfree86/common/xf86Cursor.c          |    3 
 hw/xfree86/modes/xf86Rotate.c           |    6 
 hw/xfree86/os-support/hurd/hurd_init.c  |    1 
 hw/xfree86/os-support/hurd/hurd_mmap.c  |    1 
 hw/xfree86/os-support/hurd/hurd_video.c |    1 
 hw/xfree86/os-support/shared/vidmem.c   |   13 
 hw/xfree86/os-support/xf86OSpriv.h      |    2 
 hw/xfree86/os-support/xf86_OSproc.h     |    2 
 hw/xfree86/vbe/vbe.c                    |   17 
 hw/xnest/GCOps.c                        |   14 
 hw/xnest/Pixmap.c                       |   15 
 hw/xnest/Screen.c                       |    1 
 hw/xnest/XNPixmap.h                     |    2 
 hw/xquartz/GL/glcontextmodes.c          |    1 
 hw/xquartz/GL/visualConfigs.c           |    3 
 hw/xquartz/xpr/xprCursor.c              |    2 
 hw/xwin/glx/indirect.c                  |    3 
 include/cursorstr.h                     |    2 
 include/dixstruct.h                     |   11 
 include/extinit.h                       |    2 
 include/list.h                          |    2 
 include/privates.h                      |    1 
 mi/miinitext.c                          |    5 
 mi/mipointer.c                          |   23 
 mi/mipointer.h                          |   12 
 mi/misprite.c                           |   10 
 mi/miwideline.c                         |    6 
 miext/damage/damage.c                   |  151 ---
 miext/damage/damage.h                   |   20 
 miext/damage/damagestr.h                |    3 
 miext/rootless/rootlessWindow.c         |    6 
 miext/shadow/Makefile.am                |    1 
 miext/shadow/shadow.c                   |    2 
 miext/sync/misync.c                     |   21 
 os/access.c                             |    8 
 os/io.c                                 |   63 -
 os/utils.c                              |    2 
 randr/rrpointer.c                       |    2 
 test/.gitignore                         |    1 
 105 files changed, 2122 insertions(+), 5341 deletions(-)

New commits:
commit 8aae28e3cbdd49bfa8d940a4a517c94a53b94f86
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Sun Oct 6 09:20:45 2013 -0700

    XQuartz: Dont't set screen on __GLXConfig
    
    Fixes regression introduced by c3c976f54c3c282d6fa6c8360688e036bc43d210
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/hw/xquartz/GL/visualConfigs.c b/hw/xquartz/GL/visualConfigs.c
index 92142cb..687bf80 100644
--- a/hw/xquartz/GL/visualConfigs.c
+++ b/hw/xquartz/GL/visualConfigs.c
@@ -140,8 +140,6 @@ __GLXconfig *__glXAquaCreateVisualConfigs(int *numConfigsPtr, int screenNumber)
                                         c->visualType = GLX_TRUE_COLOR;
                                         c->next = c + 1;
 
-                                        c->screen = screenNumber;
-
                                         c->level = 0;
                                         c->indexBits = 0;
 
commit c5f8eb968efa970201712105a1ac880b517e7b6d
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Sun Oct 6 09:18:15 2013 -0700

    rootless: Use miCopyRegion instead of fbCopyRegion
    
    Fixes regression introduced by e657635dbe6b92875b0e88370557c2cbab673a49
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/miext/rootless/rootlessWindow.c b/miext/rootless/rootlessWindow.c
index cfcb6e5..7e3c281 100644
--- a/miext/rootless/rootlessWindow.c
+++ b/miext/rootless/rootlessWindow.c
@@ -684,7 +684,7 @@ RootlessResizeCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg,
     if (gResizeDeathCount == 1) {
         /* Simple case, we only have a single source pixmap. */
 
-        fbCopyRegion(&gResizeDeathPix[0]->drawable,
+        miCopyRegion(&gResizeDeathPix[0]->drawable,
                      &pScreen->GetWindowPixmap(pWin)->drawable, 0,
                      &rgnDst, dx, dy, fbCopyWindowProc, 0, 0);
     }
@@ -700,7 +700,7 @@ RootlessResizeCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg,
             RegionNull(&clipped);
             RegionIntersect(&rgnDst, &clip, &clipped);
 
-            fbCopyRegion(&gResizeDeathPix[i]->drawable,
+            miCopyRegion(&gResizeDeathPix[i]->drawable,
                          &pScreen->GetWindowPixmap(pWin)->drawable, 0,
                          &clipped, dx, dy, fbCopyWindowProc, 0, 0);
 
@@ -778,7 +778,7 @@ RootlessCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
     else {
         RootlessStartDrawing(pWin);
 
-        fbCopyRegion((DrawablePtr) pWin, (DrawablePtr) pWin,
+        miCopyRegion((DrawablePtr) pWin, (DrawablePtr) pWin,
                      0, &rgnDst, dx, dy, fbCopyWindowProc, 0, 0);
 
         /* prgnSrc has been translated to dst position */
commit ccbe17b1c6da1ad9d085fc8133cdd15dc7004a4a
Author: Pino Toscano <toscano.pino at tiscali.it>
Date:   Wed Aug 28 17:15:03 2013 +0200

    os: move <arpa/inet.h> for any !win32 system
    
    It is needed in IPv6 configurations (for inet_pton) also when
    SIOCGIFCONF is not defined.
    
    Signed-off-by: Pino Toscano <toscano.pino at tiscali.it>
    Acked-by: Samuel Thibault <samuel.thibault at ens-lyon.org>
    Signed-off-by: Julien Cristau <jcristau at debian.org>

diff --git a/os/access.c b/os/access.c
index 88a44d9..6d991b3 100644
--- a/os/access.c
+++ b/os/access.c
@@ -163,6 +163,10 @@ SOFTWARE.
 /* #endif */
 #endif
 
+#if defined(IPv6) && defined(AF_INET6)
+#include <arpa/inet.h>
+#endif
+
 #endif                          /* WIN32 */
 
 #define X_INCLUDE_NETDB_H
@@ -461,10 +465,6 @@ DefineSelf(int fd)
 #endif
 
 #if defined(IPv6) && defined(AF_INET6)
-#include <arpa/inet.h>
-#endif
-
-#if defined(IPv6) && defined(AF_INET6)
 static void
 in6_fillscopeid(struct sockaddr_in6 *sin6)
 {
commit c079b8e675dd2762c9e07fe5d8c07612299dceb7
Author: Pino Toscano <toscano.pino at tiscali.it>
Date:   Wed Aug 28 17:04:48 2013 +0200

    xfree86/hurd: include <hurd.h>
    
    Needed for using get_privileged_port.
    
    Signed-off-by: Pino Toscano <toscano.pino at tiscali.it>
    Acked-by: Samuel Thibault <samuel.thibault at ens-lyon.org>
    Signed-off-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/xfree86/os-support/hurd/hurd_init.c b/hw/xfree86/os-support/hurd/hurd_init.c
index 185b2b9..fe1a764 100644
--- a/hw/xfree86/os-support/hurd/hurd_init.c
+++ b/hw/xfree86/os-support/hurd/hurd_init.c
@@ -42,6 +42,7 @@
 #include <sys/file.h>
 #include <assert.h>
 #include <mach.h>
+#include <hurd.h>
 
 int
 xf86ProcessArgument(int argc, char **argv, int i)
diff --git a/hw/xfree86/os-support/hurd/hurd_mmap.c b/hw/xfree86/os-support/hurd/hurd_mmap.c
index 6ac9efd..8e089ca 100644
--- a/hw/xfree86/os-support/hurd/hurd_mmap.c
+++ b/hw/xfree86/os-support/hurd/hurd_mmap.c
@@ -27,6 +27,7 @@
 #include<mach.h>
 #include<device/device.h>
 #include<mach/machine/mach_i386.h>
+#include <hurd.h>
 
 #include <X11/X.h>
 
diff --git a/hw/xfree86/os-support/hurd/hurd_video.c b/hw/xfree86/os-support/hurd/hurd_video.c
index 72474ba..b3b94c9 100644
--- a/hw/xfree86/os-support/hurd/hurd_video.c
+++ b/hw/xfree86/os-support/hurd/hurd_video.c
@@ -28,6 +28,7 @@
 #include <mach.h>
 #include <device/device.h>
 #include <mach/machine/mach_i386.h>
+#include <hurd.h>
 
 #include <X11/X.h>
 #include "input.h"
commit f0659a7f68a5a334879af01a6a63742eab1bf5de
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Oct 4 16:44:46 2013 -0700

    Bump version to 1.14.99.2
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index f322a8b..3df579a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,9 +26,9 @@ dnl
 dnl Process this file with autoconf to create configure.
 
 AC_PREREQ(2.60)
-AC_INIT([xorg-server], 1.14.99.1, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
-RELEASE_DATE="2013-04-24"
-RELEASE_NAME="Sweet Tea"
+AC_INIT([xorg-server], 1.14.99.2, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
+RELEASE_DATE="2013-10-04"
+RELEASE_NAME="Chicory Coffee"
 AC_CONFIG_SRCDIR([Makefile.am])
 AM_INIT_AUTOMAKE([foreign dist-bzip2])
 
commit f2d149b6d10edea7233d93c7e19f71decf11dc62
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Oct 4 16:43:41 2013 -0700

    kdrive/ephyr: Remove duplicate ephyrExtensions and ephyrExtensionInit decls
    
    These were duplicated when GLX support was re-added on two different branches.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/kdrive/ephyr/ephyrinit.c b/hw/kdrive/ephyr/ephyrinit.c
index 80b7a6a..cf8bc90 100644
--- a/hw/kdrive/ephyr/ephyrinit.c
+++ b/hw/kdrive/ephyr/ephyrinit.c
@@ -48,22 +48,6 @@ extern KdKeyboardDriver LinuxEvdevKeyboardDriver;
 
 void processScreenArg(const char *screen_size, char *parent_id);
 
-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
 InitCard(char *name)
 {
commit e0a678f0596f3547b98d74d5f0438b484b059458
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sat Sep 28 15:26:38 2013 -0400

    xfree86: add a comment as to why the logdir is created
    
    Without the logdir, the xserver will write the content of the log file on the
    terminal stating that it cannot be written and will stop.
    
    Refer to https://bugs.freedesktop.org/show_bug.cgi?id=3889
    
    Reviewed-By:  Matt Dew <marcoz at osource.org>
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/Makefile.am b/hw/xfree86/Makefile.am
index aed631b..59cfb5f 100644
--- a/hw/xfree86/Makefile.am
+++ b/hw/xfree86/Makefile.am
@@ -84,6 +84,7 @@ os-support/solaris/solaris- at SOLARIS_INOUT_ARCH@.il:
 	 $(MAKE) $(AM_MAKEFLAGS) solaris- at SOLARIS_INOUT_ARCH@.il
 endif
 
+# Without logdir, X will post an error on the terminal and will not start
 install-data-local:
 	$(AM_V_GEN)$(MKDIR_P) $(DESTDIR)$(logdir)
 if CYGWIN
commit 5bdbf2dba3f7da4a593b286020eab0c7857e940c
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sat Sep 28 15:26:37 2013 -0400

    xfree86: Use $(MKDIR_P) for better code portability
    
    Still true that we should not use the lower case $(mkdir_p) version.
    However, remove the 2005 comment as the MKDIR_P is widely used now.
    
    Reviewed-By:  Matt Dew <marcoz at osource.org>
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/Makefile.am b/hw/xfree86/Makefile.am
index 3410e4a..aed631b 100644
--- a/hw/xfree86/Makefile.am
+++ b/hw/xfree86/Makefile.am
@@ -84,9 +84,8 @@ os-support/solaris/solaris- at SOLARIS_INOUT_ARCH@.il:
 	 $(MAKE) $(AM_MAKEFLAGS) solaris- at SOLARIS_INOUT_ARCH@.il
 endif
 
-# do not use $(mkdir_p) if you want automake 1.7 to work
 install-data-local:
-	mkdir -p $(DESTDIR)$(logdir)
+	$(AM_V_GEN)$(MKDIR_P) $(DESTDIR)$(logdir)
 if CYGWIN
 	$(INSTALL_DATA) libXorg.exe.a $(DESTDIR)$(libdir)/libXorg.exe.a
 endif
commit b8cfb0dc8426754b477b561bc158b8a24c143ddf
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sat Sep 28 15:26:36 2013 -0400

    Uninstall X link and CYGWIN libXorg.exe.a in local install targets
    
    It is our duty to uninstall any files and/or directories that we installed
    through install-data-local and install-exec-hook.
    
    Currently the X symbolic link to Xorg remains on disk after running
    make uninstall.
    
    Note the exception for logdir which is usually shared by other modules.
    
    Reviewed-By:  Matt Dew <marcoz at osource.org>
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/Makefile.am b/hw/xfree86/Makefile.am
index 4b0edeb..3410e4a 100644
--- a/hw/xfree86/Makefile.am
+++ b/hw/xfree86/Makefile.am
@@ -98,6 +98,14 @@ if INSTALL_SETUID
 	chmod u+s $(DESTDIR)$(bindir)/Xorg
 endif
 
+uninstall-local:
+if CYGWIN
+	$(AM_V_at)rm -f $(DESTDIR)$(libdir)/libXorg.exe.a
+endif
+
+uninstall-hook:
+	$(AM_V_at)rm -f $(DESTDIR)$(bindir)/X
+
 # Use variables from XORG_MANPAGE_SECTIONS and X Server configuration
 # Do not include manpages.am as values are not appropriate for rc files
 CONF_SUBSTS =	-e 's|__filemansuffix__|$(FILE_MAN_SUFFIX)|g' \
commit 35a528e49269c3df75486cc606e51a8c1c083c06
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sat Sep 28 15:26:35 2013 -0400

    Xorg binary: use install-exec-hook rather than install-exec-local
    
    The former was explicitly designed to execute additional code after the binary
    has been installed. The latter can be executed in any order, hence it's
    current dependency on install-binPROGRAMS as a workaround.
    
    The CYGWIN libXorg.exe.a target is an installation target rather than
    a post-installation one, so it should not be done as a hook. It does not depend
    on the Xorg executable being installed.
    
    Automake:
    "These hooks are run after all other install rules of the appropriate type,
    exec or data, have completed. So, for instance, it is possible to perform
    post-installation modifications using an install hook".
    
    "With the -local targets, there is no particular guarantee of execution order;
    typically, they are run early, but with parallel make, there is no way
    to be sure of that".
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/Makefile.am b/hw/xfree86/Makefile.am
index 73bddab..4b0edeb 100644
--- a/hw/xfree86/Makefile.am
+++ b/hw/xfree86/Makefile.am
@@ -87,17 +87,16 @@ endif
 # do not use $(mkdir_p) if you want automake 1.7 to work
 install-data-local:
 	mkdir -p $(DESTDIR)$(logdir)
+if CYGWIN
+	$(INSTALL_DATA) libXorg.exe.a $(DESTDIR)$(libdir)/libXorg.exe.a
+endif
 
-
-install-exec-local: install-binPROGRAMS
+install-exec-hook:
 	(cd $(DESTDIR)$(bindir) && rm -f X && $(LN_S) Xorg$(EXEEXT) X)
 if INSTALL_SETUID
 	chown root $(DESTDIR)$(bindir)/Xorg
 	chmod u+s $(DESTDIR)$(bindir)/Xorg
 endif
-if CYGWIN
-	$(INSTALL_DATA) libXorg.exe.a $(DESTDIR)$(libdir)/libXorg.exe.a
-endif
 
 # Use variables from XORG_MANPAGE_SECTIONS and X Server configuration
 # Do not include manpages.am as values are not appropriate for rc files
commit a1d87576a30008253eb0cc92b44c9718f6665062
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sat Sep 28 15:26:34 2013 -0400

    Use $(LN_S) provided by AC_PROG_LN_S macro to create links
    
    For better code portability.
    
    Reviewed-By:  Matt Dew <marcoz at osource.org>
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/Makefile.am b/hw/xfree86/Makefile.am
index 6b66732..73bddab 100644
--- a/hw/xfree86/Makefile.am
+++ b/hw/xfree86/Makefile.am
@@ -90,7 +90,7 @@ install-data-local:
 
 
 install-exec-local: install-binPROGRAMS
-	(cd $(DESTDIR)$(bindir) && rm -f X && ln -s Xorg$(EXEEXT) X)
+	(cd $(DESTDIR)$(bindir) && rm -f X && $(LN_S) Xorg$(EXEEXT) X)
 if INSTALL_SETUID
 	chown root $(DESTDIR)$(bindir)/Xorg
 	chmod u+s $(DESTDIR)$(bindir)/Xorg
commit 28c8e1910797970dbf1d40794f1804a8fcc812bc
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sat Sep 28 15:26:33 2013 -0400

    The Xorg binary is missing the extension $(EXEEXT) in the makefile
    
    This is not a problem on UNIX platforms, but on CYGWIN it creates a broken
    link to Xorg rather than a link to Xorg.exe.
    
    From the CYGWIN log on tinderbox, we can see that the executable Xorg.exe is
    installed correctly. We can see the command used to create the link:
    
    (cd /jhbuild/install/[...]/install/bin && rm -f X && ln -s Xorg X)
    
    Note that the "relink" makefile target correctly appends $(EXEEXT) to Xorg.
    
    Reviewed-By:  Matt Dew <marcoz at osource.org>
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/Makefile.am b/hw/xfree86/Makefile.am
index d568e0d..6b66732 100644
--- a/hw/xfree86/Makefile.am
+++ b/hw/xfree86/Makefile.am
@@ -90,7 +90,7 @@ install-data-local:
 
 
 install-exec-local: install-binPROGRAMS
-	(cd $(DESTDIR)$(bindir) && rm -f X && ln -s Xorg X)
+	(cd $(DESTDIR)$(bindir) && rm -f X && ln -s Xorg$(EXEEXT) X)
 if INSTALL_SETUID
 	chown root $(DESTDIR)$(bindir)/Xorg
 	chmod u+s $(DESTDIR)$(bindir)/Xorg
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 4399bd38326b81f7b92365346504d7c6354772a9
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Mon Sep 30 13:30:46 2013 -0400

    miext/shadow: missing c2p_core.h breaks "make distcheck" target.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/miext/shadow/Makefile.am b/miext/shadow/Makefile.am
index 1db8a26..27cf414 100644
--- a/miext/shadow/Makefile.am
+++ b/miext/shadow/Makefile.am
@@ -7,6 +7,7 @@ sdk_HEADERS = shadow.h
 endif
 
 libshadow_la_SOURCES =		\
+	c2p_core.h		\
 	shadow.c		\
 	shadow.h		\
 	shafb4.c		\
commit 9ccb4a63982942fdce19609d2cadbd8e51708462
Merge: 5d2ec69 da5e201
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Oct 4 13:54:55 2013 -0700

    Merge remote-tracking branch 'whot/for-keith'

commit 5d2ec6933f6bb5116666ca1bfb07f0f20bf2a0b5
Merge: 7d3d4ae 6ee4d9f
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Oct 4 13:50:04 2013 -0700

    Merge remote-tracking branch 'ajax/xserver-next'

commit da5e20127a5b6e11a47eb6e61f3ea87b056cdf5f
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Thu Sep 19 19:13:35 2013 -0400

    test: add new os executable to .gitignore
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/test/.gitignore b/test/.gitignore
index 363d4b6..acbda7a 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -3,6 +3,7 @@ hashtabletest
 input
 list
 misc
+os
 string
 touch
 xfree86
commit c73c36b537f996574628e69681833ea37dec2b6e
Author: Laércio de Sousa <lbsousajr at gmail.com>
Date:   Wed Sep 18 13:42:17 2013 -0300

    xserver: enable InputClass option "GrabDevice" by default for non-seat0 seats (#69478)
    
    This patch contributes to fill the remaining gaps which make
    systemd-multi-seat-x wrapper still necessary in some multiseat setups.
    
    This also replaces previous evdev patch that does the same thing
    for that particular driver.
    
    When option "-seat" is passed with an argument different from "seat0",
    option "GrabDevice" for input devices is enabled by default
    (no need of enabling it in xorg.conf's "InputClass" section).
    
    Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=69478
    
    Signed-off-by: Laércio de Sousa <lbsousajr at gmail.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/config/udev.c b/config/udev.c
index de89241..b55b78e 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -226,6 +226,10 @@ device_added(struct udev_device *udev_device)
 
     input_options = input_option_new(input_options, "config_info", config_info);
 
+    /* Default setting needed for non-seat0 seats */
+    if (ServerIsNotSeat0())
+        input_options = input_option_new(input_options, "GrabDevice", "on");
+
     LogMessage(X_INFO, "config/udev: Adding input device %s (%s)\n",
                name, path);
     rc = NewInputDeviceRequest(input_options, &attrs, &dev);
commit 160c2db32d0b9ee5316a44179a6af4f4722e3d0a
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Sep 18 16:04:44 2013 +1000

    dmx: provide enough space for axis mappings
    
    relmap/absmap is used as a evdev-axis-to-x-axis mapping. ABS_X maps to
    axis 0, ABS_Y to 1, etc. skipping over non-existing axes so that the third bit
    set in the ABS_* range is axis 2, and so on. This requires us to actually have
    enough space to have all the ABS_*/REL_* range.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/hw/dmx/input/usb-private.h b/hw/dmx/input/usb-private.h
index 096607a..2ecfdf6 100644
--- a/hw/dmx/input/usb-private.h
+++ b/hw/dmx/input/usb-private.h
@@ -102,8 +102,8 @@ typedef struct _myPrivate {
     int fd;                                 /**< File descriptor */
     unsigned char mask[EV_MAX / 8 + 1];     /**< Mask */
     int numRel, numAbs, numLeds;            /**< Counts */
-    int relmap[DMX_MAX_AXES];               /**< Relative axis map */
-    int absmap[DMX_MAX_AXES];               /**< Absolute axis map */
+    int relmap[REL_CNT];                    /**< Relative axis map */
+    int absmap[ABS_CNT];                    /**< Absolute axis map */
 
     CARD32 kbdState[NUM_STATE_ENTRIES];         /**< Keyboard state */
     DeviceIntPtr pKeyboard;                     /** Keyboard device */
commit 7d3d4ae55dd6ee338439e2424ac423b1df80501b
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Sep 20 14:43:41 2013 -0500

    damage: Must translate initial window damage by window offset
    
    Damage is reported relative to the drawable origin, but the window
    borderClip is absolute. Translate the region by the window position
    before reporting damage to adjust.
    
    Reported-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/damageext/damageext.c b/damageext/damageext.c
index a942ffa..cf6b63b 100644
--- a/damageext/damageext.c
+++ b/damageext/damageext.c
@@ -223,7 +223,9 @@ ProcDamageCreate(ClientPtr client)
 
     if (pDrawable->type == DRAWABLE_WINDOW) {
         pRegion = &((WindowPtr) pDrawable)->borderClip;
+        RegionTranslate(pRegion, -pDrawable->x, -pDrawable->y);
         DamageReportDamage(pDamageExt->pDamage, pRegion);
+        RegionTranslate(pRegion, pDrawable->x, pDrawable->y);
     }
 
     return Success;
commit 6ee4d9f94ae2cc27c39381d7554134d9b4807a65
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 9 11:19:11 2013 -0400

    glx: Fill in some missing attributes from DoGetFBConfigs
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index 0ab2ed5..73e76ca 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -1032,7 +1032,7 @@ __glXDisp_GetVisualConfigs(__GLXclientState * cl, GLbyte * pc)
     return Success;
 }
 
-#define __GLX_TOTAL_FBCONFIG_ATTRIBS (37)
+#define __GLX_TOTAL_FBCONFIG_ATTRIBS (44)
 #define __GLX_FBCONFIG_ATTRIBS_LENGTH (__GLX_TOTAL_FBCONFIG_ATTRIBS * 2)
 /**
  * Send the set of GLXFBConfigs to the client.  There is not currently
@@ -1117,13 +1117,23 @@ DoGetFBConfigs(__GLXclientState * cl, unsigned screen)
         WRITE_PAIR(GLX_SWAP_METHOD_OML, modes->swapMethod);
         WRITE_PAIR(GLX_SAMPLES_SGIS, modes->samples);
         WRITE_PAIR(GLX_SAMPLE_BUFFERS_SGIS, modes->sampleBuffers);
-        /* GLX_VISUAL_SELECT_GROUP_SGIX ? */
+        WRITE_PAIR(GLX_VISUAL_SELECT_GROUP_SGIX, modes->visualSelectGroup);
         WRITE_PAIR(GLX_DRAWABLE_TYPE, modes->drawableType);
         WRITE_PAIR(GLX_BIND_TO_TEXTURE_RGB_EXT, modes->bindToTextureRgb);
         WRITE_PAIR(GLX_BIND_TO_TEXTURE_RGBA_EXT, modes->bindToTextureRgba);
         WRITE_PAIR(GLX_BIND_TO_MIPMAP_TEXTURE_EXT, modes->bindToMipmapTexture);
         WRITE_PAIR(GLX_BIND_TO_TEXTURE_TARGETS_EXT,
                    modes->bindToTextureTargets);
+	WRITE_PAIR(GLX_Y_INVERTED_EXT, modes->yInverted);
+	if (modes->drawableType & GLX_PBUFFER_BIT) {
+	    WRITE_PAIR(GLX_MAX_PBUFFER_WIDTH, modes->maxPbufferWidth);
+	    WRITE_PAIR(GLX_MAX_PBUFFER_HEIGHT, modes->maxPbufferHeight);
+	    WRITE_PAIR(GLX_MAX_PBUFFER_PIXELS, modes->maxPbufferPixels);
+	    WRITE_PAIR(GLX_OPTIMAL_PBUFFER_WIDTH_SGIX,
+		       modes->optimalPbufferWidth);
+	    WRITE_PAIR(GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX,
+		       modes->optimalPbufferHeight);
+	}
         /* Add attribute only if its value is not default. */
         if (modes->sRGBCapable != GL_FALSE) {
             WRITE_PAIR(GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT, modes->sRGBCapable);
commit b257fabff00ae925bb7e70364dd1d738634087c9
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu Jul 4 10:31:40 2013 -0400

    glx: Remove a dead comment
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/glx/glxext.c b/glx/glxext.c
index bc7fe82..2c3f5ed 100644
--- a/glx/glxext.c
+++ b/glx/glxext.c
@@ -286,10 +286,6 @@ glxClientCallback(CallbackListPtr *list, pointer closure, pointer data)
 
     switch (pClient->clientState) {
     case ClientStateRunning:
-        /*
-         ** By default, assume that the client supports
-         ** GLX major version 1 minor version 0 protocol.
-         */
         cl->client = pClient;
         break;
 
commit abd086502123086ce3d1fba25c159bb022d2750f
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Jul 8 17:01:13 2013 -0400

    glx: Catch another failure case in drawable creation
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index 9deadb7..0ab2ed5 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -515,6 +515,10 @@ __glXGetDrawable(__GLXcontext * glxc, GLXDrawable drawId, ClientPtr client,
                                                 pDraw, drawId,
                                                 GLX_DRAWABLE_WINDOW,
                                                 drawId, glxc->config);
+    if (!pGlxDraw) {
+	*error = BadAlloc;
+	return NULL;
+    }
 
     /* since we are creating the drawablePrivate, drawId should be new */
     if (!AddResource(drawId, __glXDrawableRes, pGlxDraw)) {
commit c3c976f54c3c282d6fa6c8360688e036bc43d210
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Jul 8 12:28:56 2013 -0400

    glx: Remove screen number from __GLXconfig
    
    Not used.  There's no real reason to match against this instead of
    matching against fbconfig or visual ID anyway.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/glx/glxscreens.h b/glx/glxscreens.h
index 19a2599..c8119fd 100644
--- a/glx/glxscreens.h
+++ b/glx/glxscreens.h
@@ -92,8 +92,6 @@ struct __GLXconfig {
     /* OML_swap_method */
     GLint swapMethod;
 
-    GLint screen;
-
     /* EXT_texture_from_pixmap */
     GLint bindToTextureRgb;
     GLint bindToTextureRgba;
commit 1d1484e9bd55d1fa8316b1574754f28d5d31a076
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Jul 8 12:09:13 2013 -0400

    glx: Remove pixmapMode from __GLXconfig
    
    This has never been filled in with anything meaningful afaict, and you
    can't get to it from the client in any event.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/glx/glxscreens.h b/glx/glxscreens.h
index 7a0a515..19a2599 100644
--- a/glx/glxscreens.h
+++ b/glx/glxscreens.h
@@ -54,8 +54,6 @@ struct __GLXconfig {
 
     GLint level;
 
-    GLint pixmapMode;
-
     /* GLX */
     GLint visualID;
     GLint visualType;     /**< One of the GLX X visual types. (i.e., 
diff --git a/hw/xquartz/GL/glcontextmodes.c b/hw/xquartz/GL/glcontextmodes.c
index dc97f89..1ce3570 100644
--- a/hw/xquartz/GL/glcontextmodes.c
+++ b/hw/xquartz/GL/glcontextmodes.c
@@ -555,7 +555,6 @@ _gl_context_modes_are_same(const __GLcontextModes * a,
             (a->stencilBits == b->stencilBits) &&
             (a->numAuxBuffers == b->numAuxBuffers) &&
             (a->level == b->level) &&
-            (a->pixmapMode == b->pixmapMode) &&
             (a->visualRating == b->visualRating) &&
 
             (a->transparentPixel == b->transparentPixel) &&
diff --git a/hw/xquartz/GL/visualConfigs.c b/hw/xquartz/GL/visualConfigs.c
index a00abf2..92142cb 100644
--- a/hw/xquartz/GL/visualConfigs.c
+++ b/hw/xquartz/GL/visualConfigs.c
@@ -144,7 +144,6 @@ __GLXconfig *__glXAquaCreateVisualConfigs(int *numConfigsPtr, int screenNumber)
 
                                         c->level = 0;
                                         c->indexBits = 0;
-                                        c->pixmapMode = 0; // TODO: What should this be?
 
                                         if(conf->accelerated) {
                                             c->visualRating = GLX_NONE;
diff --git a/hw/xwin/glx/indirect.c b/hw/xwin/glx/indirect.c
index 14a4711..02f9b0e 100644
--- a/hw/xwin/glx/indirect.c
+++ b/hw/xwin/glx/indirect.c
@@ -1715,7 +1715,6 @@ fbConfigToPixelFormat(__GLXconfig * mode, PIXELFORMATDESCRIPTOR * pfdret,
     pfd.cAuxBuffers = mode->numAuxBuffers;
 
     /* mode->level ? */
-    /* mode->pixmapMode ? */
 
     *pfdret = pfd;
 
@@ -1925,7 +1924,6 @@ glxWinCreateConfigs(HDC hdc, glxWinScreen * screen)
         // pfd.dwLayerMask; // ignored
         // pfd.dwDamageMask;  // ignored
 
-        c->base.pixmapMode = 0;
         c->base.visualID = -1;  // will be set by __glXScreenInit()
 
         /* EXT_visual_rating / GLX 1.2 */
@@ -2263,7 +2261,6 @@ glxWinCreateConfigsExt(HDC hdc, glxWinScreen * screen)
         }
         c->base.level = 0;
 
-        c->base.pixmapMode = 0; // ???
         c->base.visualID = -1;  // will be set by __glXScreenInit()
 
         /* EXT_visual_rating / GLX 1.2 */
commit 34e6e60105796ad015469c10921c5ff09acf7eb0
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 2 12:33:36 2013 -0400

    glx: Remove support for NV_vertex_program and NV_fragment_program
    
    Mesa doesn't implement these anymore, never really did outside of swrast
    anyway.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/glx/glxscreens.c b/glx/glxscreens.c
index 6a07af9..78769f4 100644
--- a/glx/glxscreens.c
+++ b/glx/glxscreens.c
@@ -128,7 +128,6 @@ static const char GLServerExtensions[] =
     "GL_NV_blend_square "
     "GL_NV_depth_clamp "
     "GL_NV_fog_distance "
-    "GL_NV_fragment_program "
     "GL_NV_fragment_program_option "
     "GL_NV_fragment_program2 "
     "GL_NV_light_max_exponent "
@@ -139,9 +138,6 @@ static const char GLServerExtensions[] =
     "GL_NV_texture_env_combine4 "
     "GL_NV_texture_expand_normal "
     "GL_NV_texture_rectangle "
-    "GL_NV_vertex_program "
-    "GL_NV_vertex_program1_1 "
-    "GL_NV_vertex_program2 "
     "GL_NV_vertex_program2_option "
     "GL_NV_vertex_program3 "
     "GL_OES_compressed_paletted_texture "
commit acf14c1de766c4ea206cd7ce7f25b780a589d33c
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 2 10:35:19 2013 -0400

    glx: realloc style fix in RenderLarge
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index b817e5a..9deadb7 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -2176,15 +2176,12 @@ __glXDisp_RenderLarge(__GLXclientState * cl, GLbyte * pc)
          ** Make enough space in the buffer, then copy the entire request.
          */
         if (cl->largeCmdBufSize < cmdlen) {
-            if (!cl->largeCmdBuf) {
-                cl->largeCmdBuf = (GLbyte *) malloc(cmdlen);
-            }
-            else {
-                cl->largeCmdBuf = (GLbyte *) realloc(cl->largeCmdBuf, cmdlen);
-            }
-            if (!cl->largeCmdBuf) {
-                return BadAlloc;
-            }
+	    GLbyte *newbuf = cl->largeCmdBuf;
+
+	    if (!(newbuf = realloc(newbuf, cmdlen)))
+		return BadAlloc;
+
+	    cl->largeCmdBuf = newbuf;
             cl->largeCmdBufSize = cmdlen;
         }
         memcpy(cl->largeCmdBuf, pc, dataBytes);
commit 9ebf739a6864c9ec38bf72f63ef2e3b9cd1951db
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 2 10:30:40 2013 -0400

    glx: Eliminate a small malloc from QueryContext
    
    No reason to have that be a failure path.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index 9426fc1..b817e5a 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -1687,15 +1687,14 @@ DoQueryContext(__GLXclientState * cl, GLXContextID gcId)
     ClientPtr client = cl->client;
     __GLXcontext *ctx;
     xGLXQueryContextInfoEXTReply reply;
-    int nProps;
-    int *sendBuf, *pSendBuf;
+    int nProps = 3;
+    int sendBuf[nProps * 2];
     int nReplyBytes;
     int err;
 
     if (!validGlxContext(cl->client, gcId, DixReadAccess, &ctx, &err))
         return err;
 
-    nProps = 3;
     reply = (xGLXQueryContextInfoEXTReply) {
         .type = X_Reply,
         .sequenceNumber = client->sequence,
@@ -1704,17 +1703,12 @@ DoQueryContext(__GLXclientState * cl, GLXContextID gcId)
     };
 
     nReplyBytes = reply.length << 2;
-    sendBuf = (int *) malloc((size_t) nReplyBytes);
-    if (sendBuf == NULL) {
-        return __glXError(GLXBadContext);       /* XXX: Is this correct? */
-    }
-    pSendBuf = sendBuf;
-    *pSendBuf++ = GLX_SHARE_CONTEXT_EXT;
-    *pSendBuf++ = (int) (ctx->share_id);
-    *pSendBuf++ = GLX_VISUAL_ID_EXT;
-    *pSendBuf++ = (int) (ctx->config->visualID);
-    *pSendBuf++ = GLX_SCREEN_EXT;
-    *pSendBuf++ = (int) (ctx->pGlxScreen->pScreen->myNum);
+    sendBuf[0] = GLX_SHARE_CONTEXT_EXT;
+    sendBuf[1] = (int) (ctx->share_id);
+    sendBuf[2] = GLX_VISUAL_ID_EXT;
+    sendBuf[3] = (int) (ctx->config->visualID);
+    sendBuf[4] = GLX_SCREEN_EXT;
+    sendBuf[5] = (int) (ctx->pGlxScreen->pScreen->myNum);
 
     if (client->swapped) {
         __glXSwapQueryContextInfoEXTReply(client, &reply, sendBuf);
@@ -1723,7 +1717,6 @@ DoQueryContext(__GLXclientState * cl, GLXContextID gcId)
         WriteToClient(client, sz_xGLXQueryContextInfoEXTReply, &reply);
         WriteToClient(client, nReplyBytes, sendBuf);
     }
-    free((char *) sendBuf);
 
     return Success;
 }
commit b99f7975407f111b99d772cd28224d7dc1b34fe4
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Nov 9 18:05:27 2012 -0500

    glx: Handle failure to create the pixmap backing the pbuffer
    
    We happen not to sanitize the width/height we pass to CreatePixmap here,
    oops.  It's not exploitable, but it's certainly a crash, so let's just
    throw BadAlloc instead.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index 27a68aa..9426fc1 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -1416,6 +1416,8 @@ DoCreatePbuffer(ClientPtr client, int screenNum, XID fbconfigId,
                                                     width, height,
                                                     config->rgbBits, 0);
     __glXleaveServer(GL_FALSE);
+    if (!pPixmap)
+        return BadAlloc;
 
     /* Assign the pixmap the same id as the pbuffer and add it as a
      * resource so it and the DRI2 drawable will be reclaimed when the
commit 22fbfdcb31f335c22053a0e29f0e73c03cd70a76
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Nov 9 17:52:12 2012 -0500

    glx: Implement GLX_PRESERVED_CONTENTS drawable attribute
    
    We back pixmaps with pbuffers so they're never actually clobbered.  Say
    so when asked.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index 553b3b6..27a68aa 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -1457,7 +1457,6 @@ __glXDisp_CreatePbuffer(__GLXclientState * cl, GLbyte * pc)
             height = attrs[i * 2 + 1];
             break;
         case GLX_LARGEST_PBUFFER:
-        case GLX_PRESERVED_CONTENTS:
             /* FIXME: huh... */
             break;
         }
@@ -1475,6 +1474,10 @@ __glXDisp_CreateGLXPbufferSGIX(__GLXclientState * cl, GLbyte * pc)
 
     REQUEST_AT_LEAST_SIZE(xGLXCreateGLXPbufferSGIXReq);
 
+    /*
+     * We should really handle attributes correctly, but this extension
+     * is so rare I have difficulty caring.
+     */
     return DoCreatePbuffer(cl->client, req->screen, req->fbconfig,
                            req->width, req->height, req->pbuffer);
 }
@@ -1892,7 +1895,7 @@ DoGetDrawableAttributes(__GLXclientState * cl, XID drawId)
     ClientPtr client = cl->client;
     xGLXGetDrawableAttributesReply reply;
     __GLXdrawable *pGlxDraw;
-    CARD32 attributes[12];
+    CARD32 attributes[14];
     int numAttribs = 0, error;
 
     if (!validGlxDrawable(client, drawId, GLX_DRAWABLE_ANY,
@@ -1918,6 +1921,11 @@ DoGetDrawableAttributes(__GLXclientState * cl, XID drawId)
     attributes[10] = GLX_FBCONFIG_ID;
     attributes[11] = pGlxDraw->config->fbconfigID;
     numAttribs++;
+    if (pGlxDraw->type == GLX_DRAWABLE_PBUFFER) {
+        attributes[12] = GLX_PRESERVED_CONTENTS;
+        attributes[13] = GL_TRUE;
+        numAttribs++;
+    }
 
     reply = (xGLXGetDrawableAttributesReply) {
         .type = X_Reply,
commit 2e20b8382cdf37ae5a2802f85b8f06a370f9645d
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Nov 9 17:12:49 2012 -0500

    glx: Implement GLX_FBCONFIG_ID in GetDrawableAttributes
    
    Required by GLX 1.4, section 3.3.6, "Querying Attributes".
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index 4a343a6..553b3b6 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -1892,7 +1892,7 @@ DoGetDrawableAttributes(__GLXclientState * cl, XID drawId)
     ClientPtr client = cl->client;
     xGLXGetDrawableAttributesReply reply;
     __GLXdrawable *pGlxDraw;
-    CARD32 attributes[10];
+    CARD32 attributes[12];
     int numAttribs = 0, error;
 
     if (!validGlxDrawable(client, drawId, GLX_DRAWABLE_ANY,
@@ -1915,6 +1915,9 @@ DoGetDrawableAttributes(__GLXclientState * cl, XID drawId)
     attributes[8] = GLX_HEIGHT;
     attributes[9] = pGlxDraw->pDraw->height;
     numAttribs++;
+    attributes[10] = GLX_FBCONFIG_ID;
+    attributes[11] = pGlxDraw->config->fbconfigID;
+    numAttribs++;
 
     reply = (xGLXGetDrawableAttributesReply) {
         .type = X_Reply,
commit 0d76191baeee005982754ac18ca995742e32d8c1
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Nov 9 17:10:57 2012 -0500

    glx: Implement GLX_{WIDTH,HEIGHT} in GetDrawableAttributes
    
    Required by GLX 1.4, section 3.3.6, "Querying Attributes".
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index cecbf7b..4a343a6 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -1892,7 +1892,7 @@ DoGetDrawableAttributes(__GLXclientState * cl, XID drawId)
     ClientPtr client = cl->client;
     xGLXGetDrawableAttributesReply reply;
     __GLXdrawable *pGlxDraw;
-    CARD32 attributes[6];
+    CARD32 attributes[10];
     int numAttribs = 0, error;
 
     if (!validGlxDrawable(client, drawId, GLX_DRAWABLE_ANY,
@@ -1909,6 +1909,12 @@ DoGetDrawableAttributes(__GLXclientState * cl, XID drawId)
     attributes[4] = GLX_EVENT_MASK;
     attributes[5] = pGlxDraw->eventMask;
     numAttribs++;
+    attributes[6] = GLX_WIDTH;
+    attributes[7] = pGlxDraw->pDraw->width;
+    numAttribs++;
+    attributes[8] = GLX_HEIGHT;
+    attributes[9] = pGlxDraw->pDraw->height;
+    numAttribs++;
 
     reply = (xGLXGetDrawableAttributesReply) {
         .type = X_Reply,
commit d11f13e383dda1e9cabe32793d261d46edc44418
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Nov 9 17:07:20 2012 -0500

    glx: Compute number of attributes in GetDrawableAttributes on the fly
    
    This doesn't have any effect yet, but is needed to properly build the
    reply for pbuffers.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index cbbdae8..cecbf7b 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -1893,27 +1893,29 @@ DoGetDrawableAttributes(__GLXclientState * cl, XID drawId)
     xGLXGetDrawableAttributesReply reply;
     __GLXdrawable *pGlxDraw;
     CARD32 attributes[6];
-    int numAttribs, error;
+    int numAttribs = 0, error;
 
     if (!validGlxDrawable(client, drawId, GLX_DRAWABLE_ANY,
                           DixGetAttrAccess, &pGlxDraw, &error))
         return error;
 
-    numAttribs = 3;
-    reply = (xGLXGetDrawableAttributesReply) {
-        .type = X_Reply,
-        .sequenceNumber = client->sequence,
-        .length = numAttribs << 1,
-        .numAttribs = numAttribs
-    };
-
     attributes[0] = GLX_TEXTURE_TARGET_EXT;
     attributes[1] = pGlxDraw->target == GL_TEXTURE_2D ? GLX_TEXTURE_2D_EXT :
         GLX_TEXTURE_RECTANGLE_EXT;
+    numAttribs++;
     attributes[2] = GLX_Y_INVERTED_EXT;
     attributes[3] = GL_FALSE;
+    numAttribs++;
     attributes[4] = GLX_EVENT_MASK;
     attributes[5] = pGlxDraw->eventMask;
+    numAttribs++;
+
+    reply = (xGLXGetDrawableAttributesReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = numAttribs << 1,
+        .numAttribs = numAttribs
+    };
 
     if (client->swapped) {
         __glXSwapGetDrawableAttributesReply(client, &reply, attributes);
commit 468b57324f838144d79e3a9d85a0bde853578c4b
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Nov 9 16:48:16 2012 -0500

    glx: Style fixes
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/glx/glxscreens.c b/glx/glxscreens.c
index 3724d19..6a07af9 100644
--- a/glx/glxscreens.c
+++ b/glx/glxscreens.c
@@ -154,7 +154,9 @@ static const char GLServerExtensions[] =
     "GL_SGIS_texture_edge_clamp "
     "GL_SGIS_texture_lod "
     "GL_SGIX_depth_texture "
-    "GL_SGIX_shadow " "GL_SGIX_shadow_ambient " "GL_SUN_slice_accum ";
+    "GL_SGIX_shadow "
+    "GL_SGIX_shadow_ambient "
+    "GL_SUN_slice_accum ";
 
 /*
 ** We have made the simplifying assuption that the same extensions are 
@@ -168,12 +170,14 @@ static char GLXServerExtensions[] =
     "GLX_EXT_visual_rating "
     "GLX_EXT_import_context "
     "GLX_EXT_texture_from_pixmap "
-    "GLX_OML_swap_method " "GLX_SGI_make_current_read "
+    "GLX_OML_swap_method "
+    "GLX_SGI_make_current_read "
 #ifndef __APPLE__
     "GLX_SGIS_multisample "
 #endif
     "GLX_SGIX_fbconfig "
-    "GLX_SGIX_pbuffer " "GLX_MESA_copy_sub_buffer ";
+    "GLX_SGIX_pbuffer "
+    "GLX_MESA_copy_sub_buffer ";
 
 static Bool
 glxCloseScreen(ScreenPtr pScreen)
commit 2b181ad0952851f47f23dcb1a36471685313c13e
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Nov 9 16:33:54 2012 -0500

    glx: Pull GLX vendor string out of __GLXscreen
    
    Given how we're currently implementing GLX this can't meaningfully vary
    per-screen.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index 5b7a628..cbbdae8 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -50,6 +50,8 @@
 #include "indirect_table.h"
 #include "indirect_util.h"
 
+static char GLXServerVendorName[] = "SGI";
+
 _X_HIDDEN int
 validGlxScreen(ClientPtr client, int screen, __GLXscreen ** pGlxScreen,
                int *err)
@@ -2384,7 +2386,7 @@ __glXDisp_QueryServerString(__GLXclientState * cl, GLbyte * pc)
 
     switch (req->name) {
     case GLX_VENDOR:
-        ptr = pGlxScreen->GLXvendor;
+        ptr = GLXServerVendorName;
         break;
     case GLX_VERSION:
         /* Return to the server version rather than the screen version
diff --git a/glx/glxscreens.c b/glx/glxscreens.c
index 61d590c..3724d19 100644
--- a/glx/glxscreens.c
+++ b/glx/glxscreens.c
@@ -160,7 +160,6 @@ static const char GLServerExtensions[] =
 ** We have made the simplifying assuption that the same extensions are 
 ** supported across all screens in a multi-screen system.
 */
-static char GLXServerVendorName[] = "SGI";
 unsigned glxMajorVersion = SERVER_GLX_MAJOR_VERSION;
 unsigned glxMinorVersion = SERVER_GLX_MINOR_VERSION;
 static char GLXServerExtensions[] =
@@ -330,7 +329,6 @@ __glXScreenInit(__GLXscreen * pGlxScreen, ScreenPtr pScreen)
 
     pGlxScreen->pScreen = pScreen;
     pGlxScreen->GLextensions = strdup(GLServerExtensions);
-    pGlxScreen->GLXvendor = strdup(GLXServerVendorName);
     pGlxScreen->GLXextensions = strdup(GLXServerExtensions);
 
     /* All GLX providers must support all of the functionality required for at
@@ -420,7 +418,6 @@ __glXScreenInit(__GLXscreen * pGlxScreen, ScreenPtr pScreen)
 void
 __glXScreenDestroy(__GLXscreen * screen)
 {
-    free(screen->GLXvendor);
     free(screen->GLXextensions);
     free(screen->GLextensions);
     free(screen->visuals);
diff --git a/glx/glxscreens.h b/glx/glxscreens.h
index 0a7b604..7a0a515 100644
--- a/glx/glxscreens.h
+++ b/glx/glxscreens.h
@@ -145,7 +145,6 @@ struct __GLXscreen {
 
     char *GLextensions;
 
-    char *GLXvendor;
     char *GLXextensions;
 
     /**
commit b9c489cf13e1ad35b7d9bea9de8d85e929374d17
Author: Adam Jackson <ajax at redhat.com>
Date:   Wed Oct 31 10:05:24 2012 -0400

    glx: Remove unused bits from the context struct
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/glx/glxcontext.h b/glx/glxcontext.h
index 4764e56..3d08c99 100644
--- a/glx/glxcontext.h
+++ b/glx/glxcontext.h
@@ -55,7 +55,6 @@ struct __GLXcontext {
     /*
      ** list of context structs
      */
-    __GLXcontext *last;
     __GLXcontext *next;
 
     /*
commit f579cc85c29f52b575c62e6ae1e16eb87c506bd3
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu Jul 4 10:08:40 2013 -0400

    glxproxy: Don't track GLCLientm{aj,in}orVersion
    
    Basically just a port of 62f06b0d to glxproxy.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/dmx/glxProxy/glxcmds.c b/hw/dmx/glxProxy/glxcmds.c
index 8cdb25e..335da37 100644
--- a/hw/dmx/glxProxy/glxcmds.c
+++ b/hw/dmx/glxProxy/glxcmds.c
@@ -2734,8 +2734,6 @@ __glXClientInfo(__GLXclientState * cl, GLbyte * pc)
     int to_screen = 0;
     int s;
 
-    cl->GLClientmajorVersion = req->major;
-    cl->GLClientminorVersion = req->minor;
     free(cl->GLClientextensions);
     buf = (const char *) (req + 1);
     cl->GLClientextensions = strdup(buf);
diff --git a/hw/dmx/glxProxy/glxext.c b/hw/dmx/glxProxy/glxext.c
index e72a040..b469708 100644
--- a/hw/dmx/glxProxy/glxext.c
+++ b/hw/dmx/glxProxy/glxext.c
@@ -88,12 +88,6 @@ ResetClientState(int clientIndex)
     memset(cl, 0, sizeof(__GLXclientState));
     cl->be_displays = keep_be_displays;
 
-    /*
-     ** By default, assume that the client supports
-     ** GLX major version 1 minor version 0 protocol.
-     */
-    cl->GLClientmajorVersion = 1;
-    cl->GLClientminorVersion = 0;
     free(cl->GLClientextensions);
 
     memset(cl->be_displays, 0, screenInfo.numScreens * sizeof(Display *));
diff --git a/hw/dmx/glxProxy/glxserver.h b/hw/dmx/glxProxy/glxserver.h
index ad94966..754ad30 100644
--- a/hw/dmx/glxProxy/glxserver.h
+++ b/hw/dmx/glxProxy/glxserver.h
@@ -119,8 +119,6 @@ struct __GLXclientStateRec {
     /* Back pointer to X client record */
     ClientPtr client;
 
-    int GLClientmajorVersion;
-    int GLClientminorVersion;
     char *GLClientextensions;
 
     GLXContextTag *be_currentCTag;
commit e549ffb5f19cf044bc3e2d368a6f081f8b84bfaa
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Oct 30 18:20:43 2012 -0400

    dmx/glx: Remove unused __glXNop
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/dmx/glxProxy/Makefile.am b/hw/dmx/glxProxy/Makefile.am
index 4ee1036..c3df169 100644
--- a/hw/dmx/glxProxy/Makefile.am
+++ b/hw/dmx/glxProxy/Makefile.am
@@ -22,7 +22,6 @@ libglxproxy_a_SOURCES = compsize.c \
                         glxsingle.h \
                         glxswap.c \
                         glxswap.h \
-                        glxutil.c \
                         glxutil.h \
                         glxvendor.c \
                         glxvendor.h \
diff --git a/hw/dmx/glxProxy/glxutil.c b/hw/dmx/glxProxy/glxutil.c
deleted file mode 100644
index f90dbf1..0000000
--- a/hw/dmx/glxProxy/glxutil.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
- * Copyright (C) 1991-2000 Silicon Graphics, 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, 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 including the dates of first publication and
- * either this permission notice or a reference to
- * http://oss.sgi.com/projects/FreeB/
- * 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
- * SILICON GRAPHICS, INC. 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.
- *
- * Except as contained in this notice, the name of Silicon Graphics, Inc.
- * shall not be used in advertising or otherwise to promote the sale, use or
- * other dealings in this Software without prior written authorization from
- * Silicon Graphics, Inc.
- */
-
-#include "glxserver.h"
-#include "glxutil.h"
-
-void
-__glXNop(void)
-{
-}
diff --git a/hw/dmx/glxProxy/glxutil.h b/hw/dmx/glxProxy/glxutil.h
index d3c7286..605c07b 100644
--- a/hw/dmx/glxProxy/glxutil.h
+++ b/hw/dmx/glxProxy/glxutil.h
@@ -31,8 +31,6 @@
  * Silicon Graphics, Inc.
  */
 
-extern void __glXNop(void);
-
 /* context helper routines */
 extern __GLXcontext *__glXLookupContextByTag(__GLXclientState *, GLXContextTag);
 extern DrawablePtr __glXLookupDrawableByTag(__GLXclientState * cl,
commit d962b8ed272d4a8921c0dadf16cd926484e30d10
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu Aug 22 16:42:23 2013 -0400

    damageext: Style fix
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/damageext/damageext.c b/damageext/damageext.c
index db0a753..01b88ef 100644
--- a/damageext/damageext.c
+++ b/damageext/damageext.c
@@ -306,11 +306,14 @@ static const int version_requests[] = {
 #define NUM_VERSION_REQUESTS	(sizeof (version_requests) / sizeof (version_requests[0]))
 
 static int (*ProcDamageVector[XDamageNumberRequests]) (ClientPtr) = {
-/*************** Version 1 ******************/
+    /*************** Version 1 ******************/
     ProcDamageQueryVersion,
-        ProcDamageCreate, ProcDamageDestroy, ProcDamageSubtract,
-/*************** Version 1.1 ****************/
-ProcDamageAdd,};
+    ProcDamageCreate,
+    ProcDamageDestroy,
+    ProcDamageSubtract,
+    /*************** Version 1.1 ****************/
+    ProcDamageAdd,
+};
 
 static int
 ProcDamageDispatch(ClientPtr client)
@@ -386,11 +389,14 @@ SProcDamageAdd(ClientPtr client)
 }
 
 static int (*SProcDamageVector[XDamageNumberRequests]) (ClientPtr) = {
-/*************** Version 1 ******************/
+    /*************** Version 1 ******************/
     SProcDamageQueryVersion,
-        SProcDamageCreate, SProcDamageDestroy, SProcDamageSubtract,
-/*************** Version 1.1 ****************/
-SProcDamageAdd,};
+    SProcDamageCreate,
+    SProcDamageDestroy,
+    SProcDamageSubtract,
+    /*************** Version 1.1 ****************/
+    SProcDamageAdd,
+};
 
 static int
 SProcDamageDispatch(ClientPtr client)
commit c90add0f1ce0c85aea7a60635de765848d778266
Author: Adam Jackson <ajax at redhat.com>
Date:   Wed Aug 21 11:57:24 2013 -0400

    damage: Remove "post-rendering" hooks
    
    This is a revert of 974db58f5b730c3770ee461665a02dd4334d1dea.  There are
    no consumers of this API, we must not need it.
    
    Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/miext/damage/damage.c b/miext/damage/damage.c
index 0fef53f..cc02991 100644
--- a/miext/damage/damage.c
+++ b/miext/damage/damage.c
@@ -119,51 +119,6 @@ getDrawableDamageRef(DrawablePtr pDrawable)
     DamagePtr	*pPrev = (DamagePtr *) \
 	dixLookupPrivateAddr(&(pWindow)->devPrivates, damageWinPrivateKey)
 
-static void
-damageReportDamagePostRendering(DamagePtr pDamage, RegionPtr pOldDamage,
-                                RegionPtr pDamageRegion)
-{
-    BoxRec tmpBox;
-    RegionRec tmpRegion, newDamage;
-    Bool was_empty;
-
-    RegionUnion(&newDamage, pOldDamage, pDamageRegion);
-
-    switch (pDamage->damageLevel) {
-    case DamageReportRawRegion:
-        (*pDamage->damageReportPostRendering) (pDamage, pDamageRegion,
-                                               pDamage->closure);
-        break;
-    case DamageReportDeltaRegion:
-        RegionNull(&tmpRegion);
-        RegionSubtract(&tmpRegion, pDamageRegion, pOldDamage);
-        if (RegionNotEmpty(&tmpRegion)) {
-            (*pDamage->damageReportPostRendering) (pDamage, &tmpRegion,
-                                                   pDamage->closure);
-        }
-        RegionUninit(&tmpRegion);
-        break;
-    case DamageReportBoundingBox:
-        tmpBox = *RegionExtents(pOldDamage);
-        if (!BOX_SAME(&tmpBox, RegionExtents(&newDamage))) {
-            (*pDamage->damageReportPostRendering) (pDamage, &newDamage,
-                                                   pDamage->closure);
-        }
-        break;
-    case DamageReportNonEmpty:
-        was_empty = !RegionNotEmpty(pOldDamage);
-        if (was_empty && RegionNotEmpty(&newDamage)) {
-            (*pDamage->damageReportPostRendering) (pDamage, &newDamage,
-                                                   pDamage->closure);
-        }
-        break;
-    case DamageReportNone:
-        break;
-    }
-
-    RegionUninit(&newDamage);
-}
-
 #if DAMAGE_DEBUG_ENABLE
 static void
 _damageRegionAppend(DrawablePtr pDrawable, RegionPtr pRegion, Bool clip,
@@ -299,14 +254,10 @@ damageRegionAppend(DrawablePtr pDrawable, RegionPtr pRegion, Bool clip,
             RegionTranslate(pDamageRegion, -draw_x, -draw_y);
 
         /* Store damage region if needed after submission. */
-        if (pDamage->reportAfter || pDamage->damageMarker)
+        if (pDamage->reportAfter)
             RegionUnion(&pDamage->pendingDamage,
                         &pDamage->pendingDamage, pDamageRegion);
 
-        /* Duplicate current damage if needed. */
-        if (pDamage->damageMarker)
-            RegionCopy(&pDamage->backupDamage, &pDamage->damage);
-
         /* Report damage now, if desired. */
         if (!pDamage->reportAfter) {
             if (pDamage->damageReport)
@@ -335,12 +286,6 @@ damageRegionProcessPending(DrawablePtr pDrawable)
     drawableDamage(pDrawable);
 
     for (; pDamage != NULL; pDamage = pDamage->pNext) {
-        /* submit damage marker whenever possible. */
-        if (pDamage->damageMarker)
-            (*pDamage->damageMarker) (pDrawable, pDamage,
-                                      &pDamage->backupDamage,
-                                      &pDamage->pendingDamage,
-                                      pDamage->closure);
         if (pDamage->reportAfter) {
             /* It's possible that there is only interest in postRendering reporting. */
             if (pDamage->damageReport)
@@ -350,10 +295,8 @@ damageRegionProcessPending(DrawablePtr pDrawable)
                             &pDamage->pendingDamage);
         }
 
-        if (pDamage->reportAfter || pDamage->damageMarker)
+        if (pDamage->reportAfter)
             RegionEmpty(&pDamage->pendingDamage);
-        if (pDamage->damageMarker)
-            RegionEmpty(&pDamage->backupDamage);
     }
 
 }
@@ -1762,9 +1705,7 @@ DamageCreate(DamageReportFunc damageReport,
     pDamage->reportAfter = FALSE;
 
     pDamage->damageReport = damageReport;
-    pDamage->damageReportPostRendering = NULL;
     pDamage->damageDestroy = damageDestroy;
-    pDamage->damageMarker = NULL;
     pDamage->pScreen = pScreen;
 
     (*pScrPriv->funcs.Create) (pDamage);
@@ -1936,17 +1877,6 @@ DamageRegionProcessPending(DrawablePtr pDrawable)
     damageRegionProcessPending(pDrawable);
 }
 
-/* If a damage marker is provided, then this function must be called after rendering is done. */
-/* Please do call back so any future enhancements can assume this function is called. */
-/* There are no strict timing requirements for calling this function, just as soon as (is cheaply) possible. */
-void
-DamageRegionRendered(DrawablePtr pDrawable, DamagePtr pDamage,
-                     RegionPtr pOldDamage, RegionPtr pRegion)
-{
-    if (pDamage->damageReportPostRendering)
-        damageReportDamagePostRendering(pDamage, pOldDamage, pRegion);
-}
-
 /* This call is very odd, i'm leaving it intact for API sake, but please don't use it. */
 void
 DamageDamageRegion(DrawablePtr pDrawable, RegionPtr pRegion)
@@ -1966,15 +1896,6 @@ DamageSetReportAfterOp(DamagePtr pDamage, Bool reportAfter)
     pDamage->reportAfter = reportAfter;
 }
 
-void
-DamageSetPostRenderingFunctions(DamagePtr pDamage,
-                                DamageReportFunc damageReportPostRendering,
-                                DamageMarkerFunc damageMarker)
-{
-    pDamage->damageReportPostRendering = damageReportPostRendering;
-    pDamage->damageMarker = damageMarker;
-}
-
 DamageScreenFuncsPtr
 DamageGetScreenFuncs(ScreenPtr pScreen)
 {
diff --git a/miext/damage/damage.h b/miext/damage/damage.h
index e5d6913..525b2db 100644
--- a/miext/damage/damage.h
+++ b/miext/damage/damage.h
@@ -41,12 +41,6 @@ typedef void (*DamageReportFunc) (DamagePtr pDamage, RegionPtr pRegion,
                                   void *closure);
 typedef void (*DamageDestroyFunc) (DamagePtr pDamage, void *closure);
 
-/* It's the responsibility of the driver to duplicate both regions. */
-/* At some point DamageRegionRendered() must be called. */
-typedef void (*DamageMarkerFunc) (DrawablePtr pDrawable, DamagePtr pDamage,
-                                  RegionPtr pOldDamage, RegionPtr pRegion,
-                                  void *closure);
-
 typedef void (*DamageScreenCreateFunc) (DamagePtr);
 typedef void (*DamageScreenRegisterFunc) (DrawablePtr, DamagePtr);
 typedef void (*DamageScreenUnregisterFunc) (DrawablePtr, DamagePtr);
@@ -105,12 +99,6 @@ extern _X_EXPORT void
 extern _X_EXPORT void
  DamageRegionProcessPending(DrawablePtr pDrawable);
 
-/* Call this some time after rendering is done, only relevant when a damageMarker is provided. */
-extern _X_EXPORT void
-
-DamageRegionRendered(DrawablePtr pDrawable, DamagePtr pDamage,
-                     RegionPtr pOldDamage, RegionPtr pRegion);
-
 /* Call this when you create a new Damage and you wish to send an initial damage message (to it). */
 extern _X_EXPORT void
  DamageReportDamage(DamagePtr pDamage, RegionPtr pDamageRegion);
@@ -122,12 +110,6 @@ extern _X_EXPORT void
 extern _X_EXPORT void
  DamageSetReportAfterOp(DamagePtr pDamage, Bool reportAfter);
 
-extern _X_EXPORT void
-
-DamageSetPostRenderingFunctions(DamagePtr pDamage,
-                                DamageReportFunc damageReportPostRendering,
-                                DamageMarkerFunc damageMarker);
-
 extern _X_EXPORT DamageScreenFuncsPtr DamageGetScreenFuncs(ScreenPtr);
 
 #endif                          /* _DAMAGE_H_ */
diff --git a/miext/damage/damagestr.h b/miext/damage/damagestr.h
index 8918990..36753ee 100644
--- a/miext/damage/damagestr.h
+++ b/miext/damage/damagestr.h
@@ -44,13 +44,10 @@ typedef struct _damage {
     DrawablePtr pDrawable;
 
     DamageReportFunc damageReport;
-    DamageReportFunc damageReportPostRendering;
     DamageDestroyFunc damageDestroy;
-    DamageMarkerFunc damageMarker;
 
     Bool reportAfter;
     RegionRec pendingDamage;    /* will be flushed post submission at the latest */
-    RegionRec backupDamage;     /* for use with damageMarker */
     ScreenPtr pScreen;
     PrivateRec *devPrivates;
 } DamageRec;
commit 0f3f8e4295d4c05f33b93e0ffd2f6f8cd5759bf7
Author: Adam Jackson <ajax at redhat.com>
Date:   Wed Aug 21 11:13:11 2013 -0400

    damage: Don't rewrite Text ops to GlyphBlt ops
    
    There's no particularly good reason to, and it breaks Xnest.
    
    Bugzilla: http://bugs.freedesktop.org/2454
    Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/miext/damage/damage.c b/miext/damage/damage.c
index 2b9c350..0fef53f 100644
--- a/miext/damage/damage.c
+++ b/miext/damage/damage.c
@@ -1336,7 +1336,7 @@ damageDamageChars(DrawablePtr pDrawable,
 #define TT_POLY16  2
 #define TT_IMAGE16 3
 
-static int
+static void
 damageText(DrawablePtr pDrawable,
            GCPtr pGC,
            int x,
@@ -1345,39 +1345,29 @@ damageText(DrawablePtr pDrawable,
            char *chars, FontEncoding fontEncoding, Bool textType)
 {
     CharInfoPtr *charinfo;
-    CharInfoPtr *info;
     unsigned long i;
     unsigned int n;
-    int w;
     Bool imageblt;
 
     imageblt = (textType == TT_IMAGE8) || (textType == TT_IMAGE16);
 
+    if (!checkGCDamage(pDrawable, pGC))
+        return;
+
     charinfo = malloc(count * sizeof(CharInfoPtr));
     if (!charinfo)
-        return x;
+        return;
 
     GetGlyphs(pGC->font, count, (unsigned char *) chars,
               fontEncoding, &i, charinfo);
     n = (unsigned int) i;
-    w = 0;
-    if (!imageblt)
-        for (info = charinfo; i--; info++)
-            w += (*info)->metrics.characterWidth;
 
     if (n != 0) {
         damageDamageChars(pDrawable, pGC->font, x + pDrawable->x,
                           y + pDrawable->y, n, charinfo, imageblt,
                           pGC->subWindowMode);
-        if (imageblt)
-            (*pGC->ops->ImageGlyphBlt) (pDrawable, pGC, x, y, n, charinfo,
-                                        FONTGLYPHS(pGC->font));
-        else
-            (*pGC->ops->PolyGlyphBlt) (pDrawable, pGC, x, y, n, charinfo,
-                                       FONTGLYPHS(pGC->font));
     }
     free(charinfo);
-    return x + w;
 }
 
 static int
@@ -1385,12 +1375,9 @@ damagePolyText8(DrawablePtr pDrawable,
                 GCPtr pGC, int x, int y, int count, char *chars)
 {
     DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable);
-
-    if (checkGCDamage(pDrawable, pGC))
-        x = damageText(pDrawable, pGC, x, y, (unsigned long) count, chars,
-                       Linear8Bit, TT_POLY8);
-    else
-        x = (*pGC->ops->PolyText8) (pDrawable, pGC, x, y, count, chars);
+    damageText(pDrawable, pGC, x, y, (unsigned long) count, chars, Linear8Bit,
+               TT_POLY8);
+    x = (*pGC->ops->PolyText8) (pDrawable, pGC, x, y, count, chars);
     damageRegionProcessPending(pDrawable);
     DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable);
     return x;
@@ -1401,14 +1388,10 @@ damagePolyText16(DrawablePtr pDrawable,
                  GCPtr pGC, int x, int y, int count, unsigned short *chars)
 {
     DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable);
-
-    if (checkGCDamage(pDrawable, pGC))
-        x = damageText(pDrawable, pGC, x, y, (unsigned long) count,
-                       (char *) chars,
-                       FONTLASTROW(pGC->font) == 0 ? Linear16Bit : TwoD16Bit,
-                       TT_POLY16);
-    else
-        x = (*pGC->ops->PolyText16) (pDrawable, pGC, x, y, count, chars);
+    damageText(pDrawable, pGC, x, y, (unsigned long) count, (char *) chars,
+               FONTLASTROW(pGC->font) == 0 ? Linear16Bit : TwoD16Bit,
+               TT_POLY16);
+    x = (*pGC->ops->PolyText16) (pDrawable, pGC, x, y, count, chars);
     damageRegionProcessPending(pDrawable);
     DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable);
     return x;
@@ -1419,12 +1402,9 @@ damageImageText8(DrawablePtr pDrawable,
                  GCPtr pGC, int x, int y, int count, char *chars)
 {
     DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable);
-
-    if (checkGCDamage(pDrawable, pGC))
-        damageText(pDrawable, pGC, x, y, (unsigned long) count, chars,
-                   Linear8Bit, TT_IMAGE8);
-    else
-        (*pGC->ops->ImageText8) (pDrawable, pGC, x, y, count, chars);
+    damageText(pDrawable, pGC, x, y, (unsigned long) count, chars, Linear8Bit,
+               TT_IMAGE8);
+    (*pGC->ops->ImageText8) (pDrawable, pGC, x, y, count, chars);
     damageRegionProcessPending(pDrawable);
     DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable);
 }
@@ -1434,13 +1414,10 @@ damageImageText16(DrawablePtr pDrawable,
                   GCPtr pGC, int x, int y, int count, unsigned short *chars)
 {
     DAMAGE_GC_OP_PROLOGUE(pGC, pDrawable);
-
-    if (checkGCDamage(pDrawable, pGC))
-        damageText(pDrawable, pGC, x, y, (unsigned long) count, (char *) chars,
-                   FONTLASTROW(pGC->font) == 0 ? Linear16Bit : TwoD16Bit,
-                   TT_IMAGE16);
-    else
-        (*pGC->ops->ImageText16) (pDrawable, pGC, x, y, count, chars);
+    damageText(pDrawable, pGC, x, y, (unsigned long) count, (char *) chars,
+               FONTLASTROW(pGC->font) == 0 ? Linear16Bit : TwoD16Bit,
+               TT_IMAGE16);
+    (*pGC->ops->ImageText16) (pDrawable, pGC, x, y, count, chars);
     damageRegionProcessPending(pDrawable);
     DAMAGE_GC_OP_EPILOGUE(pGC, pDrawable);
 }
commit d08966227e7d567df8d26eebc80f35f886e59a4a
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Aug 26 14:03:51 2013 -0400

    damage: Simplify DamageUnregister
    
    You can only register one drawable on a given damage, so there's no
    reason to require the caller to specify the drawable, the damage is
    enough.  The implementation would do something fairly horrible if you
    _did_ pass mismatched drawable and damage, so let's avoid the problem
    entirely.
    
    v2: Simplify xf86RotateDestroy even more [anholt]
    
    Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/composite/compalloc.c b/composite/compalloc.c
index cc69c68..b7d731e 100644
--- a/composite/compalloc.c
+++ b/composite/compalloc.c
@@ -205,7 +205,7 @@ compRedirectWindow(ClientPtr pClient, WindowPtr pWin, int update)
             anyMarked = compMarkWindows(pWin, &pLayerWin);
 
         if (cw->damageRegistered) {
-            DamageUnregister(&pWin->drawable, cw->damage);
+            DamageUnregister(cw->damage);
             cw->damageRegistered = FALSE;
         }
         cw->update = CompositeRedirectManual;
@@ -638,7 +638,7 @@ compSetParentPixmap(WindowPtr pWin)
     CompWindowPtr cw = GetCompWindow(pWin);
 
     if (cw->damageRegistered) {
-        DamageUnregister(&pWin->drawable, cw->damage);
+        DamageUnregister(cw->damage);
         cw->damageRegistered = FALSE;
         DamageEmpty(cw->damage);
     }
diff --git a/hw/xfree86/modes/xf86Rotate.c b/hw/xfree86/modes/xf86Rotate.c
index a393747..495af9b 100644
--- a/hw/xfree86/modes/xf86Rotate.c
+++ b/hw/xfree86/modes/xf86Rotate.c
@@ -272,14 +272,10 @@ xf86RotateDestroy(xf86CrtcPtr crtc)
             screenDrawable = &pScreen->root->drawable;
         /* Free damage structure */
         if (xf86_config->rotation_damage_registered) {
-            if (screenDrawable)
-                DamageUnregister(screenDrawable,
-                        xf86_config->rotation_damage);
             xf86_config->rotation_damage_registered = FALSE;
             DisableLimitedSchedulingLatency();
         }
-        if (screenDrawable)
-            DamageDestroy(xf86_config->rotation_damage);
+        DamageDestroy(xf86_config->rotation_damage);
         xf86_config->rotation_damage = NULL;
     }
 }
diff --git a/mi/misprite.c b/mi/misprite.c
index 8163f5b..85ca022 100644
--- a/mi/misprite.c
+++ b/mi/misprite.c
@@ -146,8 +146,7 @@ static void
 miSpriteDisableDamage(ScreenPtr pScreen, miSpriteScreenPtr pScreenPriv)
 {
     if (pScreenPriv->damageRegistered) {
-        DamageUnregister(&(pScreen->GetScreenPixmap(pScreen)->drawable),
-                         pScreenPriv->pDamage);
+        DamageUnregister(pScreenPriv->pDamage);
         pScreenPriv->damageRegistered = 0;
     }
 }
diff --git a/miext/damage/damage.c b/miext/damage/damage.c
index cf4b61a..2b9c350 100644
--- a/miext/damage/damage.c
+++ b/miext/damage/damage.c
@@ -1843,8 +1843,9 @@ DamageDrawInternal(ScreenPtr pScreen, Bool enable)
 }
 
 void
-DamageUnregister(DrawablePtr pDrawable, DamagePtr pDamage)
+DamageUnregister(DamagePtr pDamage)
 {
+    DrawablePtr pDrawable = pDamage->pDrawable;
     ScreenPtr pScreen = pDrawable->pScreen;
 
     damageScrPriv(pScreen);
@@ -1888,7 +1889,7 @@ DamageDestroy(DamagePtr pDamage)
     damageScrPriv(pScreen);
 
     if (pDamage->pDrawable)
-        DamageUnregister(pDamage->pDrawable, pDamage);
+        DamageUnregister(pDamage);
 
     if (pDamage->damageDestroy)
         (*pDamage->damageDestroy) (pDamage, pDamage->closure);
diff --git a/miext/damage/damage.h b/miext/damage/damage.h
index c2c313a..e5d6913 100644
--- a/miext/damage/damage.h
+++ b/miext/damage/damage.h
@@ -80,7 +80,7 @@ extern _X_EXPORT void
  DamageRegister(DrawablePtr pDrawable, DamagePtr pDamage);
 
 extern _X_EXPORT void
- DamageUnregister(DrawablePtr pDrawable, DamagePtr pDamage);
+ DamageUnregister(DamagePtr pDamage);
 
 extern _X_EXPORT void
  DamageDestroy(DamagePtr pDamage);
diff --git a/miext/shadow/shadow.c b/miext/shadow/shadow.c
index 2d869e5..1a9088c 100644
--- a/miext/shadow/shadow.c
+++ b/miext/shadow/shadow.c
@@ -219,7 +219,7 @@ shadowRemove(ScreenPtr pScreen, PixmapPtr pPixmap)
     shadowBuf(pScreen);
 
     if (pBuf->pPixmap) {
-        DamageUnregister(&pBuf->pPixmap->drawable, pBuf->pDamage);
+        DamageUnregister(pBuf->pDamage);
         pBuf->update = 0;
         pBuf->window = 0;
         pBuf->randr = 0;
commit 28708a045de7d9043d20fb06b61c44a46eb5526b
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Aug 26 13:52:14 2013 -0400

    damage: Implicitly unregister on destroy
    
    There's no reason not to, and it simplifies quite a few callers.
    
    Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/damageext/damageext.c b/damageext/damageext.c
index e02a28f..db0a753 100644
--- a/damageext/damageext.c
+++ b/damageext/damageext.c
@@ -429,7 +429,6 @@ FreeDamageExt(pointer value, XID did)
      */
     pDamageExt->id = 0;
     if (pDamageExt->pDamage) {
-        DamageUnregister(pDamageExt->pDrawable, pDamageExt->pDamage);
         DamageDestroy(pDamageExt->pDamage);
     }
     free(pDamageExt);
diff --git a/dix/pixmap.c b/dix/pixmap.c
index fe92147..d5dc383 100644
--- a/dix/pixmap.c
+++ b/dix/pixmap.c
@@ -202,7 +202,6 @@ PixmapStopDirtyTracking(PixmapPtr src, PixmapPtr slave_dst)
 
     xorg_list_for_each_entry_safe(ent, safe, &screen->pixmap_dirty_list, ent) {
         if (ent->src == src && ent->slave_dst == slave_dst) {
-            DamageUnregister(&src->drawable, ent->damage);
             DamageDestroy(ent->damage);
             xorg_list_del(&ent->ent);
             free(ent);
diff --git a/exa/exa_classic.c b/exa/exa_classic.c
index 1fa534b..0fa422f 100644
--- a/exa/exa_classic.c
+++ b/exa/exa_classic.c
@@ -192,7 +192,6 @@ exaModifyPixmapHeader_classic(PixmapPtr pPixmap, int width, int height,
          * gpu memory, so there's no need to track damage.
          */
         if (pExaPixmap->pDamage) {
-            DamageUnregister(&pPixmap->drawable, pExaPixmap->pDamage);
             DamageDestroy(pExaPixmap->pDamage);
             pExaPixmap->pDamage = NULL;
         }
diff --git a/exa/exa_migration_mixed.c b/exa/exa_migration_mixed.c
index 445c4fc..5e0bf15 100644
--- a/exa/exa_migration_mixed.c
+++ b/exa/exa_migration_mixed.c
@@ -190,7 +190,6 @@ exaPrepareAccessReg_mixed(PixmapPtr pPixmap, int index, RegionPtr pReg)
              * copy anymore. Drivers that prefer DFS, should fail prepare
              * access.
              */
-            DamageUnregister(&pPixmap->drawable, pExaPixmap->pDamage);
             DamageDestroy(pExaPixmap->pDamage);
             pExaPixmap->pDamage = NULL;
 
diff --git a/exa/exa_mixed.c b/exa/exa_mixed.c
index 0fb4091..3e2dcf2 100644
--- a/exa/exa_mixed.c
+++ b/exa/exa_mixed.c
@@ -139,7 +139,6 @@ exaModifyPixmapHeader_mixed(PixmapPtr pPixmap, int width, int height, int depth,
     if (pPixData) {
         if (pExaPixmap->driverPriv) {
             if (pExaPixmap->pDamage) {
-                DamageUnregister(&pPixmap->drawable, pExaPixmap->pDamage);
                 DamageDestroy(pExaPixmap->pDamage);
                 pExaPixmap->pDamage = NULL;
             }
@@ -189,7 +188,6 @@ exaModifyPixmapHeader_mixed(PixmapPtr pPixmap, int width, int height, int depth,
             if (pExaPixmap->sys_ptr) {
                 free(pExaPixmap->sys_ptr);
                 pExaPixmap->sys_ptr = NULL;
-                DamageUnregister(&pPixmap->drawable, pExaPixmap->pDamage);
                 DamageDestroy(pExaPixmap->pDamage);
                 pExaPixmap->pDamage = NULL;
                 RegionEmpty(&pExaPixmap->validSys);
diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index 0ee2cf3..db08e98 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -389,10 +389,7 @@ ephyrUnsetInternalDamage(ScreenPtr pScreen)
     KdScreenPriv(pScreen);
     KdScreenInfo *screen = pScreenPriv->screen;
     EphyrScrPriv *scrpriv = screen->driver;
-    PixmapPtr pPixmap = NULL;
 
-    pPixmap = (*pScreen->GetScreenPixmap) (pScreen);
-    DamageUnregister(&pPixmap->drawable, scrpriv->pDamage);
     DamageDestroy(scrpriv->pDamage);
 
     RemoveBlockAndWakeupHandlers(ephyrInternalDamageBlockHandler,
diff --git a/miext/damage/damage.c b/miext/damage/damage.c
index a98c20e..cf4b61a 100644
--- a/miext/damage/damage.c
+++ b/miext/damage/damage.c
@@ -1637,7 +1637,6 @@ damageDestroyWindow(WindowPtr pWindow)
     damageScrPriv(pScreen);
 
     while ((pDamage = damageGetWinPriv(pWindow))) {
-        DamageUnregister(&pWindow->drawable, pDamage);
         DamageDestroy(pDamage);
     }
     unwrap(pScrPriv, pScreen, DestroyWindow);
@@ -1888,6 +1887,9 @@ DamageDestroy(DamagePtr pDamage)
 
     damageScrPriv(pScreen);
 
+    if (pDamage->pDrawable)
+        DamageUnregister(pDamage->pDrawable, pDamage);
+
     if (pDamage->damageDestroy)
         (*pDamage->damageDestroy) (pDamage, pDamage->closure);
     (*pScrPriv->funcs.Destroy) (pDamage);
commit e657635dbe6b92875b0e88370557c2cbab673a49
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu Oct 18 14:24:23 2012 -0400

    fb: Remove unused compatibility wrappers
    
    Originally added in early 2009, not being used elsewhere anymore.
    
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/fb/fb.h b/fb/fb.h
index b869d12..26957df 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -1111,17 +1111,6 @@ fbInitVisuals(VisualPtr * visualp,
  * fbcopy.c
  */
 
-/* Compatibility definition, to be removed at next ABI change. */
-typedef void (*fbCopyProc) (DrawablePtr pSrcDrawable,
-                            DrawablePtr pDstDrawable,
-                            GCPtr pGC,
-                            BoxPtr pDstBox,
-                            int nbox,
-                            int dx,
-                            int dy,
-                            Bool reverse,
-                            Bool upsidedown, Pixel bitplane, void *closure);
-
 extern _X_EXPORT void
 
 fbCopyNtoN(DrawablePtr pSrcDrawable,
@@ -1133,29 +1122,6 @@ fbCopyNtoN(DrawablePtr pSrcDrawable,
            int dy,
            Bool reverse, Bool upsidedown, Pixel bitplane, void *closure);
 
-/* Compatibility wrapper, to be removed at next ABI change. */
-extern _X_EXPORT void
-
-fbCopyRegion(DrawablePtr pSrcDrawable,
-             DrawablePtr pDstDrawable,
-             GCPtr pGC,
-             RegionPtr pDstRegion,
-             int dx,
-             int dy, fbCopyProc copyProc, Pixel bitPlane, void *closure);
-
-/* Compatibility wrapper, to be removed at next ABI change. */
-extern _X_EXPORT RegionPtr
-
-fbDoCopy(DrawablePtr pSrcDrawable,
-         DrawablePtr pDstDrawable,
-         GCPtr pGC,
-         int xIn,
-         int yIn,
-         int widthSrc,
-         int heightSrc,
-         int xOut,
-         int yOut, fbCopyProc copyProc, Pixel bitplane, void *closure);
-
 extern _X_EXPORT void
 
 fbCopy1toN(DrawablePtr pSrcDrawable,
diff --git a/fb/fbcopy.c b/fb/fbcopy.c
index e9c252a..541ef71 100644
--- a/fb/fbcopy.c
+++ b/fb/fbcopy.c
@@ -28,33 +28,6 @@
 
 #include "fb.h"
 
-/* Compatibility wrapper, to be removed at next ABI change. */
-void
-fbCopyRegion(DrawablePtr pSrcDrawable,
-             DrawablePtr pDstDrawable,
-             GCPtr pGC,
-             RegionPtr pDstRegion,
-             int dx, int dy, fbCopyProc copyProc, Pixel bitPlane, void *closure)
-{
-    miCopyRegion(pSrcDrawable, pDstDrawable, pGC, pDstRegion, dx, dy, copyProc,
-                 bitPlane, closure);
-}
-
-/* Compatibility wrapper, to be removed at next ABI change. */
-RegionPtr
-fbDoCopy(DrawablePtr pSrcDrawable,
-         DrawablePtr pDstDrawable,
-         GCPtr pGC,
-         int xIn,
-         int yIn,
-         int widthSrc,
-         int heightSrc,
-         int xOut, int yOut, fbCopyProc copyProc, Pixel bitPlane, void *closure)
-{
-    return miDoCopy(pSrcDrawable, pDstDrawable, pGC, xIn, yIn, widthSrc,
-                    heightSrc, xOut, yOut, copyProc, bitPlane, closure);
-}
-
 void
 fbCopyNtoN(DrawablePtr pSrcDrawable,
            DrawablePtr pDstDrawable,
commit e4b15125bb06c97f1f34f7074fcdb597e718399c
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu Oct 18 14:24:22 2012 -0400

    mipointer: Remove deprecated miPointerCurrentScreen
    
    The only remaining use was in some debugging code in DMX.
    
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Mark Kettenis <kettenis at openbsd.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/dmx/input/dmxbackend.c b/hw/dmx/input/dmxbackend.c
index 9463c87..807e023 100644
--- a/hw/dmx/input/dmxbackend.c
+++ b/hw/dmx/input/dmxbackend.c
@@ -419,10 +419,9 @@ dmxBackendCollectEvents(DevicePtr pDev,
             }
             break;
         case MotionNotify:
-            DMXDBG9("dmxBackendCollectEvents: MotionNotify %d/%d (mi %d)"
+            DMXDBG8("dmxBackendCollectEvents: MotionNotify %d/%d"
                     " newscreen=%d: %d %d (e=%d; last=%d,%d)\n",
                     dmxScreen->index, priv->myScreen,
-                    miPointerCurrentScreen()->myNum,
                     priv->newscreen,
                     X.xmotion.x, X.xmotion.y,
                     entered, priv->lastX, priv->lastY);
@@ -579,9 +578,6 @@ dmxBackendLateReInit(DevicePtr pDev)
     GETPRIVFROMPDEV;
     int x, y;
 
-    DMXDBG1("dmxBackendLateReInit miPointerCurrentScreen() = %p\n",
-            miPointerCurrentScreen());
-
     dmxBackendSameDisplay(NULL, 0);     /* Invalidate cache */
     dmxBackendInitPrivate(pDev);
     dmxBackendComputeCenter(priv);
diff --git a/mi/mipointer.c b/mi/mipointer.c
index f07c5db..5d591a1 100644
--- a/mi/mipointer.c
+++ b/mi/mipointer.c
@@ -481,15 +481,6 @@ miPointerSetScreen(DeviceIntPtr pDev, int screen_no, int x, int y)
 }
 
 /**
- * @return The current screen of the VCP
- */
-ScreenPtr
-miPointerCurrentScreen(void)
-{
-    return miPointerGetScreen(inputInfo.pointer);
-}
-
-/**
  * @return The current screen of the given device or NULL.
  */
 ScreenPtr
diff --git a/mi/mipointer.h b/mi/mipointer.h
index 33261ab..bdeed12 100644
--- a/mi/mipointer.h
+++ b/mi/mipointer.h
@@ -91,11 +91,6 @@ extern _X_EXPORT void miPointerWarpCursor(DeviceIntPtr /*pDev */ ,
                                           int   /*y */
     );
 
-/* Deprecated in favour of miPointerGetScreen. */
-extern _X_EXPORT ScreenPtr
-miPointerCurrentScreen(void
-) _X_DEPRECATED;
-
 extern _X_EXPORT ScreenPtr
 miPointerGetScreen(DeviceIntPtr pDev);
 extern _X_EXPORT void
commit b5d66b9513a0f1e13f5c5bc9e0958f4eac9bf6c3
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu Oct 18 14:24:21 2012 -0400

    xfree86: Remove deprecated unimplemented xf86MapReadSideEffects
    
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Mark Kettenis <kettenis at openbsd.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/os-support/shared/vidmem.c b/hw/xfree86/os-support/shared/vidmem.c
index 514fc2f..68ed30e 100644
--- a/hw/xfree86/os-support/shared/vidmem.c
+++ b/hw/xfree86/os-support/shared/vidmem.c
@@ -257,16 +257,3 @@ xf86LinearVidMem(void)
     xf86InitVidMem();
     return vidMemInfo.linearSupported;
 }
-
-void
-xf86MapReadSideEffects(int ScreenNum, int Flags, pointer base,
-                       unsigned long Size)
-{
-    if (!(Flags & VIDMEM_READSIDEEFFECT))
-        return;
-
-    if (!vidMemInfo.initialised || !vidMemInfo.readSideEffects)
-        return;
-
-    vidMemInfo.readSideEffects(ScreenNum, base, Size);
-}
diff --git a/hw/xfree86/os-support/xf86OSpriv.h b/hw/xfree86/os-support/xf86OSpriv.h
index 65769c1..bd734f5 100644
--- a/hw/xfree86/os-support/xf86OSpriv.h
+++ b/hw/xfree86/os-support/xf86OSpriv.h
@@ -38,7 +38,6 @@ typedef pointer (*SetWCProcPtr) (int, unsigned long, unsigned long, Bool,
                                  MessageType);
 typedef void (*ProtectMemProcPtr) (int, pointer, unsigned long, Bool);
 typedef void (*UndoWCProcPtr) (int, pointer);
-typedef void (*ReadSideEffectsProcPtr) (int, pointer, unsigned long);
 
 typedef struct {
     Bool initialised;
@@ -47,7 +46,6 @@ typedef struct {
     ProtectMemProcPtr protectMem;
     SetWCProcPtr setWC;
     UndoWCProcPtr undoWC;
-    ReadSideEffectsProcPtr readSideEffects;
     Bool linearSupported;
 } VidMemInfo, *VidMemInfoPtr;
 
diff --git a/hw/xfree86/os-support/xf86_OSproc.h b/hw/xfree86/os-support/xf86_OSproc.h
index 6be5946..106168a 100644
--- a/hw/xfree86/os-support/xf86_OSproc.h
+++ b/hw/xfree86/os-support/xf86_OSproc.h
@@ -136,8 +136,6 @@ extern _X_EXPORT _X_DEPRECATED pointer xf86MapVidMem(int, int, unsigned long,
                                                      unsigned long);
 extern _X_EXPORT _X_DEPRECATED void xf86UnMapVidMem(int, pointer,
                                                     unsigned long);
-extern _X_EXPORT _X_DEPRECATED void xf86MapReadSideEffects(int, int, pointer,
-                                                           unsigned long);
 extern _X_EXPORT int xf86ReadBIOS(unsigned long, unsigned long, unsigned char *,
                                   int);
 extern _X_EXPORT Bool xf86EnableIO(void);
commit abbd85742a390e18497b96902a0c0d976739e3bd
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu Oct 18 14:24:20 2012 -0400

    dix: FIXES is not optional
    
    It's already not optional at configure time, this just makes it so at
    build time too.
    
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/Xext/panoramiX.c b/Xext/panoramiX.c
index 7f888e3..2b3a570 100644
--- a/Xext/panoramiX.c
+++ b/Xext/panoramiX.c
@@ -53,9 +53,7 @@ Equipment Corporation.
 #include "servermd.h"
 #include "resource.h"
 #include "picturestr.h"
-#ifdef XFIXES
 #include "xfixesint.h"
-#endif
 #ifdef COMPOSITE
 #include "compint.h"
 #endif
@@ -583,9 +581,7 @@ PanoramiXExtensionInit(void)
     ProcVector[X_StoreNamedColor] = PanoramiXStoreNamedColor;
 
     PanoramiXRenderInit();
-#ifdef XFIXES
     PanoramiXFixesInit();
-#endif
 #ifdef COMPOSITE
     PanoramiXCompositeInit();
 #endif
@@ -890,9 +886,7 @@ PanoramiXResetProc(ExtensionEntry * extEntry)
     int i;
 
     PanoramiXRenderReset();
-#ifdef XFIXES
     PanoramiXFixesReset();
-#endif
 #ifdef COMPOSITE
     PanoramiXCompositeReset ();
 #endif
diff --git a/dix/cursor.c b/dix/cursor.c
index cd8305c..8cc54bd 100644
--- a/dix/cursor.c
+++ b/dix/cursor.c
@@ -71,9 +71,7 @@ static GlyphSharePtr sharedGlyphs = (GlyphSharePtr) NULL;
 
 DevScreenPrivateKeyRec cursorScreenDevPriv;
 
-#ifdef XFIXES
 static CARD32 cursorSerial;
-#endif
 
 static void
 FreeCursorBits(CursorBitsPtr bits)
@@ -272,10 +270,8 @@ AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits,
     bits->refcnt = -1;
     CheckForEmptyMask(bits);
     pCurs->bits = bits;
-#ifdef XFIXES
     pCurs->serialNumber = ++cursorSerial;
     pCurs->name = None;
-#endif
 
     pCurs->foreRed = foreRed;
     pCurs->foreGreen = foreGreen;
@@ -433,10 +429,8 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
     CheckForEmptyMask(bits);
     pCurs->bits = bits;
     pCurs->refcnt = 1;
-#ifdef XFIXES
     pCurs->serialNumber = ++cursorSerial;
     pCurs->name = None;
-#endif
 
     pCurs->foreRed = foreRed;
     pCurs->foreGreen = foreGreen;
diff --git a/dix/window.c b/dix/window.c
index 9fa51c2..cff341b 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -2847,11 +2847,9 @@ HandleSaveSet(ClientPtr client)
 
     for (j = 0; j < client->numSaved; j++) {
         pWin = SaveSetWindow(client->saveSet[j]);
-#ifdef XFIXES
         if (SaveSetToRoot(client->saveSet[j]))
             pParent = pWin->drawable.pScreen->root;
         else
-#endif
         {
             pParent = pWin->parent;
             while (pParent && (wClient(pParent) == client))
@@ -2859,11 +2857,9 @@ HandleSaveSet(ClientPtr client)
         }
         if (pParent) {
             if (pParent != pWin->parent) {
-#ifdef XFIXES
                 /* unmap first so that ReparentWindow doesn't remap */
                 if (!SaveSetShouldMap(client->saveSet[j]))
                     UnmapWindow(pWin, FALSE);
-#endif
                 ReparentWindow(pWin, pParent,
                                pWin->drawable.x - wBorderWidth(pWin) -
                                pParent->drawable.x,
@@ -2872,9 +2868,7 @@ HandleSaveSet(ClientPtr client)
                 if (!pWin->realized && pWin->mapped)
                     pWin->mapped = FALSE;
             }
-#ifdef XFIXES
             if (SaveSetShouldMap(client->saveSet[j]))
-#endif
                 MapWindow(pWin, client);
         }
     }
diff --git a/include/cursorstr.h b/include/cursorstr.h
index 68ab2ec..2157954 100644
--- a/include/cursorstr.h
+++ b/include/cursorstr.h
@@ -78,10 +78,8 @@ typedef struct _Cursor {
     int refcnt;
     PrivateRec *devPrivates;    /* set by pScr->RealizeCursor */
     XID id;
-#ifdef XFIXES
     CARD32 serialNumber;
     Atom name;
-#endif
 } CursorRec;
 
 #define CURSOR_REC_SIZE (sizeof(CursorRec) + dixPrivatesSize(PRIVATE_CURSOR))
diff --git a/include/dixstruct.h b/include/dixstruct.h
index aef822c..0be7f0e 100644
--- a/include/dixstruct.h
+++ b/include/dixstruct.h
@@ -61,7 +61,6 @@ typedef enum { ClientStateInitial,
     ClientStateGone
 } ClientState;
 
-#ifdef XFIXES
 typedef struct _saveSet {
     struct _Window *windowPtr;
     Bool toRoot;
@@ -73,16 +72,6 @@ typedef struct _saveSet {
 #define SaveSetAssignWindow(ss,w)   ((ss).windowPtr = (w))
 #define SaveSetAssignToRoot(ss,tr)  ((ss).toRoot = (tr))
 #define SaveSetAssignMap(ss,m)      ((ss).map = (m))
-#else
-typedef struct _Window *SaveSetElt;
-
-#define SaveSetWindow(ss)   (ss)
-#define SaveSetToRoot(ss)   FALSE
-#define SaveSetShouldMap(ss)	    TRUE
-#define SaveSetAssignWindow(ss,w)   ((ss) = (w))
-#define SaveSetAssignToRoot(ss,tr)
-#define SaveSetAssignMap(ss,m)
-#endif
 
 typedef struct _Client {
     pointer requestBuffer;
diff --git a/include/extinit.h b/include/extinit.h
index 5690d7b..6d67bf2 100644
--- a/include/extinit.h
+++ b/include/extinit.h
@@ -140,10 +140,8 @@ extern void XFree86BigfontExtensionInit(void);
 
 extern void BigReqExtensionInit(void);
 
-#ifdef XFIXES
 extern _X_EXPORT Bool noXFixesExtension;
 extern void XFixesExtensionInit(void);
-#endif
 
 extern void XInputExtensionInit(void);
 extern _X_EXPORT void AssignTypeAndName(DeviceIntPtr dev,
diff --git a/mi/miinitext.c b/mi/miinitext.c
index dbca9f7..145da38 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -86,7 +86,6 @@ SOFTWARE.
 #undef DBE
 #undef SCREENSAVER
 #undef RANDR
-#undef XFIXES
 #undef DAMAGE
 #undef COMPOSITE
 #undef MITSHM
@@ -168,9 +167,7 @@ static ExtensionToggle ExtensionToggleList[] = {
     {"XFree86-VidModeExtension", &noXFree86VidModeExtension},
 #endif
 #endif
-#ifdef XFIXES
     {"XFIXES", &noXFixesExtension},
-#endif
 #ifdef PANORAMIX
     {"XINERAMA", &noPanoramiXExtension},
 #endif
@@ -263,10 +260,8 @@ static ExtensionModule staticExtensions[] = {
      */
     {PseudoramiXExtensionInit, "PseudoramiX", &noPseudoramiXExtension},
 #endif
-#ifdef XFIXES
     /* must be before Render to layer DisplayCursor correctly */
     {XFixesExtensionInit, "XFIXES", &noXFixesExtension},
-#endif
 #ifdef XF86BIGFONT
     {XFree86BigfontExtensionInit, XF86BIGFONTNAME, &noXFree86BigfontExtension},
 #endif
diff --git a/os/utils.c b/os/utils.c
index 60e828e..97c3125 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -169,9 +169,7 @@ Bool noXFree86DRIExtension = FALSE;
 #ifdef XF86VIDMODE
 Bool noXFree86VidModeExtension = FALSE;
 #endif
-#ifdef XFIXES
 Bool noXFixesExtension = FALSE;
-#endif
 #ifdef PANORAMIX
 /* Xinerama is disabled by default unless enabled via +xinerama */
 Bool noPanoramiXExtension = TRUE;
commit dff81687f5eac3eac9b49f58d4654cc30add2547
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu Oct 18 14:24:19 2012 -0400

    vbe: Don't try to load the ddc submodule
    
    DDC is built into the server now.
    
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/vbe/vbe.c b/hw/xfree86/vbe/vbe.c
index f0344af..39f0cef 100644
--- a/hw/xfree86/vbe/vbe.c
+++ b/hw/xfree86/vbe/vbe.c
@@ -319,10 +319,8 @@ vbeReadEDID(vbeInfoPtr pVbe)
 }
 
 xf86MonPtr
-vbeDoEDID(vbeInfoPtr pVbe, pointer pDDCModule)
+vbeDoEDID(vbeInfoPtr pVbe, pointer unused)
 {
-    xf86MonPtr pMonitor;
-    pointer pModule;
     unsigned char *DDC_data = NULL;
 
     if (!pVbe)
@@ -330,23 +328,12 @@ vbeDoEDID(vbeInfoPtr pVbe, pointer pDDCModule)
     if (pVbe->version < 0x200)
         return NULL;
 
-    if (!(pModule = pDDCModule)) {
-        pModule =
-            xf86LoadSubModule(pVbe->pInt10->pScrn, "ddc");
-        if (!pModule)
-            return NULL;
-    }
-
     DDC_data = vbeReadEDID(pVbe);
 
     if (!DDC_data)
         return NULL;
 
-    pMonitor = xf86InterpretEDID(pVbe->pInt10->pScrn->scrnIndex, DDC_data);
-
-    if (!pDDCModule)
-        xf86UnloadSubModule(pModule);
-    return pMonitor;
+    return xf86InterpretEDID(pVbe->pInt10->pScrn->scrnIndex, DDC_data);
 }
 
 #define GET_UNALIGNED2(x) \
commit bb82191bcfa8042f8d98ec8b1c6616dc31d2c5c8
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu Oct 18 14:24:18 2012 -0400

    misprite: Delete some dead private storage
    
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/mi/misprite.c b/mi/misprite.c
index 97bbf8e..8163f5b 100644
--- a/mi/misprite.c
+++ b/mi/misprite.c
@@ -86,10 +86,6 @@ typedef struct {
     /* os layer procedures */
     ScreenBlockHandlerProcPtr BlockHandler;
 
-    /* device cursor procedures */
-    DeviceCursorInitializeProcPtr DeviceCursorInitialize;
-    DeviceCursorCleanupProcPtr DeviceCursorCleanup;
-
     xColorItem colors[2];
     ColormapPtr pInstalledMap;
     ColormapPtr pColormap;
@@ -329,9 +325,6 @@ miSpriteInitialize(ScreenPtr pScreen, miPointerScreenFuncPtr screenFuncs)
 
     pScreenPriv->BlockHandler = NULL;
 
-    pScreenPriv->DeviceCursorInitialize = pScreen->DeviceCursorInitialize;
-    pScreenPriv->DeviceCursorCleanup = pScreen->DeviceCursorCleanup;
-
     pScreenPriv->pInstalledMap = NULL;
     pScreenPriv->pColormap = NULL;
     pScreenPriv->colors[SOURCE_COLOR].red = 0;
commit 3639ab4ce25dc82a3f8592b7322198f1d2aca5f9
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Oct 16 14:56:25 2012 -0400

    dri2: Don't bother with xf86LoaderCheckSymbol("DRI2Connect")
    
    The DRI2 code is now built-in to the server, even for Xorg.  The only
    thing this could protect against is trying to run a libglx built with
    DRI2 support against an Xorg built without it, which is firmly in
    "doctor it hurts when I do this" territory.
    
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/glx/glxdri2.c b/glx/glxdri2.c
index 8a1fa41..f662b21 100644
--- a/glx/glxdri2.c
+++ b/glx/glxdri2.c
@@ -941,8 +941,7 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
     if (screen == NULL)
         return NULL;
 
-    if (!xf86LoaderCheckSymbol("DRI2Connect") ||
-        !DRI2Connect(serverClient, pScreen, DRI2DriverDRI,
+    if (!DRI2Connect(serverClient, pScreen, DRI2DriverDRI,
                      &screen->fd, &driverName, &deviceName)) {
         LogMessage(X_INFO,
                    "AIGLX: Screen %d is not DRI2 capable\n", pScreen->myNum);
commit 13b507409f9e01adebba50e7eb801b52e52692ba
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Oct 16 14:56:23 2012 -0400

    list: Avoid using X types
    
    In particular, Bool.  This is not an ABI break:
    
    /usr/include/X11/Xdefs.h:typedef int Bool;
    
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/include/list.h b/include/list.h
index 11de7c5..455c670 100644
--- a/include/list.h
+++ b/include/list.h
@@ -213,7 +213,7 @@ xorg_list_del(struct xorg_list *entry)
  *
  * @return True if the list contains one or more elements or False otherwise.
  */
-static inline Bool
+static inline int
 xorg_list_is_empty(struct xorg_list *head)
 {
     return head->next == head;
commit dbe10ef0e35659ee0e5db73f29670a3894a3e3f5
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Oct 16 14:56:22 2012 -0400

    dbe: Fold the window private private into the window private
    
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/dbe/Makefile.am b/dbe/Makefile.am
index 043555b..7d034c7 100644
--- a/dbe/Makefile.am
+++ b/dbe/Makefile.am
@@ -9,5 +9,4 @@ endif
 libdbe_la_SOURCES = \
         dbe.c \
         midbe.c \
-        midbe.h \
-        midbestr.h
+        midbe.h
diff --git a/dbe/dbe.c b/dbe/dbe.c
index 3054c54..5524615 100644
--- a/dbe/dbe.c
+++ b/dbe/dbe.c
@@ -229,8 +229,7 @@ ProcDbeAllocateBackBufferName(ClientPtr client)
          * Allocate a window priv.
          */
 
-        pDbeWindowPriv =
-            dixAllocateObjectWithPrivates(DbeWindowPrivRec, PRIVATE_DBE_WINDOW);
+        pDbeWindowPriv = calloc(1, sizeof(DbeWindowPrivRec));
         if (!pDbeWindowPriv)
             return BadAlloc;
 
@@ -1222,7 +1221,7 @@ DbeWindowPrivDelete(pointer pDbeWinPriv, XID id)
                       NULL);
 
         /* We are done with the window priv. */
-        dixFreeObjectWithPrivates(pDbeWindowPriv, PRIVATE_DBE_WINDOW);
+        free(pDbeWindowPriv);
     }
 
     return Success;
diff --git a/dbe/dbestruct.h b/dbe/dbestruct.h
index 22dc460..2002066 100644
--- a/dbe/dbestruct.h
+++ b/dbe/dbestruct.h
@@ -143,6 +143,20 @@ typedef struct _DbeWindowPrivRec {
      */
     XID initIDs[DBE_INIT_MAX_IDS];
 
+    /* Pointer to a drawable that contains the contents of the back buffer.
+     */
+    PixmapPtr pBackBuffer;
+
+    /* Pointer to a drawable that contains the contents of the front buffer.
+     * This pointer is only used for the XdbeUntouched swap action.  For that
+     * swap action, we need to copy the front buffer (window) contents into
+     * this drawable, copy the contents of current back buffer drawable (the
+     * back buffer) into the window, swap the front and back drawable pointers,
+     * and then swap the drawable/resource associations in the resource
+     * database.
+     */
+    PixmapPtr pFrontBuffer;
+
     /* Device-specific private information.
      */
     PrivateRec *devPrivates;
diff --git a/dbe/midbe.c b/dbe/midbe.c
index 71c7963..3663fdd 100644
--- a/dbe/midbe.c
+++ b/dbe/midbe.c
@@ -48,7 +48,6 @@
 #include "resource.h"
 #include "opaque.h"
 #include "dbestruct.h"
-#include "midbestr.h"
 #include "regionstr.h"
 #include "gcstruct.h"
 #include "inputstr.h"
@@ -57,9 +56,6 @@
 
 #include <stdio.h>
 
-static DevPrivateKeyRec miDbeWindowPrivPrivKeyRec;
-
-#define miDbeWindowPrivPrivKey (&miDbeWindowPrivPrivKeyRec)
 
 /******************************************************************************
  *
@@ -138,7 +134,6 @@ miDbeAllocBackBufferName(WindowPtr pWin, XID bufId, int swapAction)
 {
     ScreenPtr pScreen;
     DbeWindowPrivPtr pDbeWindowPriv;
-    MiDbeWindowPrivPrivPtr pDbeWindowPrivPriv;
     DbeScreenPrivPtr pDbeScreenPriv;
     GCPtr pGC;
     xRectangle clearRect;
@@ -156,12 +151,8 @@ miDbeAllocBackBufferName(WindowPtr pWin, XID bufId, int swapAction)
 
         pDbeScreenPriv = DBE_SCREEN_PRIV(pScreen);
 
-        /* Setup the window priv priv. */
-        pDbeWindowPrivPriv = MI_DBE_WINDOW_PRIV_PRIV(pDbeWindowPriv);
-        pDbeWindowPrivPriv->pDbeWindowPriv = pDbeWindowPriv;
-
         /* Get a front pixmap. */
-        if (!(pDbeWindowPrivPriv->pFrontBuffer =
+        if (!(pDbeWindowPriv->pFrontBuffer =
               (*pScreen->CreatePixmap) (pScreen, pDbeWindowPriv->width,
                                         pDbeWindowPriv->height,
                                         pWin->drawable.depth, 0))) {
@@ -169,22 +160,22 @@ miDbeAllocBackBufferName(WindowPtr pWin, XID bufId, int swapAction)
         }
 
         /* Get a back pixmap. */
-        if (!(pDbeWindowPrivPriv->pBackBuffer =
+        if (!(pDbeWindowPriv->pBackBuffer =
               (*pScreen->CreatePixmap) (pScreen, pDbeWindowPriv->width,
                                         pDbeWindowPriv->height,
                                         pWin->drawable.depth, 0))) {
-            (*pScreen->DestroyPixmap) (pDbeWindowPrivPriv->pFrontBuffer);
+            (*pScreen->DestroyPixmap) (pDbeWindowPriv->pFrontBuffer);
             return BadAlloc;
         }
 
         /* Security creation/labeling check. */
         rc = XaceHook(XACE_RESOURCE_ACCESS, serverClient, bufId,
-                      dbeDrawableResType, pDbeWindowPrivPriv->pBackBuffer,
+                      dbeDrawableResType, pDbeWindowPriv->pBackBuffer,
                       RT_WINDOW, pWin, DixCreateAccess);
 
         /* Make the back pixmap a DBE drawable resource. */
         if (rc != Success || !AddResource(bufId, dbeDrawableResType,
-                                          pDbeWindowPrivPriv->pBackBuffer)) {
+                                          pDbeWindowPriv->pBackBuffer)) {
             /* free the buffer and the drawable resource */
             FreeResource(bufId, RT_NONE);
             return (rc == Success) ? BadAlloc : rc;
@@ -193,11 +184,11 @@ miDbeAllocBackBufferName(WindowPtr pWin, XID bufId, int swapAction)
         /* Clear the back buffer. */
         pGC = GetScratchGC(pWin->drawable.depth, pWin->drawable.pScreen);
         if ((*pDbeScreenPriv->SetupBackgroundPainter) (pWin, pGC)) {
-            ValidateGC((DrawablePtr) pDbeWindowPrivPriv->pBackBuffer, pGC);
+            ValidateGC((DrawablePtr) pDbeWindowPriv->pBackBuffer, pGC);
             clearRect.x = clearRect.y = 0;
-            clearRect.width = pDbeWindowPrivPriv->pBackBuffer->drawable.width;
-            clearRect.height = pDbeWindowPrivPriv->pBackBuffer->drawable.height;
-            (*pGC->ops->PolyFillRect) ((DrawablePtr) pDbeWindowPrivPriv->
+            clearRect.width = pDbeWindowPriv->pBackBuffer->drawable.width;
+            clearRect.height = pDbeWindowPriv->pBackBuffer->drawable.height;
+            (*pGC->ops->PolyFillRect) ((DrawablePtr) pDbeWindowPriv->
                                        pBackBuffer, pGC, 1, &clearRect);
         }
         FreeScratchGC(pGC);
@@ -210,9 +201,8 @@ miDbeAllocBackBufferName(WindowPtr pWin, XID bufId, int swapAction)
          */
 
         /* Associate the new ID with an existing pixmap. */
-        pDbeWindowPrivPriv = MI_DBE_WINDOW_PRIV_PRIV(pDbeWindowPriv);
         if (!AddResource(bufId, dbeDrawableResType,
-                         (pointer) pDbeWindowPrivPriv->pBackBuffer)) {
+                         (pointer) pDbeWindowPriv->pBackBuffer)) {
             return BadAlloc;
         }
 
@@ -237,12 +227,10 @@ static void
 miDbeAliasBuffers(DbeWindowPrivPtr pDbeWindowPriv)
 {
     int i;
-    MiDbeWindowPrivPrivPtr pDbeWindowPrivPriv =
-        MI_DBE_WINDOW_PRIV_PRIV(pDbeWindowPriv);
 
     for (i = 0; i < pDbeWindowPriv->nBufferIDs; i++) {
         ChangeResourceValue(pDbeWindowPriv->IDs[i], dbeDrawableResType,
-                            (pointer) pDbeWindowPrivPriv->pBackBuffer);
+                            (pointer) pDbeWindowPriv->pBackBuffer);
     }
 
 }                               /* miDbeAliasBuffers() */
@@ -261,15 +249,15 @@ static int
 miDbeSwapBuffers(ClientPtr client, int *pNumWindows, DbeSwapInfoPtr swapInfo)
 {
     DbeScreenPrivPtr pDbeScreenPriv;
+    DbeWindowPrivPtr pDbeWindowPriv;
     GCPtr pGC;
     WindowPtr pWin;
-    MiDbeWindowPrivPrivPtr pDbeWindowPrivPriv;
     PixmapPtr pTmpBuffer;
     xRectangle clearRect;
 
     pWin = swapInfo[0].pWindow;
     pDbeScreenPriv = DBE_SCREEN_PRIV_FROM_WINDOW(pWin);
-    pDbeWindowPrivPriv = MI_DBE_WINDOW_PRIV_PRIV_FROM_WINDOW(pWin);
+    pDbeWindowPriv = DBE_WINDOW_PRIV(pWin);
     pGC = GetScratchGC(pWin->drawable.depth, pWin->drawable.pScreen);
 
     /*
@@ -286,9 +274,9 @@ miDbeSwapBuffers(ClientPtr client, int *pNumWindows, DbeSwapInfoPtr swapInfo)
         break;
 
     case XdbeUntouched:
-        ValidateGC((DrawablePtr) pDbeWindowPrivPriv->pFrontBuffer, pGC);
+        ValidateGC((DrawablePtr) pDbeWindowPriv->pFrontBuffer, pGC);
         (*pGC->ops->CopyArea) ((DrawablePtr) pWin,
-                               (DrawablePtr) pDbeWindowPrivPriv->pFrontBuffer,
+                               (DrawablePtr) pDbeWindowPriv->pFrontBuffer,
                                pGC, 0, 0, pWin->drawable.width,
                                pWin->drawable.height, 0, 0);
         break;
@@ -305,7 +293,7 @@ miDbeSwapBuffers(ClientPtr client, int *pNumWindows, DbeSwapInfoPtr swapInfo)
      */
 
     ValidateGC((DrawablePtr) pWin, pGC);
-    (*pGC->ops->CopyArea) ((DrawablePtr) pDbeWindowPrivPriv->pBackBuffer,
+    (*pGC->ops->CopyArea) ((DrawablePtr) pDbeWindowPriv->pBackBuffer,
                            (DrawablePtr) pWin, pGC, 0, 0,
                            pWin->drawable.width, pWin->drawable.height, 0, 0);
 
@@ -321,23 +309,23 @@ miDbeSwapBuffers(ClientPtr client, int *pNumWindows, DbeSwapInfoPtr swapInfo)
 
     case XdbeBackground:
         if ((*pDbeScreenPriv->SetupBackgroundPainter) (pWin, pGC)) {
-            ValidateGC((DrawablePtr) pDbeWindowPrivPriv->pBackBuffer, pGC);
+            ValidateGC((DrawablePtr) pDbeWindowPriv->pBackBuffer, pGC);
             clearRect.x = 0;
             clearRect.y = 0;
-            clearRect.width = pDbeWindowPrivPriv->pBackBuffer->drawable.width;
-            clearRect.height = pDbeWindowPrivPriv->pBackBuffer->drawable.height;
-            (*pGC->ops->PolyFillRect) ((DrawablePtr) pDbeWindowPrivPriv->
+            clearRect.width = pDbeWindowPriv->pBackBuffer->drawable.width;
+            clearRect.height = pDbeWindowPriv->pBackBuffer->drawable.height;
+            (*pGC->ops->PolyFillRect) ((DrawablePtr) pDbeWindowPriv->
                                        pBackBuffer, pGC, 1, &clearRect);
         }
         break;
 
     case XdbeUntouched:
         /* Swap pixmap pointers. */
-        pTmpBuffer = pDbeWindowPrivPriv->pBackBuffer;
-        pDbeWindowPrivPriv->pBackBuffer = pDbeWindowPrivPriv->pFrontBuffer;
-        pDbeWindowPrivPriv->pFrontBuffer = pTmpBuffer;
+        pTmpBuffer = pDbeWindowPriv->pBackBuffer;
+        pDbeWindowPriv->pBackBuffer = pDbeWindowPriv->pFrontBuffer;
+        pDbeWindowPriv->pFrontBuffer = pTmpBuffer;
 
-        miDbeAliasBuffers(pDbeWindowPrivPriv->pDbeWindowPriv);
+        miDbeAliasBuffers(pDbeWindowPriv);
 
         break;
 
@@ -427,8 +415,6 @@ miDbeSwapBuffers(ClientPtr client, int *pNumWindows, DbeSwapInfoPtr swapInfo)
 static void
 miDbeWinPrivDelete(DbeWindowPrivPtr pDbeWindowPriv, XID bufId)
 {
-    MiDbeWindowPrivPrivPtr pDbeWindowPrivPriv;
-
     if (pDbeWindowPriv->nBufferIDs != 0) {
         /* We still have at least one more buffer ID associated with this
          * window.
@@ -440,18 +426,15 @@ miDbeWinPrivDelete(DbeWindowPrivPtr pDbeWindowPriv, XID bufId)
      * free some stuff.
      */
 
-    pDbeWindowPrivPriv = MI_DBE_WINDOW_PRIV_PRIV(pDbeWindowPriv);
-
     /* Destroy the front and back pixmaps. */
-    if (pDbeWindowPrivPriv->pFrontBuffer) {
+    if (pDbeWindowPriv->pFrontBuffer) {
         (*pDbeWindowPriv->pWindow->drawable.pScreen->
-         DestroyPixmap) (pDbeWindowPrivPriv->pFrontBuffer);
+         DestroyPixmap) (pDbeWindowPriv->pFrontBuffer);
     }
-    if (pDbeWindowPrivPriv->pBackBuffer) {
+    if (pDbeWindowPriv->pBackBuffer) {
         (*pDbeWindowPriv->pWindow->drawable.pScreen->
-         DestroyPixmap) (pDbeWindowPrivPriv->pBackBuffer);
+         DestroyPixmap) (pDbeWindowPriv->pBackBuffer);
     }
-
 }                               /* miDbeWinPrivDelete() */
 
 /******************************************************************************
@@ -627,10 +610,6 @@ miDbePositionWindow(WindowPtr pWin, int x, int y)
     else {
         /* Clear out the new DBE buffer pixmaps. */
 
-        MiDbeWindowPrivPrivPtr pDbeWindowPrivPriv;
-
-        pDbeWindowPrivPriv = MI_DBE_WINDOW_PRIV_PRIV(pDbeWindowPriv);
-
         /* I suppose this could avoid quite a bit of work if
          * it computed the minimal area required.
          */
@@ -641,9 +620,9 @@ miDbePositionWindow(WindowPtr pWin, int x, int y)
         }
         /* Copy the contents of the old front pixmap to the new one. */
         if (pWin->bitGravity != ForgetGravity) {
-            (*pGC->ops->CopyArea) ((DrawablePtr) pDbeWindowPrivPriv->
-                                   pFrontBuffer, (DrawablePtr) pFrontBuffer,
-                                   pGC, sourcex, sourcey, savewidth, saveheight,
+            (*pGC->ops->CopyArea) ((DrawablePtr) pDbeWindowPriv->pFrontBuffer,
+				   (DrawablePtr) pFrontBuffer, pGC,
+				   sourcex, sourcey, savewidth, saveheight,
                                    destx, desty);
         }
 
@@ -654,8 +633,8 @@ miDbePositionWindow(WindowPtr pWin, int x, int y)
         }
         /* Copy the contents of the old back pixmap to the new one. */
         if (pWin->bitGravity != ForgetGravity) {
-            (*pGC->ops->CopyArea) ((DrawablePtr) pDbeWindowPrivPriv->
-                                   pBackBuffer, (DrawablePtr) pBackBuffer, pGC,
+            (*pGC->ops->CopyArea) ((DrawablePtr) pDbeWindowPriv->pBackBuffer,
+				   (DrawablePtr) pBackBuffer, pGC,
                                    sourcex, sourcey, savewidth, saveheight,
                                    destx, desty);
         }
@@ -664,11 +643,11 @@ miDbePositionWindow(WindowPtr pWin, int x, int y)
          * pixmaps.
          */
 
-        (*pScreen->DestroyPixmap) (pDbeWindowPrivPriv->pFrontBuffer);
-        (*pScreen->DestroyPixmap) (pDbeWindowPrivPriv->pBackBuffer);
+        (*pScreen->DestroyPixmap) (pDbeWindowPriv->pFrontBuffer);
+        (*pScreen->DestroyPixmap) (pDbeWindowPriv->pBackBuffer);
 
-        pDbeWindowPrivPriv->pFrontBuffer = pFrontBuffer;
-        pDbeWindowPrivPriv->pBackBuffer = pBackBuffer;
+        pDbeWindowPriv->pFrontBuffer = pFrontBuffer;
+        pDbeWindowPriv->pBackBuffer = pBackBuffer;
 
         /* Make sure all XID are associated with the new back pixmap. */
         miDbeAliasBuffers(pDbeWindowPriv);
@@ -693,10 +672,6 @@ miDbePositionWindow(WindowPtr pWin, int x, int y)
 Bool
 miDbeInit(ScreenPtr pScreen, DbeScreenPrivPtr pDbeScreenPriv)
 {
-    if (!dixRegisterPrivateKey(&miDbeWindowPrivPrivKeyRec, PRIVATE_DBE_WINDOW,
-                               sizeof(MiDbeWindowPrivPrivRec)))
-        return FALSE;
-
     /* Wrap functions. */
     pDbeScreenPriv->PositionWindow = pScreen->PositionWindow;
     pScreen->PositionWindow = miDbePositionWindow;
diff --git a/dbe/midbestr.h b/dbe/midbestr.h
deleted file mode 100644
index 70017b0..0000000
--- a/dbe/midbestr.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/******************************************************************************
- * 
- * Copyright (c) 1994, 1995  Hewlett-Packard Company
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- * 
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL HEWLETT-PACKARD COMPANY 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.
- * 
- * Except as contained in this notice, the name of the Hewlett-Packard
- * Company shall not be used in advertising or otherwise to promote the
- * sale, use or other dealings in this Software without prior written
- * authorization from the Hewlett-Packard Company.
- * 
- *     Header file for users of machine-independent DBE code
- * 
- *****************************************************************************/
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#ifndef MIDBE_STRUCT_H
-#define MIDBE_STRUCT_H
-
-/* DEFINES */
-
-#define MI_DBE_WINDOW_PRIV_PRIV(pDbeWindowPriv) \
-    (!(pDbeWindowPriv) ? NULL : (MiDbeWindowPrivPrivPtr) \
-     dixLookupPrivate(&(pDbeWindowPriv)->devPrivates, miDbeWindowPrivPrivKey))
-
-#define MI_DBE_WINDOW_PRIV_PRIV_FROM_WINDOW(pWin)\
-    MI_DBE_WINDOW_PRIV_PRIV(DBE_WINDOW_PRIV(pWin))
-
-/* TYPEDEFS */
-
-typedef struct _MiDbeWindowPrivPrivRec {
-    /* Place machine-specific fields in here.
-     * Since this is mi code, we do not really have machine-specific fields.
-     */
-
-    /* Pointer to a drawable that contains the contents of the back buffer.
-     */
-    PixmapPtr pBackBuffer;
-
-    /* Pointer to a drawable that contains the contents of the front buffer.
-     * This pointer is only used for the XdbeUntouched swap action.  For that
-     * swap action, we need to copy the front buffer (window) contents into
-     * this drawable, copy the contents of current back buffer drawable (the
-     * back buffer) into the window, swap the front and back drawable pointers,
-     * and then swap the drawable/resource associations in the resource
-     * database.
-     */
-    PixmapPtr pFrontBuffer;
-
-    /* Pointer back to our window private with which we are associated. */
-    DbeWindowPrivPtr pDbeWindowPriv;
-
-} MiDbeWindowPrivPrivRec, *MiDbeWindowPrivPrivPtr;
-
-#endif                          /* MIDBE_STRUCT_H */
diff --git a/dix/privates.c b/dix/privates.c
index 55b9345..41b1a76 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -105,7 +105,6 @@ static const char *key_names[PRIVATE_LAST] = {
     [PRIVATE_CURSOR_BITS] = "CURSOR_BITS",
 
     /* extension privates */
-    [PRIVATE_DBE_WINDOW] = "DBE_WINDOW",
     [PRIVATE_DAMAGE] = "DAMAGE",
     [PRIVATE_GLYPH] = "GLYPH",
     [PRIVATE_GLYPHSET] = "GLYPHSET",
diff --git a/include/privates.h b/include/privates.h
index 2c8864b..0abdce7 100644
--- a/include/privates.h
+++ b/include/privates.h
@@ -46,7 +46,6 @@ typedef enum {
     PRIVATE_CURSOR_BITS,
 
     /* extension privates */
-    PRIVATE_DBE_WINDOW,
     PRIVATE_DAMAGE,
     PRIVATE_GLYPH,
     PRIVATE_GLYPHSET,
commit 1489637d567b0034a916f88079b5f360e7fce99c
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Oct 16 14:56:21 2012 -0400

    dbe: Fold midbe reset into dix
    
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/dbe/dbe.c b/dbe/dbe.c
index c708c9e..3054c54 100644
--- a/dbe/dbe.c
+++ b/dbe/dbe.c
@@ -91,7 +91,6 @@ DbeStubScreen(DbeScreenPrivPtr pDbeScreenPriv, int *nStubbedScreens)
     pDbeScreenPriv->AllocBackBufferName = NULL;
     pDbeScreenPriv->SwapBuffers = NULL;
     pDbeScreenPriv->WinPrivDelete = NULL;
-    pDbeScreenPriv->ResetProc = NULL;
 
     (*nStubbedScreens)++;
 
@@ -1255,10 +1254,7 @@ DbeResetProc(ExtensionEntry * extEntry)
         if (pDbeScreenPriv) {
             /* Unwrap DestroyWindow, which was wrapped in DbeExtensionInit(). */
             pScreen->DestroyWindow = pDbeScreenPriv->DestroyWindow;
-
-            if (pDbeScreenPriv->ResetProc)
-                (*pDbeScreenPriv->ResetProc) (pScreen);
-
+            pScreen->PositionWindow = pDbeScreenPriv->PositionWindow;
             free(pDbeScreenPriv);
         }
     }
diff --git a/dbe/dbestruct.h b/dbe/dbestruct.h
index 1930b71..22dc460 100644
--- a/dbe/dbestruct.h
+++ b/dbe/dbestruct.h
@@ -183,9 +183,6 @@ typedef struct _DbeScreenPrivRec {
     void (*WinPrivDelete) (DbeWindowPrivPtr /*pDbeWindowPriv */ ,
                            XID  /*bufId */
         );
-    void (*ResetProc) (ScreenPtr        /*pScreen */
-        );
-
 } DbeScreenPrivRec, *DbeScreenPrivPtr;
 
 #endif                          /* DBE_STRUCT_H */
diff --git a/dbe/midbe.c b/dbe/midbe.c
index 01f2a45..71c7963 100644
--- a/dbe/midbe.c
+++ b/dbe/midbe.c
@@ -682,30 +682,6 @@ miDbePositionWindow(WindowPtr pWin, int x, int y)
 
 /******************************************************************************
  *
- * DBE MI Procedure: miDbeResetProc
- *
- * Description:
- *
- *     This function is called from DbeResetProc(), which is called at the end
- *     of every server generation.  This function peforms any MI-specific
- *     shutdown tasks.
- *
- *****************************************************************************/
-
-static void
-miDbeResetProc(ScreenPtr pScreen)
-{
-    DbeScreenPrivPtr pDbeScreenPriv;
-
-    pDbeScreenPriv = DBE_SCREEN_PRIV(pScreen);
-
-    /* Unwrap wrappers */
-    pScreen->PositionWindow = pDbeScreenPriv->PositionWindow;
-
-}                               /* miDbeResetProc() */
-
-/******************************************************************************
- *
  * DBE MI Procedure: miDbeInit
  *
  * Description:
@@ -729,7 +705,6 @@ miDbeInit(ScreenPtr pScreen, DbeScreenPrivPtr pDbeScreenPriv)
     pDbeScreenPriv->GetVisualInfo = miDbeGetVisualInfo;
     pDbeScreenPriv->AllocBackBufferName = miDbeAllocBackBufferName;
     pDbeScreenPriv->SwapBuffers = miDbeSwapBuffers;
-    pDbeScreenPriv->ResetProc = miDbeResetProc;
     pDbeScreenPriv->WinPrivDelete = miDbeWinPrivDelete;
 
     return TRUE;
commit 44d770750069486a8452fb2384f9b85745268e61
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Oct 16 14:56:20 2012 -0400

    dbe: Drop the unused idiom support
    
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/dbe/dbe.c b/dbe/dbe.c
index 9039d80..c708c9e 100644
--- a/dbe/dbe.c
+++ b/dbe/dbe.c
@@ -90,8 +90,6 @@ DbeStubScreen(DbeScreenPrivPtr pDbeScreenPriv, int *nStubbedScreens)
     pDbeScreenPriv->GetVisualInfo = NULL;
     pDbeScreenPriv->AllocBackBufferName = NULL;
     pDbeScreenPriv->SwapBuffers = NULL;
-    pDbeScreenPriv->BeginIdiom = NULL;
-    pDbeScreenPriv->EndIdiom = NULL;
     pDbeScreenPriv->WinPrivDelete = NULL;
     pDbeScreenPriv->ResetProc = NULL;
 
@@ -545,44 +543,6 @@ ProcDbeSwapBuffers(ClientPtr client)
 
 /******************************************************************************
  *
- * DBE DIX Procedure: ProcDbeBeginIdiom
- *
- * Description:
- *
- *     This function is for processing a DbeBeginIdiom request.
- *     This request informs the server that a complex swap will immediately
- *     follow this request.
- *
- * Return Values:
- *
- *     Success
- *
- *****************************************************************************/
-
-static int
-ProcDbeBeginIdiom(ClientPtr client)
-{
-    /* REQUEST(xDbeBeginIdiomReq); */
-    DbeScreenPrivPtr pDbeScreenPriv;
-    register int i;
-
-    REQUEST_SIZE_MATCH(xDbeBeginIdiomReq);
-
-    for (i = 0; i < screenInfo.numScreens; i++) {
-        pDbeScreenPriv = DBE_SCREEN_PRIV(screenInfo.screens[i]);
-
-        /* Call the DDX begin idiom procedure if there is one. */
-        if (pDbeScreenPriv->BeginIdiom) {
-            (*pDbeScreenPriv->BeginIdiom) (client);
-        }
-    }
-
-    return Success;
-
-}                               /* ProcDbeBeginIdiom() */
-
-/******************************************************************************
- *
  * DBE DIX Procedure: ProcDbeGetVisualInfo
  *
  * Description:
@@ -818,7 +778,7 @@ ProcDbeDispatch(ClientPtr client)
         return (ProcDbeSwapBuffers(client));
 
     case X_DbeBeginIdiom:
-        return (ProcDbeBeginIdiom(client));
+        return Success;
 
     case X_DbeEndIdiom:
         return Success;
@@ -982,32 +942,6 @@ SProcDbeSwapBuffers(ClientPtr client)
 
 /******************************************************************************
  *
- * DBE DIX Procedure: SProcDbeBeginIdiom
- *
- * Description:
- *
- *     This function is for processing a DbeBeginIdiom request on a swapped
- *     server.  This request informs the server that a complex swap will
- *     immediately follow this request.
- *
- * Return Values:
- *
- *     Success
- *
- *****************************************************************************/
-
-static int
-SProcDbeBeginIdiom(ClientPtr client)
-{
-    REQUEST(xDbeBeginIdiomReq);
-
-    swaps(&stuff->length);
-    return (ProcDbeBeginIdiom(client));
-
-}                               /* SProcDbeBeginIdiom() */
-
-/******************************************************************************
- *
  * DBE DIX Procedure: SProcDbeGetVisualInfo
  *
  * Description:
@@ -1097,7 +1031,7 @@ SProcDbeDispatch(ClientPtr client)
         return (SProcDbeSwapBuffers(client));
 
     case X_DbeBeginIdiom:
-        return (SProcDbeBeginIdiom(client));
+        return Success;
 
     case X_DbeEndIdiom:
         return Success;
diff --git a/dbe/dbestruct.h b/dbe/dbestruct.h
index f9d938a..1930b71 100644
--- a/dbe/dbestruct.h
+++ b/dbe/dbestruct.h
@@ -180,10 +180,6 @@ typedef struct _DbeScreenPrivRec {
                         int * /*pNumWindows */ ,
                         DbeSwapInfoPtr  /*swapInfo */
         );
-    void (*BeginIdiom) (ClientPtr       /*client */
-        );
-    void (*EndIdiom) (ClientPtr /*client */
-        );
     void (*WinPrivDelete) (DbeWindowPrivPtr /*pDbeWindowPriv */ ,
                            XID  /*bufId */
         );
diff --git a/dbe/midbe.c b/dbe/midbe.c
index d810d99..01f2a45 100644
--- a/dbe/midbe.c
+++ b/dbe/midbe.c
@@ -729,8 +729,6 @@ miDbeInit(ScreenPtr pScreen, DbeScreenPrivPtr pDbeScreenPriv)
     pDbeScreenPriv->GetVisualInfo = miDbeGetVisualInfo;
     pDbeScreenPriv->AllocBackBufferName = miDbeAllocBackBufferName;
     pDbeScreenPriv->SwapBuffers = miDbeSwapBuffers;
-    pDbeScreenPriv->BeginIdiom = 0;
-    pDbeScreenPriv->EndIdiom = 0;
     pDbeScreenPriv->ResetProc = miDbeResetProc;
     pDbeScreenPriv->WinPrivDelete = miDbeWinPrivDelete;
 
commit 8cce0cf4d378f6fa52bc2cd277737b8986ab683c
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Oct 16 14:56:19 2012 -0400

    damage: Remove the 'damage window' resource type.
    
    Note that the existing code never actually creates a resource of this
    type, so it can't possibly do anything.  This is clearly meant to track
    window destruction and clean up any associated Damages, but that's
    already handled by miext/damage's DestroyWindow wrapper.
    
    Previous discussion:
    http://lists.freedesktop.org/archives/xorg-devel/2011-March/020847.html
    
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/damageext/damageext.c b/damageext/damageext.c
index a942ffa..e02a28f 100644
--- a/damageext/damageext.c
+++ b/damageext/damageext.c
@@ -31,7 +31,6 @@
 static unsigned char DamageReqCode;
 static int DamageEventBase;
 static RESTYPE DamageExtType;
-static RESTYPE DamageExtWinType;
 
 static DevPrivateKeyRec DamageClientPrivateKeyRec;
 
@@ -429,8 +428,6 @@ FreeDamageExt(pointer value, XID did)
      * Get rid of the resource table entry hanging from the window id
      */
     pDamageExt->id = 0;
-    if (WindowDrawable(pDamageExt->pDrawable->type))
-        FreeResourceByType(pDamageExt->pDrawable->id, DamageExtWinType, TRUE);
     if (pDamageExt->pDamage) {
         DamageUnregister(pDamageExt->pDrawable, pDamageExt->pDamage);
         DamageDestroy(pDamageExt->pDamage);
@@ -439,16 +436,6 @@ FreeDamageExt(pointer value, XID did)
     return Success;
 }
 
-static int
-FreeDamageExtWin(pointer value, XID wid)
-{
-    DamageExtPtr pDamageExt = (DamageExtPtr) value;
-
-    if (pDamageExt->id)
-        FreeResource(pDamageExt->id, RT_NONE);
-    return Success;
-}
-
 static void
 SDamageNotifyEvent(xDamageNotifyEvent * from, xDamageNotifyEvent * to)
 {
@@ -479,10 +466,6 @@ DamageExtensionInit(void)
     if (!DamageExtType)
         return;
 
-    DamageExtWinType = CreateNewResourceType(FreeDamageExtWin, "DamageExtWin");
-    if (!DamageExtWinType)
-        return;
-
     if (!dixRegisterPrivateKey
         (&DamageClientPrivateKeyRec, PRIVATE_CLIENT, sizeof(DamageClientRec)))
         return;
commit e674815e0a217ac01ec2d6a8517f8466b27fb39f
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Oct 16 14:56:18 2012 -0400

    dmx: Remove ShadowFB support
    
    This has been listed as deprecated ever since DMX was merged.
    
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/dmx/Makefile.am b/hw/dmx/Makefile.am
index fb727e6..a05af13 100644
--- a/hw/dmx/Makefile.am
+++ b/hw/dmx/Makefile.am
@@ -56,8 +56,6 @@ Xdmx_SOURCES = dmx.c \
                dmxprop.h \
                dmxscrinit.c \
                dmxscrinit.h \
-               dmxshadow.c \
-               dmxshadow.h \
                dmxstat.c \
                dmxstat.h \
                dmxsync.c \
diff --git a/hw/dmx/dmx.h b/hw/dmx/dmx.h
index f0cb044..7242e43 100644
--- a/hw/dmx/dmx.h
+++ b/hw/dmx/dmx.h
@@ -254,10 +254,6 @@ typedef struct _DMXScreenInfo {
 /* Global variables available to all Xserver/hw/dmx routines. */
 extern int dmxNumScreens;                       /**< Number of dmxScreens */
 extern DMXScreenInfo *dmxScreens;               /**< List of outputs */
-extern int dmxShadowFB;                         /**< Non-zero if using
-
-                                                 * shadow frame-buffer
-                                                 * (deprecated) */
 extern XErrorEvent dmxLastErrorEvent;           /**< Last error that
 
                                                  * occurred */
diff --git a/hw/dmx/dmxinit.c b/hw/dmx/dmxinit.c
index 7de402b..65416ed 100644
--- a/hw/dmx/dmxinit.c
+++ b/hw/dmx/dmxinit.c
@@ -82,8 +82,6 @@ DMXScreenInfo *dmxScreens;
 int dmxNumInputs;
 DMXInputInfo *dmxInputs;
 
-int dmxShadowFB = FALSE;
-
 XErrorEvent dmxLastErrorEvent;
 Bool dmxErrorOccurred = FALSE;
 
@@ -854,9 +852,6 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char *argv[])
     /* Initialized things that need timer hooks */
     dmxStatInit();
     dmxSyncInit();              /* Calls RegisterBlockAndWakeupHandlers */
-
-    dmxLog(dmxInfo, "Shadow framebuffer support %s\n",
-           dmxShadowFB ? "enabled" : "disabled");
 }
 
 /* RATS: Assuming the fp string (which comes from the command-line argv
@@ -951,10 +946,6 @@ ddxProcessArgument(int argc, char *argv[], int i)
         retval = 2;
     }
     else if (!strcmp(argv[i], "-noshadowfb")) {
-        dmxLog(dmxWarning,
-               "-noshadowfb has been deprecated "
-               "since it is now the default\n");
-        dmxShadowFB = FALSE;
         retval = 1;
     }
     else if (!strcmp(argv[i], "-nomulticursor")) {
@@ -962,7 +953,6 @@ ddxProcessArgument(int argc, char *argv[], int i)
         retval = 1;
     }
     else if (!strcmp(argv[i], "-shadowfb")) {
-        dmxShadowFB = TRUE;
         retval = 1;
     }
     else if (!strcmp(argv[i], "-configfile")) {
diff --git a/hw/dmx/dmxpict.c b/hw/dmx/dmxpict.c
index b1177cf..c9762c2 100644
--- a/hw/dmx/dmxpict.c
+++ b/hw/dmx/dmxpict.c
@@ -141,10 +141,6 @@ dmxPictureInit(ScreenPtr pScreen, PictFormatPtr formats, int nformats)
     DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
     PictureScreenPtr ps;
 
-    /* The shadow framebuffer only relies on FB to be initialized */
-    if (dmxShadowFB)
-        return fbPictureInit(pScreen, formats, nformats);
-
     if (!miPictureInit(pScreen, formats, nformats))
         return FALSE;
 
diff --git a/hw/dmx/dmxscrinit.c b/hw/dmx/dmxscrinit.c
index 849ef16..963d3a9 100644
--- a/hw/dmx/dmxscrinit.c
+++ b/hw/dmx/dmxscrinit.c
@@ -41,7 +41,6 @@
 
 #include "dmx.h"
 #include "dmxsync.h"
-#include "dmxshadow.h"
 #include "dmxscrinit.h"
 #include "dmxcursor.h"
 #include "dmxgc.h"
@@ -159,37 +158,18 @@ dmxBEScreenInit(ScreenPtr pScreen)
 
     XMapWindow(dmxScreen->beDisplay, dmxScreen->scrnWin);
 
-    if (dmxShadowFB) {
-        mask = (GCFunction | GCPlaneMask | GCClipMask);
-        gcvals.function = GXcopy;
-        gcvals.plane_mask = AllPlanes;
-        gcvals.clip_mask = None;
-
-        dmxScreen->shadowGC = XCreateGC(dmxScreen->beDisplay,
-                                        dmxScreen->scrnWin, mask, &gcvals);
-
-        dmxScreen->shadowFBImage =
-            XCreateImage(dmxScreen->beDisplay,
-                         dmxScreen->beVisuals[dmxScreen->beDefVisualIndex].
-                         visual, dmxScreen->beDepth, ZPixmap, 0,
-                         (char *) dmxScreen->shadow, dmxScreen->scrnWidth,
-                         dmxScreen->scrnHeight, dmxScreen->beBPP,
-                         PixmapBytePad(dmxScreen->scrnWidth, dmxScreen->beBPP));
-    }
-    else {
-        /* Create default drawables (used during GC creation) */
-        for (i = 0; i < dmxScreen->beNumPixmapFormats; i++)
-            for (j = 0; j < dmxScreen->beNumDepths; j++)
-                if ((dmxScreen->bePixmapFormats[i].depth == 1) ||
-                    (dmxScreen->bePixmapFormats[i].depth ==
-                     dmxScreen->beDepths[j])) {
-                    dmxScreen->scrnDefDrawables[i] = (Drawable)
-                        XCreatePixmap(dmxScreen->beDisplay, dmxScreen->scrnWin,
-                                      1, 1,
-                                      dmxScreen->bePixmapFormats[i].depth);
-                    break;
-                }
-    }
+    /* Create default drawables (used during GC creation) */
+    for (i = 0; i < dmxScreen->beNumPixmapFormats; i++)
+	for (j = 0; j < dmxScreen->beNumDepths; j++)
+	    if ((dmxScreen->bePixmapFormats[i].depth == 1) ||
+		(dmxScreen->bePixmapFormats[i].depth ==
+		 dmxScreen->beDepths[j])) {
+		dmxScreen->scrnDefDrawables[i] = (Drawable)
+		    XCreatePixmap(dmxScreen->beDisplay, dmxScreen->scrnWin,
+				  1, 1,
+				  dmxScreen->bePixmapFormats[i].depth);
+		break;
+	    }
 }
 
 /** Initialize screen number \a pScreen->myNum. */
@@ -215,19 +195,12 @@ dmxScreenInit(ScreenPtr pScreen, int argc, char *argv[])
         dmxGeneration = serverGeneration;
     }
 
-    if (dmxShadowFB) {
-        dmxScreen->shadow = shadowAlloc(dmxScreen->scrnWidth,
-                                        dmxScreen->scrnHeight,
-                                        dmxScreen->beBPP);
-    }
-    else {
-        if (!dmxInitGC(pScreen))
-            return FALSE;
-        if (!dmxInitWindow(pScreen))
-            return FALSE;
-        if (!dmxInitPixmap(pScreen))
-            return FALSE;
-    }
+    if (!dmxInitGC(pScreen))
+	return FALSE;
+    if (!dmxInitWindow(pScreen))
+	return FALSE;
+    if (!dmxInitPixmap(pScreen))
+	return FALSE;
 
     /*
      * Initalise the visual types.  miSetVisualTypesAndMasks() requires
@@ -267,7 +240,7 @@ dmxScreenInit(ScreenPtr pScreen, int argc, char *argv[])
     }
 
     fbScreenInit(pScreen,
-                 dmxShadowFB ? dmxScreen->shadow : NULL,
+                 NULL,
                  dmxScreen->scrnWidth,
                  dmxScreen->scrnHeight,
                  dmxScreen->beXDPI,
@@ -278,22 +251,14 @@ dmxScreenInit(ScreenPtr pScreen, int argc, char *argv[])
     pScreen->GetWindowPixmap = NULL;
     pScreen->SetWindowPixmap = NULL;
 
-    if (dmxShadowFB && !shadowInit(pScreen, dmxShadowUpdateProc, NULL))
-        return FALSE;
+    MAXSCREENSALLOC(dmxCursorGeneration);
+    if (dmxCursorGeneration[pScreen->myNum] != serverGeneration) {
+	if (!(miPointerInitialize(pScreen,
+				  &dmxPointerSpriteFuncs,
+				  &dmxPointerCursorFuncs, FALSE)))
+	    return FALSE;
 
-    if (dmxShadowFB) {
-        miDCInitialize(pScreen, &dmxPointerCursorFuncs);
-    }
-    else {
-        MAXSCREENSALLOC(dmxCursorGeneration);
-        if (dmxCursorGeneration[pScreen->myNum] != serverGeneration) {
-            if (!(miPointerInitialize(pScreen,
-                                      &dmxPointerSpriteFuncs,
-                                      &dmxPointerCursorFuncs, FALSE)))
-                return FALSE;
-
-            dmxCursorGeneration[pScreen->myNum] = serverGeneration;
-        }
+	dmxCursorGeneration[pScreen->myNum] = serverGeneration;
     }
 
     DMX_WRAP(CloseScreen, dmxCloseScreen, dmxScreen, pScreen);
@@ -301,49 +266,47 @@ dmxScreenInit(ScreenPtr pScreen, int argc, char *argv[])
 
     dmxBEScreenInit(pScreen);
 
-    if (!dmxShadowFB) {
-        /* Wrap GC functions */
-        DMX_WRAP(CreateGC, dmxCreateGC, dmxScreen, pScreen);
-
-        /* Wrap Window functions */
-        DMX_WRAP(CreateWindow, dmxCreateWindow, dmxScreen, pScreen);
-        DMX_WRAP(DestroyWindow, dmxDestroyWindow, dmxScreen, pScreen);
-        DMX_WRAP(PositionWindow, dmxPositionWindow, dmxScreen, pScreen);
-        DMX_WRAP(ChangeWindowAttributes, dmxChangeWindowAttributes, dmxScreen,
-                 pScreen);
-        DMX_WRAP(RealizeWindow, dmxRealizeWindow, dmxScreen, pScreen);
-        DMX_WRAP(UnrealizeWindow, dmxUnrealizeWindow, dmxScreen, pScreen);
-        DMX_WRAP(RestackWindow, dmxRestackWindow, dmxScreen, pScreen);
-        DMX_WRAP(WindowExposures, dmxWindowExposures, dmxScreen, pScreen);
-        DMX_WRAP(CopyWindow, dmxCopyWindow, dmxScreen, pScreen);
-
-        DMX_WRAP(ResizeWindow, dmxResizeWindow, dmxScreen, pScreen);
-        DMX_WRAP(ReparentWindow, dmxReparentWindow, dmxScreen, pScreen);
-
-        DMX_WRAP(ChangeBorderWidth, dmxChangeBorderWidth, dmxScreen, pScreen);
-
-        /* Wrap Image functions */
-        DMX_WRAP(GetImage, dmxGetImage, dmxScreen, pScreen);
-        DMX_WRAP(GetSpans, dmxGetSpans, dmxScreen, pScreen);
-
-        /* Wrap Pixmap functions */
-        DMX_WRAP(CreatePixmap, dmxCreatePixmap, dmxScreen, pScreen);
-        DMX_WRAP(DestroyPixmap, dmxDestroyPixmap, dmxScreen, pScreen);
-        DMX_WRAP(BitmapToRegion, dmxBitmapToRegion, dmxScreen, pScreen);
-
-        /* Wrap Font functions */
-        DMX_WRAP(RealizeFont, dmxRealizeFont, dmxScreen, pScreen);
-        DMX_WRAP(UnrealizeFont, dmxUnrealizeFont, dmxScreen, pScreen);
-
-        /* Wrap Colormap functions */
-        DMX_WRAP(CreateColormap, dmxCreateColormap, dmxScreen, pScreen);
-        DMX_WRAP(DestroyColormap, dmxDestroyColormap, dmxScreen, pScreen);
-        DMX_WRAP(InstallColormap, dmxInstallColormap, dmxScreen, pScreen);
-        DMX_WRAP(StoreColors, dmxStoreColors, dmxScreen, pScreen);
-
-        /* Wrap Shape functions */
-        DMX_WRAP(SetShape, dmxSetShape, dmxScreen, pScreen);
-    }
+    /* Wrap GC functions */
+    DMX_WRAP(CreateGC, dmxCreateGC, dmxScreen, pScreen);
+
+    /* Wrap Window functions */
+    DMX_WRAP(CreateWindow, dmxCreateWindow, dmxScreen, pScreen);
+    DMX_WRAP(DestroyWindow, dmxDestroyWindow, dmxScreen, pScreen);
+    DMX_WRAP(PositionWindow, dmxPositionWindow, dmxScreen, pScreen);
+    DMX_WRAP(ChangeWindowAttributes, dmxChangeWindowAttributes, dmxScreen,
+	     pScreen);
+    DMX_WRAP(RealizeWindow, dmxRealizeWindow, dmxScreen, pScreen);
+    DMX_WRAP(UnrealizeWindow, dmxUnrealizeWindow, dmxScreen, pScreen);
+    DMX_WRAP(RestackWindow, dmxRestackWindow, dmxScreen, pScreen);
+    DMX_WRAP(WindowExposures, dmxWindowExposures, dmxScreen, pScreen);
+    DMX_WRAP(CopyWindow, dmxCopyWindow, dmxScreen, pScreen);
+
+    DMX_WRAP(ResizeWindow, dmxResizeWindow, dmxScreen, pScreen);
+    DMX_WRAP(ReparentWindow, dmxReparentWindow, dmxScreen, pScreen);
+
+    DMX_WRAP(ChangeBorderWidth, dmxChangeBorderWidth, dmxScreen, pScreen);
+
+    /* Wrap Image functions */
+    DMX_WRAP(GetImage, dmxGetImage, dmxScreen, pScreen);
+    DMX_WRAP(GetSpans, dmxGetSpans, dmxScreen, pScreen);
+
+    /* Wrap Pixmap functions */
+    DMX_WRAP(CreatePixmap, dmxCreatePixmap, dmxScreen, pScreen);
+    DMX_WRAP(DestroyPixmap, dmxDestroyPixmap, dmxScreen, pScreen);
+    DMX_WRAP(BitmapToRegion, dmxBitmapToRegion, dmxScreen, pScreen);
+
+    /* Wrap Font functions */
+    DMX_WRAP(RealizeFont, dmxRealizeFont, dmxScreen, pScreen);
+    DMX_WRAP(UnrealizeFont, dmxUnrealizeFont, dmxScreen, pScreen);
+
+    /* Wrap Colormap functions */
+    DMX_WRAP(CreateColormap, dmxCreateColormap, dmxScreen, pScreen);
+    DMX_WRAP(DestroyColormap, dmxDestroyColormap, dmxScreen, pScreen);
+    DMX_WRAP(InstallColormap, dmxInstallColormap, dmxScreen, pScreen);
+    DMX_WRAP(StoreColors, dmxStoreColors, dmxScreen, pScreen);
+
+    /* Wrap Shape functions */
+    DMX_WRAP(SetShape, dmxSetShape, dmxScreen, pScreen);
 
     if (!dmxCreateDefColormap(pScreen))
         return FALSE;
@@ -370,22 +333,13 @@ dmxBECloseScreen(ScreenPtr pScreen)
     XDestroyWindow(dmxScreen->beDisplay, dmxScreen->scrnWin);
     dmxScreen->scrnWin = (Window) 0;
 
-    if (dmxShadowFB) {
-        /* Free the shadow GC and image assocated with the back-end server */
-        XFreeGC(dmxScreen->beDisplay, dmxScreen->shadowGC);
-        dmxScreen->shadowGC = NULL;
-        XFree(dmxScreen->shadowFBImage);
-        dmxScreen->shadowFBImage = NULL;
-    }
-    else {
-        /* Free the default drawables */
-        for (i = 0; i < dmxScreen->beNumPixmapFormats; i++) {
-            if (dmxScreen->scrnDefDrawables[i]) {
-                XFreePixmap(dmxScreen->beDisplay,
-                            dmxScreen->scrnDefDrawables[i]);
-                dmxScreen->scrnDefDrawables[i] = (Drawable) 0;
-            }
-        }
+    /* Free the default drawables */
+    for (i = 0; i < dmxScreen->beNumPixmapFormats; i++) {
+	if (dmxScreen->scrnDefDrawables[i]) {
+	    XFreePixmap(dmxScreen->beDisplay,
+			dmxScreen->scrnDefDrawables[i]);
+	    dmxScreen->scrnDefDrawables[i] = (Drawable) 0;
+	}
     }
 
     /* Free resources allocated during initialization (in dmxinit.c) */
@@ -432,48 +386,41 @@ dmxCloseScreen(ScreenPtr pScreen)
         dmxResetFonts();
     }
 
-    if (dmxShadowFB) {
-        /* Free the shadow framebuffer */
-        free(dmxScreen->shadow);
-    }
-    else {
-
-        /* Unwrap Shape functions */
-        DMX_UNWRAP(SetShape, dmxScreen, pScreen);
+    /* Unwrap Shape functions */
+    DMX_UNWRAP(SetShape, dmxScreen, pScreen);
 
-        /* Unwrap the pScreen functions */
-        DMX_UNWRAP(CreateGC, dmxScreen, pScreen);
+    /* Unwrap the pScreen functions */
+    DMX_UNWRAP(CreateGC, dmxScreen, pScreen);
 
-        DMX_UNWRAP(CreateWindow, dmxScreen, pScreen);
-        DMX_UNWRAP(DestroyWindow, dmxScreen, pScreen);
-        DMX_UNWRAP(PositionWindow, dmxScreen, pScreen);
-        DMX_UNWRAP(ChangeWindowAttributes, dmxScreen, pScreen);
-        DMX_UNWRAP(RealizeWindow, dmxScreen, pScreen);
-        DMX_UNWRAP(UnrealizeWindow, dmxScreen, pScreen);
-        DMX_UNWRAP(RestackWindow, dmxScreen, pScreen);
-        DMX_UNWRAP(WindowExposures, dmxScreen, pScreen);
-        DMX_UNWRAP(CopyWindow, dmxScreen, pScreen);
+    DMX_UNWRAP(CreateWindow, dmxScreen, pScreen);
+    DMX_UNWRAP(DestroyWindow, dmxScreen, pScreen);
+    DMX_UNWRAP(PositionWindow, dmxScreen, pScreen);
+    DMX_UNWRAP(ChangeWindowAttributes, dmxScreen, pScreen);
+    DMX_UNWRAP(RealizeWindow, dmxScreen, pScreen);
+    DMX_UNWRAP(UnrealizeWindow, dmxScreen, pScreen);
+    DMX_UNWRAP(RestackWindow, dmxScreen, pScreen);
+    DMX_UNWRAP(WindowExposures, dmxScreen, pScreen);
+    DMX_UNWRAP(CopyWindow, dmxScreen, pScreen);
 
-        DMX_UNWRAP(ResizeWindow, dmxScreen, pScreen);
-        DMX_UNWRAP(ReparentWindow, dmxScreen, pScreen);
+    DMX_UNWRAP(ResizeWindow, dmxScreen, pScreen);
+    DMX_UNWRAP(ReparentWindow, dmxScreen, pScreen);
 
-        DMX_UNWRAP(ChangeBorderWidth, dmxScreen, pScreen);
+    DMX_UNWRAP(ChangeBorderWidth, dmxScreen, pScreen);
 
-        DMX_UNWRAP(GetImage, dmxScreen, pScreen);
-        DMX_UNWRAP(GetSpans, dmxScreen, pScreen);
+    DMX_UNWRAP(GetImage, dmxScreen, pScreen);
+    DMX_UNWRAP(GetSpans, dmxScreen, pScreen);
 
-        DMX_UNWRAP(CreatePixmap, dmxScreen, pScreen);
-        DMX_UNWRAP(DestroyPixmap, dmxScreen, pScreen);
-        DMX_UNWRAP(BitmapToRegion, dmxScreen, pScreen);
+    DMX_UNWRAP(CreatePixmap, dmxScreen, pScreen);
+    DMX_UNWRAP(DestroyPixmap, dmxScreen, pScreen);
+    DMX_UNWRAP(BitmapToRegion, dmxScreen, pScreen);
 
-        DMX_UNWRAP(RealizeFont, dmxScreen, pScreen);
-        DMX_UNWRAP(UnrealizeFont, dmxScreen, pScreen);
+    DMX_UNWRAP(RealizeFont, dmxScreen, pScreen);
+    DMX_UNWRAP(UnrealizeFont, dmxScreen, pScreen);
 
-        DMX_UNWRAP(CreateColormap, dmxScreen, pScreen);
-        DMX_UNWRAP(DestroyColormap, dmxScreen, pScreen);
-        DMX_UNWRAP(InstallColormap, dmxScreen, pScreen);
-        DMX_UNWRAP(StoreColors, dmxScreen, pScreen);
-    }
+    DMX_UNWRAP(CreateColormap, dmxScreen, pScreen);
+    DMX_UNWRAP(DestroyColormap, dmxScreen, pScreen);
+    DMX_UNWRAP(InstallColormap, dmxScreen, pScreen);
+    DMX_UNWRAP(StoreColors, dmxScreen, pScreen);
 
     DMX_UNWRAP(SaveScreen, dmxScreen, pScreen);
 
diff --git a/hw/dmx/dmxshadow.c b/hw/dmx/dmxshadow.c
deleted file mode 100644
index 9b4bafc..0000000
--- a/hw/dmx/dmxshadow.c
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright 2001 Red Hat Inc., Durham, North Carolina.
- *
- * 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 on 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
- * NON-INFRINGEMENT.  IN NO EVENT SHALL RED HAT AND/OR THEIR 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 <kem at redhat.com>
- *   David H. Dawes <dawes at xfree86.org>
- *
- */
-
-#ifdef HAVE_DMX_CONFIG_H
-#include <dmx-config.h>
-#endif
-
-#include "dmx.h"
-#include "dmxsync.h"
-#include "dmxshadow.h"
-
-/** \file
- * This file provides support for the shadow frame buffer. */
-
-/** Update the screen from the shadow frame buffer. */
-void
-dmxShadowUpdateProc(ScreenPtr pScreen, shadowBufPtr pBuf)
-{
-    RegionPtr damage = &pBuf->damage;
-    int nbox = RegionNumRects(damage);
-    BoxPtr pbox = RegionRects(damage);
-    DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
-
-    if (!dmxScreen->beDisplay)
-        return;
-
-    while (nbox--) {
-        XPutImage(dmxScreen->beDisplay,
-                  dmxScreen->scrnWin,
-                  dmxScreen->shadowGC,
-                  dmxScreen->shadowFBImage,
-                  pbox->x1, pbox->y1,
-                  pbox->x1, pbox->y1, pbox->x2 - pbox->x1, pbox->y2 - pbox->y1);
-
-        pbox++;
-    }
-
-    dmxSync(dmxScreen, FALSE);
-}
diff --git a/hw/dmx/dmxshadow.h b/hw/dmx/dmxshadow.h
deleted file mode 100644
index 081b4d1..0000000
--- a/hw/dmx/dmxshadow.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2001 Red Hat Inc., Durham, North Carolina.
- *
- * 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 on 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
- * NON-INFRINGEMENT.  IN NO EVENT SHALL RED HAT AND/OR THEIR 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 <kem at redhat.com>
- *   David H. Dawes <dawes at xfree86.org>
- *
- */
-
-/** \file
- * Interface for shadow framebuffer support.  \see dmxshadow.c */
-
-#ifndef DMXSHADOW_H
-#define DMXSHADOW_H
-
-#include "shadow.h"
-#include "scrnintstr.h"
-
-extern void dmxShadowUpdateProc(ScreenPtr pScreen, shadowBufPtr pBuf);
-
-#endif                          /* DMXSHADOW_H */
diff --git a/hw/dmx/input/dmxcommon.c b/hw/dmx/input/dmxcommon.c
index 5f25e88..db558b5 100644
--- a/hw/dmx/input/dmxcommon.c
+++ b/hw/dmx/input/dmxcommon.c
@@ -502,11 +502,6 @@ dmxCommonMouOn(DevicePtr pDev)
     GETDMXINPUTFROMPRIV;
 
     priv->eventMask |= DMX_POINTER_EVENT_MASK;
-    if (dmxShadowFB) {
-        XWarpPointer(priv->display, priv->window, priv->window,
-                     0, 0, 0, 0, priv->initPointerX, priv->initPointerY);
-        dmxSync(&dmxScreens[dmxInput->scrnIdx], TRUE);
-    }
     if (!priv->be) {
         XSelectInput(priv->display, priv->window, priv->eventMask);
         AddEnabledDevice(XConnectionNumber(priv->display));
diff --git a/hw/dmx/man/Xdmx.man b/hw/dmx/man/Xdmx.man
index bbce856..6b3feb1 100644
--- a/hw/dmx/man/Xdmx.man
+++ b/hw/dmx/man/Xdmx.man
@@ -179,16 +179,6 @@ will switch to another VC in local (raw) mode.
 .RE
 .sp
 .TP 8
-.BI "-shadowfb"
-This option turns on (legacy) support for the shadow frame buffer.
-.sp
-.TP 8
-.BI "-noshadowfb"
-This option turns off (legacy) support for the shadow frame buffer.
-Note that this option has been deprecated and will be removed in the
-next release.
-.sp
-.TP 8
 .BI "-nomulticursor"
 This option turns off support for displaying multiple cursors on
 overlapped back-end displays.  This option is available for testing and
commit 19d3a7cb5db3188210830efa746987ba50d839e9
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Oct 16 14:56:17 2012 -0400

    dix: Remove a dead parameter from DoGetImage
    
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/dix/dispatch.c b/dix/dispatch.c
index 71fda48..4fecfea 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -1974,7 +1974,7 @@ ProcPutImage(ClientPtr client)
 static int
 DoGetImage(ClientPtr client, int format, Drawable drawable,
            int x, int y, int width, int height,
-           Mask planemask, xGetImageReply ** im_return)
+           Mask planemask)
 {
     DrawablePtr pDraw, pBoundingDraw;
     int nlines, linesPerBuf, rc;
@@ -2074,46 +2074,32 @@ DoGetImage(ClientPtr client, int format, Drawable drawable,
 
     xgi.length = length;
 
-    if (im_return) {
-        pBuf = calloc(1, sz_xGetImageReply + length);
-        if (!pBuf)
-            return BadAlloc;
-        if (widthBytesLine == 0)
-            linesPerBuf = 0;
-        else
+    xgi.length = bytes_to_int32(xgi.length);
+    if (widthBytesLine == 0 || height == 0)
+        linesPerBuf = 0;
+    else if (widthBytesLine >= IMAGE_BUFSIZE)
+        linesPerBuf = 1;
+    else {
+        linesPerBuf = IMAGE_BUFSIZE / widthBytesLine;
+        if (linesPerBuf > height)
             linesPerBuf = height;
-        *im_return = (xGetImageReply *) pBuf;
-        *(xGetImageReply *) pBuf = xgi;
-        pBuf += sz_xGetImageReply;
     }
-    else {
-        xgi.length = bytes_to_int32(xgi.length);
-        if (widthBytesLine == 0 || height == 0)
-            linesPerBuf = 0;
-        else if (widthBytesLine >= IMAGE_BUFSIZE)
-            linesPerBuf = 1;
-        else {
-            linesPerBuf = IMAGE_BUFSIZE / widthBytesLine;
-            if (linesPerBuf > height)
-                linesPerBuf = height;
+    length = linesPerBuf * widthBytesLine;
+    if (linesPerBuf < height) {
+        /* we have to make sure intermediate buffers don't need padding */
+        while ((linesPerBuf > 1) &&
+               (length & ((1L << LOG2_BYTES_PER_SCANLINE_PAD) - 1))) {
+            linesPerBuf--;
+            length -= widthBytesLine;
         }
-        length = linesPerBuf * widthBytesLine;
-        if (linesPerBuf < height) {
-            /* we have to make sure intermediate buffers don't need padding */
-            while ((linesPerBuf > 1) &&
-                   (length & ((1L << LOG2_BYTES_PER_SCANLINE_PAD) - 1))) {
-                linesPerBuf--;
-                length -= widthBytesLine;
-            }
-            while (length & ((1L << LOG2_BYTES_PER_SCANLINE_PAD) - 1)) {
-                linesPerBuf++;
-                length += widthBytesLine;
-            }
+        while (length & ((1L << LOG2_BYTES_PER_SCANLINE_PAD) - 1)) {
+            linesPerBuf++;
+            length += widthBytesLine;
         }
-        if (!(pBuf = calloc(1, length)))
-            return BadAlloc;
-        WriteReplyToClient(client, sizeof(xGetImageReply), &xgi);
     }
+    if (!(pBuf = calloc(1, length)))
+        return BadAlloc;
+    WriteReplyToClient(client, sizeof(xGetImageReply), &xgi);
 
     if (pDraw->type == DRAWABLE_WINDOW) {
         pVisibleRegion = NotClippedByChildren((WindowPtr) pDraw);
@@ -2142,13 +2128,10 @@ DoGetImage(ClientPtr client, int format, Drawable drawable,
 
             /* Note that this is NOT a call to WriteSwappedDataToClient,
                as we do NOT byte swap */
-            if (!im_return) {
-                ReformatImage(pBuf, (int) (nlines * widthBytesLine),
-                              BitsPerPixel(pDraw->depth), ClientOrder(client));
+            ReformatImage(pBuf, (int) (nlines * widthBytesLine),
+                          BitsPerPixel(pDraw->depth), ClientOrder(client));
 
-/* Don't split me, gcc pukes when you do */
-                WriteToClient(client, (int) (nlines * widthBytesLine), pBuf);
-            }
+            WriteToClient(client, (int) (nlines * widthBytesLine), pBuf);
             linesDone += nlines;
         }
     }
@@ -2173,18 +2156,10 @@ DoGetImage(ClientPtr client, int format, Drawable drawable,
 
                     /* Note: NOT a call to WriteSwappedDataToClient,
                        as we do NOT byte swap */
-                    if (im_return) {
-                        pBuf += nlines * widthBytesLine;
-                    }
-                    else {
-                        ReformatImage(pBuf,
-                                      (int) (nlines * widthBytesLine),
-                                      1, ClientOrder(client));
-
-/* Don't split me, gcc pukes when you do */
-                        WriteToClient(client, (int) (nlines * widthBytesLine),
-				      pBuf);
-                    }
+                    ReformatImage(pBuf, (int) (nlines * widthBytesLine),
+                                  1, ClientOrder(client));
+
+                    WriteToClient(client, (int)(nlines * widthBytesLine), pBuf);
                     linesDone += nlines;
                 }
             }
@@ -2192,8 +2167,7 @@ DoGetImage(ClientPtr client, int format, Drawable drawable,
     }
     if (pVisibleRegion)
         RegionDestroy(pVisibleRegion);
-    if (!im_return)
-        free(pBuf);
+    free(pBuf);
     return Success;
 }
 
@@ -2207,7 +2181,7 @@ ProcGetImage(ClientPtr client)
     return DoGetImage(client, stuff->format, stuff->drawable,
                       stuff->x, stuff->y,
                       (int) stuff->width, (int) stuff->height,
-                      stuff->planeMask, (xGetImageReply **) NULL);
+                      stuff->planeMask);
 }
 
 int
commit 4dca026880da90cff9734cf5787c5b57c02e7310
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Oct 16 14:56:16 2012 -0400

    mipointer: Remove EnqueueEvent from miPointerScreenFuncRec
    
    No DDX overrode this, and we never actually called through that slot
    anyway.
    
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/dmx/dmxcursor.c b/hw/dmx/dmxcursor.c
index 5f41536..70f2bc4 100644
--- a/hw/dmx/dmxcursor.c
+++ b/hw/dmx/dmxcursor.c
@@ -197,7 +197,6 @@ miPointerScreenFuncRec dmxPointerCursorFuncs = {
     dmxCursorOffScreen,
     dmxCrossScreen,
     dmxWarpCursor,
-    NULL,
 };
 
 /** Create a list of screens that we'll manipulate. */
diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index 1f32ea1..0ee2cf3 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -823,7 +823,6 @@ miPointerScreenFuncRec ephyrPointerScreenFuncs = {
     ephyrCursorOffScreen,
     ephyrCrossScreen,
     ephyrWarpCursor,
-    NULL,
 };
 
 #ifdef XF86DRI
diff --git a/hw/xfree86/common/xf86Cursor.c b/hw/xfree86/common/xf86Cursor.c
index 973bdd3..7d0776e 100644
--- a/hw/xfree86/common/xf86Cursor.c
+++ b/hw/xfree86/common/xf86Cursor.c
@@ -72,8 +72,6 @@ static miPointerScreenFuncRec xf86PointerScreenFuncs = {
     xf86CursorOffScreen,
     xf86CrossScreen,
     xf86WarpCursor,
-    /* let miPointerInitialize take care of these */
-    NULL,
 };
 
 static xf86ScreenLayoutRec xf86ScreenLayout[MAXSCREENS];
diff --git a/hw/xquartz/xpr/xprCursor.c b/hw/xquartz/xpr/xprCursor.c
index 6e617c7..4168f7c 100644
--- a/hw/xquartz/xpr/xprCursor.c
+++ b/hw/xquartz/xpr/xprCursor.c
@@ -305,7 +305,6 @@ static miPointerScreenFuncRec quartzScreenFuncsRec = {
     QuartzCursorOffScreen,
     QuartzCrossScreen,
     QuartzWarpCursor,
-    NULL,
 };
 
 /*
diff --git a/mi/mipointer.c b/mi/mipointer.c
index 0b55c26..f07c5db 100644
--- a/mi/mipointer.c
+++ b/mi/mipointer.c
@@ -118,11 +118,6 @@ miPointerInitialize(ScreenPtr pScreen,
         return FALSE;
     pScreenPriv->spriteFuncs = spriteFuncs;
     pScreenPriv->screenFuncs = screenFuncs;
-    /*
-     * check for uninitialized methods
-     */
-    if (!screenFuncs->EnqueueEvent)
-        screenFuncs->EnqueueEvent = mieqEnqueue;
     pScreenPriv->waitForUpdate = waitForUpdate;
     pScreenPriv->showTransparent = FALSE;
     pScreenPriv->CloseScreen = pScreen->CloseScreen;
diff --git a/mi/mipointer.h b/mi/mipointer.h
index 39ba83b..33261ab 100644
--- a/mi/mipointer.h
+++ b/mi/mipointer.h
@@ -71,9 +71,6 @@ typedef struct _miPointerScreenFuncRec {
                         int /* x */ ,
                         int     /* y */
         );
-    void (*EnqueueEvent) (DeviceIntPtr /* pDev */ ,
-                          InternalEvent *       /* event */
-        );
 } miPointerScreenFuncRec, *miPointerScreenFuncPtr;
 
 extern _X_EXPORT Bool miDCInitialize(ScreenPtr /*pScreen */ ,
commit ad076dc6e82019defa422500710b3b42c6309e39
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Oct 16 14:56:15 2012 -0400

    mipointer: Flatten calls to mieqSwitchScreen
    
    No DDX was overriding this.
    
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/dmx/dmxcursor.c b/hw/dmx/dmxcursor.c
index 35aca81..5f41536 100644
--- a/hw/dmx/dmxcursor.c
+++ b/hw/dmx/dmxcursor.c
@@ -198,7 +198,6 @@ miPointerScreenFuncRec dmxPointerCursorFuncs = {
     dmxCrossScreen,
     dmxWarpCursor,
     NULL,
-    NULL,
 };
 
 /** Create a list of screens that we'll manipulate. */
diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index 02d4970..1f32ea1 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -824,7 +824,6 @@ miPointerScreenFuncRec ephyrPointerScreenFuncs = {
     ephyrCrossScreen,
     ephyrWarpCursor,
     NULL,
-    NULL
 };
 
 #ifdef XF86DRI
diff --git a/hw/xfree86/common/xf86Cursor.c b/hw/xfree86/common/xf86Cursor.c
index 65a9e82..973bdd3 100644
--- a/hw/xfree86/common/xf86Cursor.c
+++ b/hw/xfree86/common/xf86Cursor.c
@@ -74,7 +74,6 @@ static miPointerScreenFuncRec xf86PointerScreenFuncs = {
     xf86WarpCursor,
     /* let miPointerInitialize take care of these */
     NULL,
-    NULL
 };
 
 static xf86ScreenLayoutRec xf86ScreenLayout[MAXSCREENS];
diff --git a/hw/xquartz/xpr/xprCursor.c b/hw/xquartz/xpr/xprCursor.c
index 0392a46..6e617c7 100644
--- a/hw/xquartz/xpr/xprCursor.c
+++ b/hw/xquartz/xpr/xprCursor.c
@@ -306,7 +306,6 @@ static miPointerScreenFuncRec quartzScreenFuncsRec = {
     QuartzCrossScreen,
     QuartzWarpCursor,
     NULL,
-    NULL
 };
 
 /*
diff --git a/mi/mipointer.c b/mi/mipointer.c
index b8503f4..0b55c26 100644
--- a/mi/mipointer.c
+++ b/mi/mipointer.c
@@ -123,8 +123,6 @@ miPointerInitialize(ScreenPtr pScreen,
      */
     if (!screenFuncs->EnqueueEvent)
         screenFuncs->EnqueueEvent = mieqEnqueue;
-    if (!screenFuncs->NewEventScreen)
-        screenFuncs->NewEventScreen = mieqSwitchScreen;
     pScreenPriv->waitForUpdate = waitForUpdate;
     pScreenPriv->showTransparent = FALSE;
     pScreenPriv->CloseScreen = pScreen->CloseScreen;
@@ -363,7 +361,7 @@ miPointerWarpCursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y)
     pPointer = MIPOINTER(pDev);
 
     if (pPointer->pScreen != pScreen) {
-        (*pScreenPriv->screenFuncs->NewEventScreen) (pDev, pScreen, TRUE);
+        mieqSwitchScreen(pDev, pScreen, TRUE);
         changedScreen = TRUE;
     }
 
@@ -480,7 +478,7 @@ miPointerSetScreen(DeviceIntPtr pDev, int screen_no, int x, int y)
 
     pScreen = screenInfo.screens[screen_no];
     pScreenPriv = GetScreenPrivate(pScreen);
-    (*pScreenPriv->screenFuncs->NewEventScreen) (pDev, pScreen, FALSE);
+    mieqSwitchScreen(pDev, pScreen, FALSE);
     NewCurrentScreen(pDev, pScreen, x, y);
 
     pPointer->limits.x2 = pScreen->width;
@@ -617,8 +615,7 @@ miPointerSetPosition(DeviceIntPtr pDev, int mode, double *screenx,
             (*pScreenPriv->screenFuncs->CursorOffScreen) (&newScreen, &x, &y);
             if (newScreen != pScreen) {
                 pScreen = newScreen;
-                (*pScreenPriv->screenFuncs->NewEventScreen) (pDev, pScreen,
-                                                             FALSE);
+                mieqSwitchScreen(pDev, pScreen, FALSE);
                 /* Smash the confine to the new screen */
                 pPointer->limits.x2 = pScreen->width;
                 pPointer->limits.y2 = pScreen->height;
diff --git a/mi/mipointer.h b/mi/mipointer.h
index f89dff3..39ba83b 100644
--- a/mi/mipointer.h
+++ b/mi/mipointer.h
@@ -74,10 +74,6 @@ typedef struct _miPointerScreenFuncRec {
     void (*EnqueueEvent) (DeviceIntPtr /* pDev */ ,
                           InternalEvent *       /* event */
         );
-    void (*NewEventScreen) (DeviceIntPtr /* pDev */ ,
-                            ScreenPtr /* pScr */ ,
-                            Bool        /* set_dequeue_screen */
-        );
 } miPointerScreenFuncRec, *miPointerScreenFuncPtr;
 
 extern _X_EXPORT Bool miDCInitialize(ScreenPtr /*pScreen */ ,
commit e2b14a1d3bb27e86ff1d7aaf59af850d06263ef5
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Oct 16 14:56:14 2012 -0400

    os: Factor out some common code in input buffer handling
    
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/os/io.c b/os/io.c
index d34bc39..3800366 100644
--- a/os/io.c
+++ b/os/io.c
@@ -206,27 +206,17 @@ YieldControlDeath(void)
     timesThisConnection = 0;
 }
 
-int
-ReadRequestFromClient(ClientPtr client)
+/* If an input buffer was empty, either free it if it is too big or link it
+ * into our list of free input buffers.  This means that different clients can
+ * share the same input buffer (at different times).  This was done to save
+ * memory.
+ */
+static void
+NextAvailableInput(OsCommPtr oc)
 {
-    OsCommPtr oc = (OsCommPtr) client->osPrivate;
-    ConnectionInputPtr oci = oc->input;
-    int fd = oc->fd;
-    unsigned int gotnow, needed;
-    int result;
-    register xReq *request;
-    Bool need_header;
-    Bool move_header;
-
-    /* If an input buffer was empty, either free it if it is too big
-     * or link it into our list of free input buffers.  This means that
-     * different clients can share the same input buffer (at different
-     * times).  This was done to save memory.
-     */
-
     if (AvailableInput) {
         if (AvailableInput != oc) {
-            register ConnectionInputPtr aci = AvailableInput->input;
+            ConnectionInputPtr aci = AvailableInput->input;
 
             if (aci->size > BUFWATERMARK) {
                 free(aci->buffer);
@@ -236,10 +226,25 @@ ReadRequestFromClient(ClientPtr client)
                 aci->next = FreeInputs;
                 FreeInputs = aci;
             }
-            AvailableInput->input = (ConnectionInputPtr) NULL;
+            AvailableInput->input = NULL;
         }
-        AvailableInput = (OsCommPtr) NULL;
+        AvailableInput = NULL;
     }
+}
+
+int
+ReadRequestFromClient(ClientPtr client)
+{
+    OsCommPtr oc = (OsCommPtr) client->osPrivate;
+    ConnectionInputPtr oci = oc->input;
+    int fd = oc->fd;
+    unsigned int gotnow, needed;
+    int result;
+    register xReq *request;
+    Bool need_header;
+    Bool move_header;
+
+    NextAvailableInput(oc);
 
     /* make sure we have an input buffer */
 
@@ -494,22 +499,8 @@ InsertFakeRequest(ClientPtr client, char *data, int count)
     int fd = oc->fd;
     int gotnow, moveup;
 
-    if (AvailableInput) {
-        if (AvailableInput != oc) {
-            ConnectionInputPtr aci = AvailableInput->input;
+    NextAvailableInput(oc);
 
-            if (aci->size > BUFWATERMARK) {
-                free(aci->buffer);
-                free(aci);
-            }
-            else {
-                aci->next = FreeInputs;
-                FreeInputs = aci;
-            }
-            AvailableInput->input = (ConnectionInputPtr) NULL;
-        }
-        AvailableInput = (OsCommPtr) NULL;
-    }
     if (!oci) {
         if ((oci = FreeInputs))
             FreeInputs = oci->next;
commit 65fca558848acd907483d3c85c7cd4db5560f1b4
Author: Radek Doulik <rodo at novell.com>
Date:   Tue Aug 13 08:45:47 2013 +0200

    xnest: Ignore GetImage() error in xnestGetImage()
    
    When an Xnest instance is not viewable it will crash when a client in
    that instance calls GetImage. This is because the Xnest server will
    itself receives a BadMatch error.
    This patch ignores the error. The application which has requested the
    image will receive garbage - this however is fully legal according
    to the specs as obscured areas will always contain garbage if there
    isn't some sort of backing store as discussed in
    https://bugs.freedesktop.org/show_bug.cgi?id=9488
    The applied patch is a version from Dadek Doulik.
    
    v2: Call XSync() before changing error handlers as suggested by
        Daniel Stone <daniel at fooishbar.org>.
    
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Signed-off-by: Egbert Eich <eich at freedesktop.org>

diff --git a/hw/xnest/GCOps.c b/hw/xnest/GCOps.c
index e26a136..7b1956d 100644
--- a/hw/xnest/GCOps.c
+++ b/hw/xnest/GCOps.c
@@ -94,15 +94,29 @@ xnestPutImage(DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y,
     }
 }
 
+static int
+xnestIgnoreErrorHandler (Display     *display,
+                         XErrorEvent *event)
+{
+    return False; /* return value is ignored */
+}
+
 void
 xnestGetImage(DrawablePtr pDrawable, int x, int y, int w, int h,
               unsigned int format, unsigned long planeMask, char *pImage)
 {
     XImage *ximage;
     int length;
+    int (*old_handler)(Display*, XErrorEvent*);
+
+    /* we may get BadMatch error when xnest window is minimized */
+    XSync(xnestDisplay, False);
+    old_handler = XSetErrorHandler (xnestIgnoreErrorHandler);
 
     ximage = XGetImage(xnestDisplay, xnestDrawable(pDrawable),
                        x, y, w, h, planeMask, format);
+    XSync(xnestDisplay, False);
+    XSetErrorHandler(old_handler);
 
     if (ximage) {
         length = ximage->bytes_per_line * ximage->height;
commit b902c8abb6d03e68c93e13881a350523b5ac900c
Author: Michal Srb <msrb at novell.com>
Date:   Tue Aug 6 16:56:53 2013 +0200

    Xnest: Implement xnestModifyPixmapHeader
    
    Xnest variant of ModifyPixmapHeader that creates new Pixmap in parent X
    server if it's size is modified from 0x0 to anything bigger.
    
    xnestCreatePixmap doesn't create pixmap in parent X server if it has
    dimensions 0x0. If it is later resized and accessed, Xnest will be
    aborted with BadDrawable error from parent X server because it will
    use XID 0. This happens with ScratchPixmap, for example as used from
    XaceCensorImage. Applications using XACE crash Xnest.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xnest/Pixmap.c b/hw/xnest/Pixmap.c
index 13e1610..2902acd 100644
--- a/hw/xnest/Pixmap.c
+++ b/hw/xnest/Pixmap.c
@@ -78,6 +78,21 @@ xnestDestroyPixmap(PixmapPtr pPixmap)
     return TRUE;
 }
 
+Bool
+xnestModifyPixmapHeader(PixmapPtr pPixmap, int width, int height, int depth,
+                        int bitsPerPixel, int devKind, pointer pPixData)
+{
+  if(!xnestPixmapPriv(pPixmap)->pixmap && width > 0 && height > 0) {
+    xnestPixmapPriv(pPixmap)->pixmap =
+        XCreatePixmap(xnestDisplay,
+                      xnestDefaultWindows[pPixmap->drawable.pScreen->myNum],
+                      width, height, depth);
+  }
+
+  return miModifyPixmapHeader(pPixmap, width, height, depth,
+                              bitsPerPixel, devKind, pPixData);
+}
+
 RegionPtr
 xnestPixmapToRegion(PixmapPtr pPixmap)
 {
diff --git a/hw/xnest/Screen.c b/hw/xnest/Screen.c
index 58b5a11..abb4d37 100644
--- a/hw/xnest/Screen.c
+++ b/hw/xnest/Screen.c
@@ -282,6 +282,7 @@ xnestOpenScreen(ScreenPtr pScreen, int argc, char *argv[])
 
     pScreen->CreatePixmap = xnestCreatePixmap;
     pScreen->DestroyPixmap = xnestDestroyPixmap;
+    pScreen->ModifyPixmapHeader = xnestModifyPixmapHeader;
 
     /* Font procedures */
 
diff --git a/hw/xnest/XNPixmap.h b/hw/xnest/XNPixmap.h
index 268ba1e..5b2e796 100644
--- a/hw/xnest/XNPixmap.h
+++ b/hw/xnest/XNPixmap.h
@@ -33,6 +33,8 @@ typedef struct {
 PixmapPtr xnestCreatePixmap(ScreenPtr pScreen, int width, int height,
                             int depth, unsigned usage_hint);
 Bool xnestDestroyPixmap(PixmapPtr pPixmap);
+Bool xnestModifyPixmapHeader(PixmapPtr pPixmap, int width, int height, int depth,
+                             int bitsPerPixel, int devKind, pointer pPixData);
 RegionPtr xnestPixmapToRegion(PixmapPtr pPixmap);
 
 #endif                          /* XNESTPIXMAP_H */
commit 132507eba93e4dfd466d5c30c9b818cdc6f8536e
Author: Peter Harris <pharris at opentext.com>
Date:   Mon Jul 15 19:44:45 2013 -0400

    security: Don't count RetainPermanent clients twice
    
    If a RetainPermanent client is subsequently killed by a KillClient
    request, the reference count is decremented twice. This can cause the
    server to prematurely kill other clients using the same Authorization.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Peter Harris <pharris at opentext.com>

diff --git a/Xext/security.c b/Xext/security.c
index 6cc9aa0..7bf6cc4 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -57,8 +57,9 @@ static DevPrivateKeyRec stateKeyRec;
 
 /* This is what we store as client security state */
 typedef struct {
-    int haveState;
-    unsigned int trustLevel;
+    unsigned int haveState  :1;
+    unsigned int live       :1;
+    unsigned int trustLevel :2;
     XID authId;
 } SecurityStateRec;
 
@@ -141,6 +142,7 @@ SecurityLabelInitial(void)
     state = dixLookupPrivate(&serverClient->devPrivates, stateKey);
     state->trustLevel = XSecurityClientTrusted;
     state->haveState = TRUE;
+    state->live = FALSE;
 }
 
 /*
@@ -953,6 +955,7 @@ SecurityClientState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
         state->trustLevel = XSecurityClientTrusted;
         state->authId = None;
         state->haveState = TRUE;
+        state->live = FALSE;
         break;
 
     case ClientStateRunning:
@@ -963,6 +966,7 @@ SecurityClientState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
         if (rc == Success) {
             /* it is a generated authorization */
             pAuth->refcnt++;
+            state->live = TRUE;
             if (pAuth->refcnt == 1 && pAuth->timer)
                 TimerCancel(pAuth->timer);
 
@@ -975,9 +979,10 @@ SecurityClientState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
         rc = dixLookupResourceByType((pointer *) &pAuth, state->authId,
                                      SecurityAuthorizationResType, serverClient,
                                      DixGetAttrAccess);
-        if (rc == Success) {
+        if (rc == Success && state->live) {
             /* it is a generated authorization */
             pAuth->refcnt--;
+            state->live = FALSE;
             if (pAuth->refcnt == 0)
                 SecurityStartAuthorizationTimer(pAuth);
         }
commit 20c2a3bcb11b5baf564e2c73a477ba23f5ae2b10
Author: Peter Harris <pharris at opentext.com>
Date:   Mon Jul 15 19:44:29 2013 -0400

    mi: Avoid stack smash when drawing dashed lines
    
    X.org Bug 54013 <https://bugs.freedesktop.org/show_bug.cgi?id=54013>
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Peter Harris <pharris at opentext.com>

diff --git a/mi/miwideline.c b/mi/miwideline.c
index ca18f15..b76e7a8 100644
--- a/mi/miwideline.c
+++ b/mi/miwideline.c
@@ -994,7 +994,7 @@ miLineProjectingCap(DrawablePtr pDrawable, GCPtr pGC, unsigned long pixel,
 {
     int xorgi = 0, yorgi = 0;
     int lw;
-    PolyEdgeRec lefts[2], rights[2];
+    PolyEdgeRec lefts[4], rights[4];
     int lefty, righty, topy, bottomy;
     PolyEdgePtr left, right;
     PolyEdgePtr top, bottom;
@@ -1166,7 +1166,7 @@ miWideSegment(DrawablePtr pDrawable,
     PolyEdgePtr top, bottom;
     int lefty, righty, topy, bottomy;
     int signdx;
-    PolyEdgeRec lefts[2], rights[2];
+    PolyEdgeRec lefts[4], rights[4];
     LineFacePtr tface;
     int lw = pGC->lineWidth;
 
@@ -1520,7 +1520,7 @@ miWideDashSegment(DrawablePtr pDrawable,
     PolyVertexRec vertices[4];
     PolyVertexRec saveRight, saveBottom;
     PolySlopeRec slopes[4];
-    PolyEdgeRec left[2], right[2];
+    PolyEdgeRec left[4], right[4];
     LineFaceRec lcapFace, rcapFace;
     int nleft, nright;
     int h;
commit 9bf46610a9d20962854016032de4567974e87957
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Jun 21 22:58:31 2013 +0100

    os: Immediately queue initial WriteToClient
    
    If we immediately put the WriteToClient() buffer into the socket's write
    queue, not only do we benefit from sending the response back to client
    earlier, but we also avoid the overhead of copying the data into our own
    staging buffer and causing extra work in the next select(). The write is
    effectively free as typically we may only send one reply per client per
    select() call, so the cost of the FlushClient() is the same.
    
    shmget10:   26400 -> 110000
    getimage10: 25000 -> 108000
    
    shmget500:   3160 -> 13500
    getimage500: 1000 -> 1010
    
    The knock-on effect is that on a mostly idle composited desktop, the CPU
    overhead is dominated by the memmove in WriteToClient, which is in turn
    eliminated by this patch.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/os/io.c b/os/io.c
index 0d980ab..d34bc39 100644
--- a/os/io.c
+++ b/os/io.c
@@ -814,7 +814,7 @@ WriteToClient(ClientPtr who, int count, const void *__buf)
         }
     }
 #endif
-    if (oco->count + count + padBytes > oco->size) {
+    if (oco->count == 0 || oco->count + count + padBytes > oco->size) {
         FD_CLR(oc->fd, &OutputPending);
         if (!XFD_ANYSET(&OutputPending)) {
             CriticalOutputPending = FALSE;
commit ceffb34774d44ada83cc1994d20c8d65b46bd555
Author: Laurent Carlier <lordheavym at gmail.com>
Date:   Sat Jun 8 00:43:56 2013 +0200

    ephyr: restore GLX support
    
    It was removed since version 1.13
    
    Signed-off-by: Sebastien Bacher <seb128 at ubuntu.com>
    Acked-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/hw/kdrive/ephyr/ephyrinit.c b/hw/kdrive/ephyr/ephyrinit.c
index 9a1dd7d..447ff6b 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;
@@ -47,6 +48,22 @@ extern KdKeyboardDriver LinuxEvdevKeyboardDriver;
 
 void processScreenArg(const char *screen_size, char *parent_id);
 
+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
 InitCard(char *name)
 {
@@ -57,6 +74,9 @@ InitCard(char *name)
 void
 InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
 {
+    if (serverGeneration == 1)
+        ephyrExtensionInit();
+
     KdInitOutput(pScreenInfo, argc, argv);
 }
 
commit f37972f4a67b49ba9649310a6778bd1bf31e0130
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Apr 24 14:58:27 2013 -0700

    miext/sync: Fix multi-screen support in SyncFence initialization
    
    miSyncSetup was checking to see if the screen private key had been
    registered, and if so, skipping the setup of the provided screen.
    
    Instead, it should register the private index only once, but then
    initialize the screen unless it has already been initialized. This
    latter step allows drivers to initialize the sync private structures
    before the Sync extension itself is initialized.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/miext/sync/misync.c b/miext/sync/misync.c
index d24921a..b6914d1 100644
--- a/miext/sync/misync.c
+++ b/miext/sync/misync.c
@@ -182,20 +182,21 @@ miSyncSetup(ScreenPtr pScreen)
         &miSyncScreenDestroyFence
     };
 
-    if (dixPrivateKeyRegistered(syncScreenPrivateKey))
-        return TRUE;
-
-    if (!dixRegisterPrivateKey(syncScreenPrivateKey, PRIVATE_SCREEN,
-                               sizeof(SyncScreenPrivRec)))
-        return FALSE;
+    if (!dixPrivateKeyRegistered(syncScreenPrivateKey)) {
+        if (!dixRegisterPrivateKey(syncScreenPrivateKey, PRIVATE_SCREEN,
+                                   sizeof(SyncScreenPrivRec)))
+            return FALSE;
+    }
 
     pScreenPriv = SYNC_SCREEN_PRIV(pScreen);
 
-    pScreenPriv->funcs = miSyncScreenFuncs;
+    if (pScreenPriv->funcs.CreateFence) {
+        pScreenPriv->funcs = miSyncScreenFuncs;
 
-    /* Wrap CloseScreen to clean up */
-    pScreenPriv->CloseScreen = pScreen->CloseScreen;
-    pScreen->CloseScreen = SyncCloseScreen;
+        /* Wrap CloseScreen to clean up */
+        pScreenPriv->CloseScreen = pScreen->CloseScreen;
+        pScreen->CloseScreen = SyncCloseScreen;
+    }
 
     return TRUE;
 }
commit 1c8beedfe4343377fa3504f8ab71430cc137b22c
Author: Adam Jackson <ajax at redhat.com>
Date:   Wed Aug 21 14:12:52 2013 -0400

    randr: Fix a copypasta bug in CRTC confinement
    
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/randr/rrpointer.c b/randr/rrpointer.c
index ec803e9..eb6b677 100644
--- a/randr/rrpointer.c
+++ b/randr/rrpointer.c
@@ -82,7 +82,7 @@ RRPointerToNearestCrtc(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y,
         else
             dx = 0;
         if (y < crtc->y)
-            dy = crtc->y - x;
+            dy = crtc->y - y;
         else if (y > crtc->y + scan_height)
             dy = y - (crtc->y + scan_height);
         else
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 Xquartz-changes mailing list