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

Jeremy Huddleston jeremyhu at freedesktop.org
Mon Oct 12 02:07:32 PDT 2015


 Xext/geext.c                                     |   10 
 Xext/geint.h                                     |    5 
 Xext/xace.c                                      |   28 
 Xext/xace.h                                      |    3 
 Xext/xselinux_hooks.c                            |    9 
 Xi/exevents.c                                    |   15 
 composite/compinit.c                             |   27 
 composite/compwindow.c                           |    2 
 configure.ac                                     |  103 +-
 dev/null                                         |binary
 dix/atom.c                                       |    6 
 dix/colormap.c                                   |  365 ++++----
 dix/cursor.c                                     |    8 
 dix/dispatch.c                                   |    5 
 dix/dixfonts.c                                   |   12 
 dix/enterleave.c                                 |    2 
 dix/enterleave.h                                 |    2 
 dix/getevents.c                                  |    4 
 dix/main.c                                       |    5 
 dix/pixmap.c                                     |  180 +++-
 dix/privates.c                                   |    9 
 dix/protocol.txt                                 |  302 +------
 dix/resource.c                                   |   33 
 dix/touch.c                                      |    2 
 dix/window.c                                     |    9 
 doc/Xinput.xml                                   |   24 
 doc/c-extensions                                 |    2 
 doc/smartsched                                   |    6 
 dri3/dri3.c                                      |    3 
 dri3/dri3_event.c                                |  163 ---
 dri3/dri3_priv.h                                 |    2 
 exa/exa_render.c                                 |    2 
 fb/fb.h                                          |    5 
 fb/fbpict.c                                      |   13 
 glamor/glamor.c                                  |  223 +++--
 glamor/glamor.h                                  |   39 
 glamor/glamor_composite_glyphs.c                 |   85 +-
 glamor/glamor_core.c                             |   16 
 glamor/glamor_egl.c                              |  179 +++-
 glamor/glamor_egl_stubs.c                        |    2 
 glamor/glamor_fbo.c                              |   85 +-
 glamor/glamor_font.c                             |   37 
 glamor/glamor_gradient.c                         |   21 
 glamor/glamor_image.c                            |    4 
 glamor/glamor_largepixmap.c                      |   26 
 glamor/glamor_picture.c                          |  885 ++++++++++++++++++++-
 glamor/glamor_pixmap.c                           |  955 -----------------------
 glamor/glamor_prepare.c                          |   20 
 glamor/glamor_priv.h                             |  289 ++----
 glamor/glamor_program.c                          |   14 
 glamor/glamor_render.c                           |  123 +-
 glamor/glamor_transfer.c                         |    2 
 glamor/glamor_utils.h                            |  103 --
 glamor/glamor_vbo.c                              |    1 
 glamor/glamor_window.c                           |   32 
 glamor/glamor_xv.c                               |   38 
 glx/createcontext.c                              |   15 
 glx/extension_string.c                           |    1 
 glx/extension_string.h                           |    3 
 glx/glxcmds.c                                    |   20 
 glx/glxcontext.h                                 |    5 
 glx/glxdri2.c                                    |    7 
 glx/glxdriswrast.c                               |   44 +
 glx/rensize.c                                    |    1 
 hw/dmx/doc/dmx.xml                               |    2 
 hw/dmx/glxProxy/glxcmdsswap.c                    |    2 
 hw/dmx/glxProxy/glxext.c                         |    2 
 hw/kdrive/ephyr/ephyr.c                          |   17 
 hw/kdrive/ephyr/ephyrcursor.c                    |    4 
 hw/kdrive/ephyr/ephyrdriext.c                    |    4 
 hw/kdrive/ephyr/ephyrglxext.c                    |    2 
 hw/kdrive/ephyr/ephyrinit.c                      |    2 
 hw/kdrive/ephyr/hostx.c                          |   26 
 hw/kdrive/ephyr/hostx.h                          |    2 
 hw/kdrive/fake/fake.c                            |    6 
 hw/kdrive/fbdev/fbdev.c                          |    6 
 hw/kdrive/src/kinput.c                           |   35 
 hw/vfb/Makefile.am                               |    1 
 hw/xfree86/Makefile.am                           |    2 
 hw/xfree86/common/Makefile.am                    |    1 
 hw/xfree86/common/compiler.h                     |   15 
 hw/xfree86/common/dgaproc.h                      |   62 -
 hw/xfree86/common/vidmodeproc.h                  |   77 -
 hw/xfree86/common/xf86.h                         |   11 
 hw/xfree86/common/xf86Config.c                   |   29 
 hw/xfree86/common/xf86DGA.c                      |   36 
 hw/xfree86/common/xf86Events.c                   |    2 
 hw/xfree86/common/xf86Helper.c                   |    2 
 hw/xfree86/common/xf86Mode.c                     |   11 
 hw/xfree86/common/xf86Module.h                   |    2 
 hw/xfree86/common/xf86VidMode.c                  |    2 
 hw/xfree86/doc/ddxDesign.xml                     |   75 -
 hw/xfree86/dri/dri.c                             |    2 
 hw/xfree86/dri2/dri2ext.c                        |   14 
 hw/xfree86/drivers/modesetting/dri2.c            |    4 
 hw/xfree86/drivers/modesetting/driver.c          |  275 ++++--
 hw/xfree86/drivers/modesetting/driver.h          |   44 -
 hw/xfree86/drivers/modesetting/drmmode_display.c |  235 ++++-
 hw/xfree86/drivers/modesetting/drmmode_display.h |   17 
 hw/xfree86/drivers/modesetting/modesetting.man   |   18 
 hw/xfree86/drivers/modesetting/present.c         |  450 ++++++++++
 hw/xfree86/drivers/modesetting/vblank.c          |   46 -
 hw/xfree86/fbdevhw/fbdevhw.c                     |   53 +
 hw/xfree86/man/Xorg.man                          |    8 
 hw/xfree86/man/Xorg.wrap.man                     |    2 
 hw/xfree86/man/xorg.conf.man                     |    4 
 hw/xfree86/modes/xf86Cursors.c                   |    8 
 hw/xfree86/modes/xf86EdidModes.c                 |    2 
 hw/xfree86/modes/xf86RandR12.c                   |   13 
 hw/xfree86/modes/xf86Rotate.c                    |    8 
 hw/xfree86/os-support/linux/Makefile.am          |    2 
 hw/xfree86/os-support/linux/linux.h              |   32 
 hw/xfree86/os-support/linux/lnx_init.c           |  135 ++-
 hw/xfree86/os-support/linux/systemd-logind.c     |   26 
 hw/xfree86/os-support/shared/sigio.c             |    2 
 hw/xfree86/os-support/xf86_OSlib.h               |   13 
 hw/xfree86/parser/InputClass.c                   |  152 +--
 hw/xfree86/parser/Makefile.am                    |   16 
 hw/xfree86/parser/OutputClass.c                  |   52 -
 hw/xfree86/parser/Screen.c                       |   80 -
 hw/xfree86/parser/Vendor.c                       |   32 
 hw/xfree86/parser/configProcs.h                  |    9 
 hw/xfree86/ramdac/TI.c                           |    2 
 hw/xfree86/ramdac/xf86Cursor.c                   |    2 
 hw/xfree86/ramdac/xf86Cursor.h                   |    4 
 hw/xfree86/ramdac/xf86HWCurs.c                   |    6 
 hw/xfree86/sdksyms.sh                            |   12 
 hw/xfree86/x86emu/debug.c                        |    6 
 hw/xquartz/bundle/Info.plist.cpp                 |   17 
 hw/xquartz/quartz.c                              |    4 
 hw/xquartz/xpr/xprCursor.c                       |    2 
 hw/xwayland/xwayland-cursor.c                    |    1 
 hw/xwayland/xwayland-glamor.c                    |    2 
 hw/xwayland/xwayland-input.c                     |  316 ++++++-
 hw/xwayland/xwayland-output.c                    |  113 ++
 hw/xwayland/xwayland-shm.c                       |    2 
 hw/xwayland/xwayland.c                           |   17 
 hw/xwayland/xwayland.h                           |   15 
 hw/xwin/glx/indirect.c                           |   12 
 hw/xwin/glx/winpriv.c                            |    2 
 hw/xwin/winallpriv.c                             |    4 
 hw/xwin/winclipboard/internal.h                  |    4 
 hw/xwin/winclipboard/wndproc.c                   |   12 
 hw/xwin/winclipboard/xevents.c                   |   16 
 hw/xwin/wincmap.c                                |   10 
 hw/xwin/winconfig.c                              |    2 
 hw/xwin/wincreatewnd.c                           |    9 
 hw/xwin/windialogs.c                             |    8 
 hw/xwin/winkeybd.c                               |    4 
 hw/xwin/winkeyhook.c                             |    2 
 hw/xwin/winmsg.c                                 |    8 
 hw/xwin/winmultiwindowicons.c                    |    9 
 hw/xwin/winmultiwindowwindow.c                   |   50 -
 hw/xwin/winmultiwindowwm.c                       |    4 
 hw/xwin/winmultiwindowwndproc.c                  |   39 
 hw/xwin/winrandr.c                               |    7 
 hw/xwin/winscrinit.c                             |    4 
 hw/xwin/winshadddnl.c                            |   15 
 hw/xwin/winshadgdi.c                             |   10 
 hw/xwin/winwin32rootlesswndproc.c                |   18 
 hw/xwin/winwndproc.c                             |    2 
 include/Makefile.am                              |    4 
 include/colormap.h                               |   12 
 include/cursorstr.h                              |    2 
 include/dix-config.h.in                          |    9 
 include/dixfont.h                                |   36 
 include/dixstruct.h                              |   23 
 include/kdrive-config.h.in                       |    3 
 include/misc.h                                   |    3 
 include/opaque.h                                 |    1 
 include/os.h                                     |    7 
 include/pixmap.h                                 |   14 
 include/pixmapstr.h                              |    5 
 include/resource.h                               |   15 
 include/scrnintstr.h                             |   10 
 include/swaprep.h                                |  320 +++----
 include/swapreq.h                                |    6 
 include/windowstr.h                              |    4 
 include/xorg-server.h.in                         |    3 
 man/Xserver.man                                  |   16 
 mi/midispcur.c                                   |   20 
 mi/mieq.c                                        |   16 
 mi/miexpose.c                                    |   48 -
 mi/miglblt.c                                     |    1 
 mi/mioverlay.c                                   |   13 
 mi/miscrinit.c                                   |    1 
 mi/miwideline.c                                  |    2 
 mi/miwindow.c                                    |   11 
 miext/Makefile.am                                |    9 
 miext/damage/damage.c                            |    1 
 miext/rootless/rootlessCommon.h                  |   23 
 miext/rootless/rootlessConfig.h                  |   19 
 miext/rootless/rootlessGC.c                      |    2 
 miext/rootless/rootlessScreen.c                  |    3 
 miext/rootless/rootlessValTree.c                 |    2 
 miext/rootless/rootlessWindow.c                  |   31 
 miext/rootless/rootlessWindow.h                  |    1 
 os/access.c                                      |   15 
 os/connection.c                                  |    6 
 os/osdep.h                                       |    8 
 os/osinit.c                                      |    3 
 os/utils.c                                       |   65 +
 os/xdmcp.c                                       |   32 
 present/present.c                                |   14 
 present/present_event.c                          |    2 
 present/present_priv.h                           |    2 
 present/present_request.c                        |    4 
 randr/randrstr.h                                 |   10 
 randr/rrcrtc.c                                   |  127 ++-
 randr/rrdispatch.c                               |    4 
 randr/rrmonitor.c                                |    2 
 render/glyph.c                                   |   10 
 render/glyphstr.h                                |   36 
 render/mipict.c                                  |   16 
 render/mipict.h                                  |   36 
 render/picture.c                                 |   37 
 render/picture.h                                 |    6 
 render/picturestr.h                              |   50 -
 render/render.c                                  |   15 
 test/Makefile.am                                 |    2 
 test/README                                      |   17 
 test/xi1/.gitignore                              |    1 
 xfixes/Makefile.am                               |    4 
 xfixes/cursor.c                                  |    2 
 xfixes/xfixes.h                                  |    6 
 xkb/xkbActions.c                                 |    9 
 226 files changed, 4725 insertions(+), 4117 deletions(-)

New commits:
commit 2ec35402009644be4f7aca066ec210ddf8a18ac6
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Mon Oct 12 02:06:10 2015 -0700

    XQuartz: Remove InfoPlist.strings
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/hw/xquartz/bundle/Resources/English.lproj/InfoPlist.strings b/hw/xquartz/bundle/Resources/English.lproj/InfoPlist.strings
deleted file mode 100644
index 88e1f04..0000000
Binary files a/hw/xquartz/bundle/Resources/English.lproj/InfoPlist.strings and /dev/null differ
commit 086f0f70a061b6828f61af19f58d690de85a5653
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Mon Oct 12 02:04:55 2015 -0700

    XQuartz: Bump XQuartz bundle version to 2.7.9
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/hw/xquartz/bundle/Info.plist.cpp b/hw/xquartz/bundle/Info.plist.cpp
index 06e33f8..941105f 100644
--- a/hw/xquartz/bundle/Info.plist.cpp
+++ b/hw/xquartz/bundle/Info.plist.cpp
@@ -19,9 +19,9 @@
 	<key>CFBundlePackageType</key>
 		<string>APPL</string>
 	<key>CFBundleShortVersionString</key>
-		<string>2.7.7</string>
+		<string>2.7.9</string>
 	<key>CFBundleVersion</key>
-		<string>2.7.7</string>
+		<string>2.7.9</string>
 	<key>CFBundleSignature</key>
 		<string>x11a</string>
 	<key>CSResourcesFileMapped</key>
commit df80e2649aa47957986554928e6bf41b86c15240
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Mon Oct 12 02:04:11 2015 -0700

    XQuartz: Relax App Transport Security for communicating with the update server
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/hw/xquartz/bundle/Info.plist.cpp b/hw/xquartz/bundle/Info.plist.cpp
index a0d9050..06e33f8 100644
--- a/hw/xquartz/bundle/Info.plist.cpp
+++ b/hw/xquartz/bundle/Info.plist.cpp
@@ -35,6 +35,19 @@
 		<string>sparkle.pem</string>
         <key>SUFeedURL</key>
                 <string>http://xquartz.macosforge.org/downloads/sparkle/release.xml</string>
+	<key>NSAppTransportSecurity</key>
+	<dict>
+		<key>NSExceptionDomains</key>
+		<dict>
+			<key>macosforge.org</key>
+			<dict>
+				<key>NSIncludesSubdomains</key>
+				<true/>
+				<key>NSExceptionAllowsInsecureHTTPLoads</key>
+				<true/>
+			</dict>
+		</dict>
+	</dict>
 #endif
 	<key>LSApplicationCategoryType</key>
 		<string>public.app-category.utilities</string>
commit 880d4e78b1823bcc0e66e68270af1a475f097bb5
Author: Jonas Ã…dahl <jadahl at gmail.com>
Date:   Wed Oct 7 12:02:39 2015 +0800

    xwayland: Set physical screen size to something
    
    When we have a single output, just set it to the physical size of that
    output. Otherwise try to approximate it calculating a mean m.m. per
    dot. Last fallback is to default to 96 DPI.
    
    Signed-off-by: Jonas Ã…dahl <jadahl at gmail.com>
    Reviewed-by: Daniel Stone <daniels at collabora.com>

diff --git a/hw/xwayland/xwayland-output.c b/hw/xwayland/xwayland-output.c
index a8c2f2e..e4623d4 100644
--- a/hw/xwayland/xwayland-output.c
+++ b/hw/xwayland/xwayland-output.c
@@ -30,6 +30,8 @@
 #include "xwayland.h"
 #include <randrstr.h>
 
+#define DEFAULT_DPI 96
+
 static Rotation
 wl_transform_to_xrandr(enum wl_output_transform transform)
 {
@@ -129,12 +131,40 @@ output_get_new_size(struct xwl_output *xwl_output,
         *height = xwl_output->y + xwl_output->height;
 }
 
+/* Approximate some kind of mmpd (m.m. per dot) of the screen given the outputs
+ * associated with it.
+ *
+ * It will either calculate the mean mmpd of all the outputs, or default to
+ * 96 DPI if no reasonable value could be calculated.
+ */
+static double
+approximate_mmpd(struct xwl_screen *xwl_screen)
+{
+    struct xwl_output *it;
+    int total_width_mm = 0;
+    int total_width = 0;
+
+    xorg_list_for_each_entry(it, &xwl_screen->output_list, link) {
+        if (it->randr_output->mmWidth == 0)
+            continue;
+
+        total_width_mm += it->randr_output->mmWidth;
+        total_width += it->width;
+    }
+
+    if (total_width_mm != 0)
+        return (double)total_width_mm / total_width;
+    else
+        return 25.4 / DEFAULT_DPI;
+}
+
 static void
 output_handle_done(void *data, struct wl_output *wl_output)
 {
     struct xwl_output *it, *xwl_output = data;
     struct xwl_screen *xwl_screen = xwl_output->xwl_screen;
     int width = 0, height = 0, has_this_output = 0;
+    double mmpd;
 
     xorg_list_for_each_entry(it, &xwl_screen->output_list, link) {
         /* output done event is sent even when some property
@@ -164,6 +194,15 @@ output_handle_done(void *data, struct wl_output *wl_output)
     xwl_screen->screen->width = width;
     xwl_screen->screen->height = height;
 
+    if (xwl_output->width == width && xwl_output->height == height) {
+        xwl_screen->screen->mmWidth = xwl_output->randr_output->mmWidth;
+        xwl_screen->screen->mmHeight = xwl_output->randr_output->mmHeight;
+    } else {
+        mmpd = approximate_mmpd(xwl_screen);
+        xwl_screen->screen->mmWidth = width * mmpd;
+        xwl_screen->screen->mmHeight = height * mmpd;
+    }
+
     if (xwl_screen->screen->root) {
         xwl_screen->screen->root->drawable.width = width;
         xwl_screen->screen->root->drawable.height = height;
commit 216bdbc7351e2078d94857a3323f6cd8f0d2f191
Author: Jonas Ã…dahl <jadahl at gmail.com>
Date:   Wed Oct 7 12:02:38 2015 +0800

    xwayland: Update actual screen and root window size on output hot plug
    
    When a new output is hot-plugged we need to not only update our internal
    screen dimensions, but also the dix screen dimensions, screenInfo
    dimensions and the root window dimensions.
    
    https://bugs.freedesktop.org/show_bug.cgi?id=92273
    
    Signed-off-by: Jonas Ã…dahl <jadahl at gmail.com>
    Reviewed-by: Daniel Stone <daniels at collabora.com>

diff --git a/hw/xwayland/xwayland-output.c b/hw/xwayland/xwayland-output.c
index 923f368..a8c2f2e 100644
--- a/hw/xwayland/xwayland-output.c
+++ b/hw/xwayland/xwayland-output.c
@@ -156,9 +156,22 @@ output_handle_done(void *data, struct wl_output *wl_output)
 	--xwl_screen->expecting_event;
     }
 
+    if (xwl_screen->screen->root)
+        SetRootClip(xwl_screen->screen, FALSE);
+
     xwl_screen->width = width;
     xwl_screen->height = height;
-    RRScreenSizeNotify(xwl_screen->screen);
+    xwl_screen->screen->width = width;
+    xwl_screen->screen->height = height;
+
+    if (xwl_screen->screen->root) {
+        xwl_screen->screen->root->drawable.width = width;
+        xwl_screen->screen->root->drawable.height = height;
+        SetRootClip(xwl_screen->screen, TRUE);
+        RRScreenSizeNotify(xwl_screen->screen);
+    }
+
+    update_desktop_dimensions();
 }
 
 static void
commit 211d4c2d353b5e379716484055a3f58235ea65f4
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Wed Dec 14 15:55:22 2011 +0000

    render: Propagate allocation failure from createSourcePicture()
    
    All the callers were already checking for failure, except that
    createSourcePicture() itself was failing to check whether it
    successfully allocated the Picture.
    
    [ajax: Rebase, fix line wrap of preceding line]
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/render/picture.c b/render/picture.c
index 3d52dec..6d9c9df 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -862,7 +862,11 @@ createSourcePicture(void)
 {
     PicturePtr pPicture;
 
-    pPicture = dixAllocateScreenObjectWithPrivates(NULL, PictureRec, PRIVATE_PICTURE);
+    pPicture = dixAllocateScreenObjectWithPrivates(NULL, PictureRec,
+                                                   PRIVATE_PICTURE);
+    if (!pPicture)
+	return 0;
+
     pPicture->pDrawable = 0;
     pPicture->pFormat = 0;
     pPicture->pNext = 0;
commit 8a26a4aff570744347a8bed19f693bf631be464e
Author: Alexandr Shadchin <alexandr.shadchin at gmail.com>
Date:   Sun Nov 27 02:49:02 2011 +0600

    bsd: Remove LINKKIT
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Alexandr Shadchin <Alexandr.Shadchin at gmail.com>

diff --git a/hw/xfree86/os-support/xf86_OSlib.h b/hw/xfree86/os-support/xf86_OSlib.h
index 946d58a..c7b295a 100644
--- a/hw/xfree86/os-support/xf86_OSlib.h
+++ b/hw/xfree86/os-support/xf86_OSlib.h
@@ -238,8 +238,6 @@ extern _X_HIDDEN char xf86SolarisFbDev[PATH_MAX];
 #define __FreeBSD_kernel_version __FreeBSD_version
 #endif
 
-#if !defined(LINKKIT)
-  /* Don't need this stuff for the Link Kit */
 #ifdef SYSCONS_SUPPORT
 #define COMPAT_SYSCONS
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
@@ -305,7 +303,6 @@ struct pcvtid {
 #ifndef CONSOLE_GET_MEM_INFO
 #define CONSOLE_GET_MEM_INFO            _IOR('t',159,struct map_info)
 #endif
-#endif                          /* !LINKKIT */
 
 #if defined(USE_I386_IOPL) || defined(USE_AMD64_IOPL)
 #include <machine/sysarch.h>
commit ab3e34bf9ddff90261fbbe0e2604887459cd70ad
Author: Alexandr Shadchin <alexandr.shadchin at gmail.com>
Date:   Sun Nov 27 02:49:01 2011 +0600

    xfree86: Remove 386BSD
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Alexandr Shadchin <Alexandr.Shadchin at gmail.com>

diff --git a/hw/xfree86/os-support/xf86_OSlib.h b/hw/xfree86/os-support/xf86_OSlib.h
index 95c3a73..946d58a 100644
--- a/hw/xfree86/os-support/xf86_OSlib.h
+++ b/hw/xfree86/os-support/xf86_OSlib.h
@@ -208,13 +208,9 @@ extern _X_HIDDEN char xf86SolarisFbDev[PATH_MAX];
 #endif                          /* __linux__ || __GLIBC__ */
 
 /**************************************************************************/
-/* 386BSD and derivatives,  BSD/386                                       */
+/* System is BSD-like                                                     */
 /**************************************************************************/
 
-#if defined(__386BSD__) && (defined(__FreeBSD__) || defined(__NetBSD__))
-#undef __386BSD__
-#endif
-
 #ifdef CSRG_BASED
 #include <sys/ioctl.h>
 #include <signal.h>
commit c877048c8509a03f6aa69e533ab86c1039cfb6df
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Thu Jun 30 15:30:40 2011 +0100

    glx: Synchronize Xserver glx/rensize.c with mesa src/glx/compsize.c
    
    Noticed while investigating https://bugs.freedesktop.org/show_bug.cgi?id=30102
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>

diff --git a/glx/rensize.c b/glx/rensize.c
index 6bfe99b..55ad4a2 100644
--- a/glx/rensize.c
+++ b/glx/rensize.c
@@ -240,6 +240,7 @@ __glXImageSize(GLenum format, GLenum type, GLenum target,
         case GL_422_REV_AVERAGE_EXT:
         case GL_DEPTH_STENCIL_NV:
         case GL_DEPTH_STENCIL_MESA:
+        case GL_YCBCR_422_APPLE:
         case GL_YCBCR_MESA:
         case GL_LUMINANCE_ALPHA:
         case GL_LUMINANCE_ALPHA_INTEGER_EXT:
commit d08ac3660651c8614a1780750b76c48eeb0870b7
Author: Jamey Sharp <jamey at minilop.net>
Date:   Thu May 12 15:21:52 2011 -0700

    kdrive: Delete unused TOUCHSCREEN define.
    
    There's nothing in configure to enable this, and KdTsPhyScreen isn't
    defined anywhere.
    
    [ajax: Rebase, also clean up Xfbdev]
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Jamey Sharp <jamey at minilop.net>

diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index 1909a06..cb1c16e 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -50,7 +50,6 @@
 
 #include "xkbsrv.h"
 
-extern int KdTsPhyScreen;
 extern Bool ephyr_glamor;
 
 KdKeyboardInfo *ephyrKbd;
diff --git a/hw/kdrive/fake/fake.c b/hw/kdrive/fake/fake.c
index 04a7278..7205df4 100644
--- a/hw/kdrive/fake/fake.c
+++ b/hw/kdrive/fake/fake.c
@@ -25,8 +25,6 @@
 #endif
 #include "fake.h"
 
-extern int KdTsPhyScreen;
-
 Bool
 fakeInitialize(KdCardInfo * card, FakePriv * priv)
 {
@@ -364,10 +362,6 @@ fakeCreateColormap(ColormapPtr pmap)
 Bool
 fakeInitScreen(ScreenPtr pScreen)
 {
-#ifdef TOUCHSCREEN
-    KdTsPhyScreen = pScreen->myNum;
-#endif
-
     pScreen->CreateColormap = fakeCreateColormap;
     return TRUE;
 }
diff --git a/hw/kdrive/fbdev/fbdev.c b/hw/kdrive/fbdev/fbdev.c
index 23f7509..9b69edf 100644
--- a/hw/kdrive/fbdev/fbdev.c
+++ b/hw/kdrive/fbdev/fbdev.c
@@ -28,8 +28,6 @@
 
 #include <errno.h>
 
-extern int KdTsPhyScreen;
-
 const char *fbdevDevicePath = NULL;
 
 static Bool
@@ -698,10 +696,6 @@ fbdevCreateColormap(ColormapPtr pmap)
 Bool
 fbdevInitScreen(ScreenPtr pScreen)
 {
-#ifdef TOUCHSCREEN
-    KdTsPhyScreen = pScreen->myNum;
-#endif
-
     pScreen->CreateColormap = fbdevCreateColormap;
     return TRUE;
 }
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index daaff8d..112ab95 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -307,9 +307,6 @@
 /* Support TCP socket connections */
 #undef TCPCONN
 
-/* Enable touchscreen support */
-#undef TOUCHSCREEN
-
 /* Support tslib touchscreen abstraction library */
 #undef TSLIB
 
diff --git a/include/kdrive-config.h.in b/include/kdrive-config.h.in
index 0e54aa1..3d7e9a4 100644
--- a/include/kdrive-config.h.in
+++ b/include/kdrive-config.h.in
@@ -13,9 +13,6 @@
 /* Include framebuffer support in X servers */
 #undef KDRIVEFBDEV
 
-/* Enable touchscreen support */
-#undef TOUCHSCREEN
-
 /* Support tslib touchscreen abstraction library */
 #undef TSLIB
 
diff --git a/include/xorg-server.h.in b/include/xorg-server.h.in
index 3152dbd..e46ccec 100644
--- a/include/xorg-server.h.in
+++ b/include/xorg-server.h.in
@@ -101,9 +101,6 @@
 /* Support TCP socket connections */
 #undef TCPCONN
 
-/* Enable touchscreen support */
-#undef TOUCHSCREEN
-
 /* Support tslib touchscreen abstraction library */
 #undef TSLIB
 
commit e31fe8115ee080b58b2e96a5106f38e64944ce5e
Author: Olivier Fourdan <ofourdan at redhat.com>
Date:   Wed Sep 23 15:35:58 2015 +0200

    xwayland: Adjust screen size with rotation
    
    bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=92076
    Signed-off-by: Olivier Fourdan <ofourdan at redhat.com>
    Tested-by: Artem Chudinov <arzeth0 at gmail.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xwayland/xwayland-output.c b/hw/xwayland/xwayland-output.c
index 1546eaa..923f368 100644
--- a/hw/xwayland/xwayland-output.c
+++ b/hw/xwayland/xwayland-output.c
@@ -101,8 +101,13 @@ output_handle_mode(void *data, struct wl_output *wl_output, uint32_t flags,
     if (!(flags & WL_OUTPUT_MODE_CURRENT))
         return;
 
-    xwl_output->width = width;
-    xwl_output->height = height;
+    if (xwl_output->rotation & (RR_Rotate_0 | RR_Rotate_180)) {
+        xwl_output->width = width;
+        xwl_output->height = height;
+    } else {
+        xwl_output->width = height;
+        xwl_output->height = width;
+    }
 
     randr_mode = xwayland_cvt(width, height, refresh / 1000.0, 0, 0);
 
commit f6ce23fbfc8804204fa103f98b94478387b94040
Author: Fredrik Höglund <fredrik at kde.org>
Date:   Thu Sep 10 23:33:20 2015 +0200

    present: Don't stash the MSC value when present_get_ust_msc fails
    
    Otherwise we stash an uninitalized value, and later use it to compute
    the msc_offset for the window.  Also initialize ust and crtc_msc so we
    never use uninitalized values when present_get_ust_msc fails.
    
    This fixes clients getting stuck waiting indefinitely for an idle
    event when a CRTC is turned off.
    
    Signed-off-by: Fredrik Höglund <fredrik at kde.org>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>

diff --git a/present/present.c b/present/present.c
index a634601..7ddffbd 100644
--- a/present/present.c
+++ b/present/present.c
@@ -710,9 +710,9 @@ present_pixmap(WindowPtr window,
                present_notify_ptr notifies,
                int num_notifies)
 {
-    uint64_t                    ust;
+    uint64_t                    ust = 0;
     uint64_t                    target_msc;
-    uint64_t                    crtc_msc;
+    uint64_t                    crtc_msc = 0;
     int                         ret;
     present_vblank_ptr          vblank, tmp;
     ScreenPtr                   screen = window->drawable.pScreen;
@@ -734,13 +734,15 @@ present_pixmap(WindowPtr window,
             target_crtc = present_get_crtc(window);
     }
 
-    present_get_ust_msc(screen, target_crtc, &ust, &crtc_msc);
+    ret = present_get_ust_msc(screen, target_crtc, &ust, &crtc_msc);
 
     target_msc = present_window_to_crtc_msc(window, target_crtc, window_msc, crtc_msc);
 
-    /* Stash the current MSC away in case we need it later
-     */
-    window_priv->msc = crtc_msc;
+    if (ret == Success) {
+        /* Stash the current MSC away in case we need it later
+         */
+        window_priv->msc = crtc_msc;
+    }
 
     /* Adjust target_msc to match modulus
      */
commit c1f5f9022f31ca4d662cc125fa80cb25386da6d1
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sun Sep 27 18:41:35 2015 -0700

    glamor: Get rid of an extraneous ; at the end of a C source line
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>

diff --git a/glamor/glamor_picture.c b/glamor/glamor_picture.c
index 691f179..9b09454 100644
--- a/glamor/glamor_picture.c
+++ b/glamor/glamor_picture.c
@@ -231,7 +231,7 @@ glamor_get_tex_format_type_from_pictformat_gles2(PictFormatShort format,
     case PICT_b5g6r5:
         *tex_format = GL_RGB;
         *tex_type = GL_UNSIGNED_SHORT_5_6_5;
-        need_swap_rb = IS_LITTLE_ENDIAN ? 1 : 0;;
+        need_swap_rb = IS_LITTLE_ENDIAN ? 1 : 0;
         break;
 
     case PICT_x1b5g5r5:
commit 10e9116b3f709bec6d6a50446c1341441a0564e4
Author: Rui Matos <tiagomatos at gmail.com>
Date:   Tue Jul 15 15:57:20 2014 +0200

    xwayland-input: Always set the xkb group index on modifiers events
    
    While we have keyboard focus, the server's xkb code is already locking
    and latching modifiers appropriately while processing keyboard
    events.
    
    Since there is no guaranteed order between wl_keyboard key and
    modifiers events, if we got the modifiers event with a locked or
    latched modifier and then process the key press event for that
    modifier we would wrongly unlock/unlatch. To prevent this, we ignore
    locked and latched modifiers while any of our surfaces has keyboard
    focus.
    
    But we always need to set the xkb group index since this might be
    triggered programatically by the wayland compositor at any time.
    
    Reviewed-by: Daniel Stone <daniels at collabora.com>

diff --git a/hw/xwayland/xwayland-input.c b/hw/xwayland/xwayland-input.c
index 010d28c..0515eb9 100644
--- a/hw/xwayland/xwayland-input.c
+++ b/hw/xwayland/xwayland-input.c
@@ -462,12 +462,6 @@ keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard,
     xkbStateNotify sn;
     CARD16 changed;
 
-    /* We don't need any of this while we have keyboard focus since
-       the regular key event processing already takes care of setting
-       our internal state correctly. */
-    if (xwl_seat->keyboard_focus)
-        return;
-
     for (dev = inputInfo.devices; dev; dev = dev->next) {
         if (dev != xwl_seat->keyboard &&
             dev != GetMaster(xwl_seat->keyboard, MASTER_KEYBOARD))
@@ -476,10 +470,12 @@ keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard,
         old_state = dev->key->xkbInfo->state;
         new_state = &dev->key->xkbInfo->state;
 
+        if (!xwl_seat->keyboard_focus) {
+            new_state->locked_mods = mods_locked & XkbAllModifiersMask;
+            XkbLatchModifiers(dev, XkbAllModifiersMask,
+                              mods_latched & XkbAllModifiersMask);
+        }
         new_state->locked_group = group & XkbAllGroupsMask;
-        new_state->locked_mods = mods_locked & XkbAllModifiersMask;
-        XkbLatchModifiers(dev, XkbAllModifiersMask,
-                          mods_latched & XkbAllModifiersMask);
 
         XkbComputeDerivedState(dev->key->xkbInfo);
 
commit f937032ee6526af3c9206a2d8c6eacdeeb490d3b
Author: Andreas Wettstein <wettstein509 at solnet.ch>
Date:   Sat Feb 15 17:37:24 2014 +0100

    xkb: Keyboard mouse button emulation should not suppress other keyboard events
    
    With this change, when a key mapped to an action to emulate mouse button
    presses and releases is held down, other keys pressed during that time are
    still processed normally.  This is a prerequisite for proper support of
    ISOLock.
    
    Signed-off-by: Andreas Wettstein <wettstein509 at solnet.ch>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/xkb/xkbActions.c b/xkb/xkbActions.c
index 9619060..1a9878d 100644
--- a/xkb/xkbActions.c
+++ b/xkb/xkbActions.c
@@ -639,6 +639,7 @@ _XkbFilterPointerBtn(XkbSrvInfoPtr xkbi,
         }
             break;
         }
+        return 0;
     }
     else if (filter->keycode == keycode) {
         int button = filter->upAction.btn.button;
@@ -664,8 +665,9 @@ _XkbFilterPointerBtn(XkbSrvInfoPtr xkbi,
             break;
         }
         filter->active = 0;
+        return 0;
     }
-    return 0;
+    return 1;
 }
 
 static int
commit 5447ac45bc090e8f3269979af4db55f619c5f278
Author: Andreas Wettstein <wettstein509 at solnet.ch>
Date:   Sat Feb 15 17:36:51 2014 +0100

    xkb: Suppress autorepeat for Set and Lock of Mods, Groups, and Controls
    
    The autorepeat for these actions was not correctly implemented, as the key
    repeat would be mistakenly interpreted as key releases.  Rather than fixing
    this, this change simply disables autorepeat for Set/Lock actions, for two
    reasons:
    
    - Autorepeating Set/Lock keys make complicate the interactions of actions.
    
    - Autorepeating Set/Lock keys have no apparent benefit, but hurt in the real
      world for layouts such as de(neo): Neo has a Level5 shift on the LSGT key,
      and a Level5 lock on Level5 of the same key.  This is unusable if LSGT
      autorepeats.  However, disabling autorepeat for key LSGT completely is not
      ideal for users that have a "usual" layout besides Neo, where LSGT carries
      symbols.
    
    Signed-off-by: Andreas Wettstein <wettstein509 at solnet.ch>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/xkb/xkbActions.c b/xkb/xkbActions.c
index 9dd1cbd..9619060 100644
--- a/xkb/xkbActions.c
+++ b/xkb/xkbActions.c
@@ -181,6 +181,7 @@ _XkbFilterSetState(XkbSrvInfoPtr xkbi,
                    XkbFilterPtr filter, unsigned keycode, XkbAction *pAction)
 {
     if (filter->keycode == 0) { /* initial press */
+        AccessXCancelRepeatKey(xkbi, keycode);
         filter->keycode = keycode;
         filter->active = 1;
         filter->filterOthers = ((pAction->mods.mask & XkbSA_ClearLocks) != 0);
@@ -354,6 +355,9 @@ static int
 _XkbFilterLockState(XkbSrvInfoPtr xkbi,
                     XkbFilterPtr filter, unsigned keycode, XkbAction *pAction)
 {
+    if (filter->keycode == 0) /* initial press */
+        AccessXCancelRepeatKey(xkbi, keycode);
+
     if (pAction && (pAction->type == XkbSA_LockGroup)) {
         if (pAction->group.flags & XkbSA_GroupAbsolute)
             xkbi->state.locked_group = XkbSAGroup(&pAction->group);
@@ -678,6 +682,7 @@ _XkbFilterControls(XkbSrvInfoPtr xkbi,
     ctrls = xkbi->desc->ctrls;
     old = *ctrls;
     if (filter->keycode == 0) { /* initial press */
+        AccessXCancelRepeatKey(xkbi, keycode);
         filter->keycode = keycode;
         filter->active = 1;
         filter->filterOthers = 0;
commit fbac451724f7e1b8ce6b6e0505cc33ccd41c5158
Author: Arcady Goldmints-Orlov <arcadyg at nvidia.com>
Date:   Thu Oct 4 14:22:13 2012 -0700

    Fix alphamap interactions with wfb
    
    Set a destructor function on pixman images and call fbFinishAccess()
    from there, rather than directly from free_pixman_pict(). This ensures
    that fbFinishAccess() gets called even if pixman still has a reference
    to the image after free_pixman_pict(), as is the case for alphamaps.
    
    [ajax: Squash an unused variable warning in the non-wfb build]
    
    Reviewed-by: Aaron Plattner <aplattner at nvidia.com>
    Signed-off-by: Arcady Goldmints-Orlov <arcadyg at nvidia.com>
    Reviewed-by: Søren Sandmann <ssp at redhat.com>

diff --git a/fb/fbpict.c b/fb/fbpict.c
index 021f178..7ea0b66 100644
--- a/fb/fbpict.c
+++ b/fb/fbpict.c
@@ -345,6 +345,11 @@ static pixman_image_t *image_from_pict_internal(PicturePtr pict, Bool has_clip,
                                                 int *xoff, int *yoff,
                                                 Bool is_alpha_map);
 
+static void image_destroy(pixman_image_t *image, void *data)
+{
+    fbFinishAccess((DrawablePtr)data);
+}
+
 static void
 set_image_properties(pixman_image_t * image, PicturePtr pict, Bool has_clip,
                      int *xoff, int *yoff, Bool is_alpha_map)
@@ -429,6 +434,10 @@ set_image_properties(pixman_image_t * image, PicturePtr pict, Bool has_clip,
         break;
     }
 
+    if (pict->pDrawable)
+        pixman_image_set_destroy_function(image, &image_destroy,
+                                          pict->pDrawable);
+
     pixman_image_set_filter(image, filter,
                             (pixman_fixed_t *) pict->filter_params,
                             pict->filter_nparams);
@@ -481,8 +490,8 @@ image_from_pict(PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
 void
 free_pixman_pict(PicturePtr pict, pixman_image_t * image)
 {
-    if (image && pixman_image_unref(image) && pict->pDrawable)
-        fbFinishAccess(pict->pDrawable);
+    if (image)
+        pixman_image_unref(image);
 }
 
 Bool
commit 19a87257f92e7f57a167fc03fba014ee22d8e1ab
Author: Emil Velikov <emil.l.velikov at gmail.com>
Date:   Fri Sep 25 14:04:34 2015 +0100

    glamor: move 'dri3_capable' extension checks after eglMakeCurrent
    
    Otherwise we'll fail and/or crash as no context is bound.
    
    Fixes: 64e6124f27e (glamor: move GL_OES_EGL_image check next to EGL_EXT_image_dma_buf_import)
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=92105
    Cc: Michel Dänzer <michel at daenzer.net>
    Cc: Nick Sarnie <commendsarnex at gmail.com>
    Reported-by: Nick Sarnie <commendsarnex at gmail.com>
    Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
    Tested-by: Nick Sarnie <commendsarnex at gmail.com>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>

diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
index dcff443..2e6c7bd 100644
--- a/glamor/glamor_egl.c
+++ b/glamor/glamor_egl.c
@@ -866,15 +866,6 @@ glamor_egl_init(ScrnInfoPtr scrn, int fd)
                                 KHR_surfaceless_opengl);
 #endif
 
-#ifdef GLAMOR_HAS_GBM
-    if (epoxy_has_egl_extension(glamor_egl->display,
-                                "EGL_KHR_gl_texture_2D_image") &&
-        epoxy_has_egl_extension(glamor_egl->display,
-                                "EGL_EXT_image_dma_buf_import") &&
-        epoxy_has_gl_extension("GL_OES_EGL_image"))
-        glamor_egl->dri3_capable = TRUE;
-#endif
-
     glamor_egl->context = eglCreateContext(glamor_egl->display,
                                            NULL, EGL_NO_CONTEXT,
                                            config_attribs);
@@ -889,6 +880,15 @@ glamor_egl_init(ScrnInfoPtr scrn, int fd)
                    "Failed to make EGL context current\n");
         goto error;
     }
+#ifdef GLAMOR_HAS_GBM
+    if (epoxy_has_egl_extension(glamor_egl->display,
+                                "EGL_KHR_gl_texture_2D_image") &&
+        epoxy_has_egl_extension(glamor_egl->display,
+                                "EGL_EXT_image_dma_buf_import") &&
+        epoxy_has_gl_extension("GL_OES_EGL_image"))
+        glamor_egl->dri3_capable = TRUE;
+#endif
+
     glamor_egl->saved_free_screen = scrn->FreeScreen;
     scrn->FreeScreen = glamor_egl_free_screen;
 #ifdef GLAMOR_GLES2
commit dca5770af9e20bb1148374ebfd60931a81b148a2
Merge: a31bbc4 21f384b
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Sep 25 10:23:28 2015 -0400

    Merge remote-tracking branch 'mchalupa/output-bugs'

commit a31bbc450a08622aadafc264b3efe57e465eaecb
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Tue Sep 22 19:25:43 2015 -0700

    protocol.txt: Add MIT-SHM 1.2 requests
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/dix/protocol.txt b/dix/protocol.txt
index 459c385..244556a 100644
--- a/dix/protocol.txt
+++ b/dix/protocol.txt
@@ -237,6 +237,8 @@ R002 MIT-SHM:Detach
 R003 MIT-SHM:PutImage
 R004 MIT-SHM:GetImage
 R005 MIT-SHM:CreatePixmap
+R006 MIT-SHM:AttachFd
+R007 MIT-SHM:CreateSegment
 V000 MIT-SHM:Completion
 E000 MIT-SHM:BadShmSeg
 R000 MIT-SUNDRY-NONSTANDARD:SetBugMode
commit 424ba5de56e2ddf173bb0d26daa821f12897f18f
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Tue Sep 22 19:25:42 2015 -0700

    protocol.txt: Add DRI3 1.0 requests
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/dix/protocol.txt b/dix/protocol.txt
index ac66d95..459c385 100644
--- a/dix/protocol.txt
+++ b/dix/protocol.txt
@@ -101,6 +101,12 @@ R011 DRI2:WaitSBC
 R012 DRI2:SwapInterval
 V000 DRI2:BufferSwapComplete
 V001 DRI2:InvalidateBuffers
+R000 DRI3:QueryVersion
+R001 DRI3:Open
+R002 DRI3:PixmapFromBuffer
+R003 DRI3:BufferFromPixmap
+R004 DRI3:FenceFromFD
+R005 DRI3:FDFromFence
 R000 Extended-Visual-Information:QueryVersion
 R001 Extended-Visual-Information:GetVisualInfo
 R000 FontCache:QueryVersion
commit 7e6b7c799455fdeac082cf2a064fe1ba432e92ca
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Tue Sep 22 19:25:41 2015 -0700

    protocol.txt: Add Present 1.0 requests
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/dix/protocol.txt b/dix/protocol.txt
index dfeca5f..ac66d95 100644
--- a/dix/protocol.txt
+++ b/dix/protocol.txt
@@ -235,6 +235,11 @@ V000 MIT-SHM:Completion
 E000 MIT-SHM:BadShmSeg
 R000 MIT-SUNDRY-NONSTANDARD:SetBugMode
 R001 MIT-SUNDRY-NONSTANDARD:GetBugMode
+R000 Present:QueryVersion
+R001 Present:Pixmap
+R002 Present:NotifyMSC
+R003 Present:SelectInput
+R004 Present:QueryCapabilities
 R000 RANDR:QueryVersion
 R001 RANDR:OldGetScreenInfo
 R002 RANDR:SetScreenConfig
commit fd653194be731e4e32f95f38446e0dcbf56d04c9
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Tue Sep 22 19:25:40 2015 -0700

    protocol.txt: Add RANDR 1.5 requests
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/dix/protocol.txt b/dix/protocol.txt
index cf612b5..dfeca5f 100644
--- a/dix/protocol.txt
+++ b/dix/protocol.txt
@@ -277,6 +277,9 @@ R038 RANDR:RRConfigureProviderProperty
 R039 RANDR:RRChangeProviderProperty
 R040 RANDR:RRDeleteProviderProperty
 R041 RANDR:RRGetProviderProperty
+R042 RANDR:GetMonitors
+R043 RANDR:SetMonitor
+R044 RANDR:DeleteMonitor
 V000 RANDR:ScreenChangeNotify
 V001 RANDR:Notify
 E000 RANDR:BadRROutput
commit 1ea8fb96bc6a95d98dd67fc9d4c4e4b858383d34
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Tue Sep 22 19:25:39 2015 -0700

    protocol.txt: Remove extensions that died before Xorg was born
    
    Adobe-DPS-Extension, DEC-XTRAP, X3D-PEX, XIE
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/dix/protocol.txt b/dix/protocol.txt
index 4633e08..cf612b5 100644
--- a/dix/protocol.txt
+++ b/dix/protocol.txt
@@ -6,20 +6,6 @@
 #
 # This is a security-sensitive file, please set permissions as appropriate.
 #
-R001 Adobe-DPS-Extension:Init
-R002 Adobe-DPS-Extension:CreateContext
-R003 Adobe-DPS-Extension:CreateSpace
-R004 Adobe-DPS-Extension:GiveInput
-R005 Adobe-DPS-Extension:GetStatus
-R006 Adobe-DPS-Extension:DestroySpace
-R007 Adobe-DPS-Extension:Reset
-R008 Adobe-DPS-Extension:NotifyContext
-R009 Adobe-DPS-Extension:CreateContextFromID
-R010 Adobe-DPS-Extension:XIDFromContext
-R011 Adobe-DPS-Extension:ContextFromXID
-R012 Adobe-DPS-Extension:SetStatusMask
-R013 Adobe-DPS-Extension:CreateSecureContext
-R014 Adobe-DPS-Extension:NotifyWhenReady
 R000 Apple-DRI:QueryVersion
 R001 Apple-DRI:QueryDirectRenderingCapable
 R002 Apple-DRI:CreateSurface
@@ -65,22 +51,6 @@ R003 DAMAGE:Subtract
 R004 DAMAGE:Add
 V000 DAMAGE:Notify
 E000 DAMAGE:BadDamage
-R000 DEC-XTRAP:Reset
-R001 DEC-XTRAP:GetAvailable
-R002 DEC-XTRAP:Config
-R003 DEC-XTRAP:StartTrap
-R004 DEC-XTRAP:StopTrap
-R005 DEC-XTRAP:GetCurrent
-R006 DEC-XTRAP:GetStatistics
-R007 DEC-XTRAP:SimulateXEvent
-R008 DEC-XTRAP:GetVersion
-R009 DEC-XTRAP:GetLastInpTime
-V000 DEC-XTRAP:Event
-E002 DEC-XTRAP:BadIO
-E004 DEC-XTRAP:BadStatistics
-E005 DEC-XTRAP:BadDevices
-E007 DEC-XTRAP:BadScreen
-E008 DEC-XTRAP:BadSwapReq
 R000 DMX:DMXQueryVersion
 R001 DMX:DMXGetScreenCount
 R002 DMX:DMXGetScreenInfoDEPRECATED
@@ -614,125 +584,6 @@ E014 X11:BadIDChoice
 E015 X11:BadName
 E016 X11:BadLength
 E017 X11:BadImplementation
-R001 X3D-PEX:GetExtensionInfo
-R002 X3D-PEX:GetEnumeratedTypeInfo
-R003 X3D-PEX:GetImpDepConstants
-R004 X3D-PEX:CreateLookupTable
-R005 X3D-PEX:CopyLookupTable
-R006 X3D-PEX:FreeLookupTable
-R007 X3D-PEX:GetTableInfo
-R008 X3D-PEX:GetPredefinedEntries
-R009 X3D-PEX:GetDefinedIndices
-R010 X3D-PEX:GetTableEntry
-R011 X3D-PEX:GetTableEntries
-R012 X3D-PEX:SetTableEntries
-R013 X3D-PEX:DeleteTableEntries
-R014 X3D-PEX:CreatePipelineContext
-R015 X3D-PEX:CopyPipelineContext
-R016 X3D-PEX:FreePipelineContext
-R017 X3D-PEX:GetPipelineContext
-R018 X3D-PEX:ChangePipelineContext
-R019 X3D-PEX:CreateRenderer
-R020 X3D-PEX:FreeRenderer
-R021 X3D-PEX:ChangeRenderer
-R022 X3D-PEX:GetRendererAttributes
-R023 X3D-PEX:GetRendererDynamics
-R024 X3D-PEX:BeginRendering
-R025 X3D-PEX:EndRendering
-R026 X3D-PEX:BeginStructure
-R027 X3D-PEX:EndStructure
-R028 X3D-PEX:OutputCommands
-R029 X3D-PEX:Network
-R030 X3D-PEX:CreateStructure
-R031 X3D-PEX:CopyStructure
-R032 X3D-PEX:DestroyStructures
-R033 X3D-PEX:GetStructureInfo
-R034 X3D-PEX:GetElementInfo
-R035 X3D-PEX:GetStructuresInNetwork
-R036 X3D-PEX:GetAncestors
-R037 X3D-PEX:GetDescendants
-R038 X3D-PEX:FetchElements
-R039 X3D-PEX:SetEditingMode
-R040 X3D-PEX:SetElementPointer
-R041 X3D-PEX:SetElementPointerAtLabel
-R042 X3D-PEX:ElementSearch
-R043 X3D-PEX:StoreElements
-R044 X3D-PEX:DeleteElements
-R045 X3D-PEX:DeleteElementsToLabel
-R046 X3D-PEX:DeleteBetweenLabels
-R047 X3D-PEX:CopyElements
-R048 X3D-PEX:ChangeStructureRefs
-R049 X3D-PEX:CreateNameSet
-R050 X3D-PEX:CopyNameSet
-R051 X3D-PEX:FreeNameSet
-R052 X3D-PEX:GetNameSet
-R053 X3D-PEX:ChangeNameSet
-R054 X3D-PEX:CreateSearchContext
-R055 X3D-PEX:CopySearchContext
-R056 X3D-PEX:FreeSearchContext
-R057 X3D-PEX:GetSearchContext
-R058 X3D-PEX:ChangeSearchContext
-R059 X3D-PEX:SearchNetwork
-R060 X3D-PEX:CreatePhigsWks
-R061 X3D-PEX:FreePhigsWks
-R062 X3D-PEX:GetWksInfo
-R063 X3D-PEX:GetDynamics
-R064 X3D-PEX:GetViewRep
-R065 X3D-PEX:RedrawAllStructures
-R066 X3D-PEX:UpdateWorkstation
-R067 X3D-PEX:RedrawClipRegion
-R068 X3D-PEX:ExecuteDeferredActions
-R069 X3D-PEX:SetViewPriority
-R070 X3D-PEX:SetDisplayUpdateMode
-R071 X3D-PEX:MapDCtoWC
-R072 X3D-PEX:MapWCtoDC
-R073 X3D-PEX:SetViewRep
-R074 X3D-PEX:SetWksWindow
-R075 X3D-PEX:SetWksViewport
-R076 X3D-PEX:SetHlhsrMode
-R077 X3D-PEX:SetWksBufferMode
-R078 X3D-PEX:PostStructure
-R079 X3D-PEX:UnpostStructure
-R080 X3D-PEX:UnpostAllStructures
-R081 X3D-PEX:GetWksPostings
-R082 X3D-PEX:GetPickDevice
-R083 X3D-PEX:ChangePickDevice
-R084 X3D-PEX:CreatePickMeasure
-R085 X3D-PEX:FreePickMeasure
-R086 X3D-PEX:GetPickMeasure
-R087 X3D-PEX:UpdatePickMeasure
-R088 X3D-PEX:OpenFont
-R089 X3D-PEX:CloseFont
-R090 X3D-PEX:QueryFont
-R091 X3D-PEX:ListFonts
-R092 X3D-PEX:ListFontsWithInfo
-R093 X3D-PEX:QueryTextExtents
-R094 X3D-PEX:MatchRenderingTargets
-R095 X3D-PEX:Escape
-R096 X3D-PEX:EscapeWithReply
-R097 X3D-PEX:Elements
-R098 X3D-PEX:AccumulateState
-R099 X3D-PEX:BeginPickOne
-R100 X3D-PEX:EndPickOne
-R101 X3D-PEX:PickOne
-R102 X3D-PEX:BeginPickAll
-R103 X3D-PEX:EndPickAll
-R104 X3D-PEX:PickAll
-E000 X3D-PEX:ColorTypeError
-E001 X3D-PEX:erStateError
-E002 X3D-PEX:FloatingPointFormatError
-E003 X3D-PEX:LabelError
-E004 X3D-PEX:LookupTableError
-E005 X3D-PEX:NameSetError
-E006 X3D-PEX:PathError
-E007 X3D-PEX:FontError
-E008 X3D-PEX:PhigsWksError
-E009 X3D-PEX:PickMeasureError
-E010 X3D-PEX:PipelineContextError
-E011 X3D-PEX:erError
-E012 X3D-PEX:SearchContextError
-E013 X3D-PEX:StructureError
-E014 X3D-PEX:OutputCommandError
 R000 XC-APPGROUP:QueryVersion
 R001 XC-APPGROUP:Create
 R002 XC-APPGROUP:Destroy
@@ -876,39 +727,6 @@ E003 XFree86-VidModeExtension:ModeUnsuitable
 E004 XFree86-VidModeExtension:ExtensionDisabled
 E005 XFree86-VidModeExtension:ClientNotLocal
 E006 XFree86-VidModeExtension:ZoomLocked
-R001 XIE:QueryImageExtension
-R002 XIE:QueryTechniques
-R003 XIE:CreateColorList
-R004 XIE:DestroyColorList
-R005 XIE:PurgeColorList
-R006 XIE:QueryColorList
-R007 XIE:CreateLUT
-R008 XIE:DestroyLUT
-R009 XIE:CreatePhotomap
-R010 XIE:DestroyPhotomap
-R011 XIE:QueryPhotomap
-R012 XIE:CreateROI
-R013 XIE:DestroyROI
-R014 XIE:CreatePhotospace
-R015 XIE:DestroyPhotospace
-R016 XIE:ExecuteImmediate
-R017 XIE:CreatePhotoflo
-R018 XIE:DestroyPhotoflo
-R019 XIE:ExecutePhotoflo
-R020 XIE:ModifyPhotoflo
-R021 XIE:RedefinePhotoflo
-R022 XIE:PutClientData
-R023 XIE:GetClientData
-R024 XIE:QueryPhotoflo
-R025 XIE:Await
-R026 XIE:Abort
-E000 XIE:ColorListError
-E001 XIE:LUTError
-E002 XIE:PhotofloError
-E003 XIE:PhotomapError
-E004 XIE:PhotospaceError
-E005 XIE:ROIError
-E006 XIE:FloError
 R000 XINERAMA:QueryVersion
 R001 XINERAMA:GetState
 R002 XINERAMA:GetScreenCount
commit 21f384b7b8b571151805674c9d384e2ad7f8b7ea
Author: Marek Chalupa <mchqwerty at gmail.com>
Date:   Thu May 21 15:43:43 2015 +0200

    xwayland: do not add output into output_list multiple times
    
    output.done event can be sent even on some property change, not only
    when announcing the output. Therefore we must check if we already have it
    otherwise we may corrupt the list by adding it multiple times.
    
    This fixes bug when xwayland looped indefinitely in output.done handler
    and that can be reproduced following these steps (under X without
    multi-monitor setup):
     1) run weston --output-count=2
     2) run xterm, move it so that half is on one output
        and half on the other
     3) close second output, try run weston-terminal
    
    weston sends updated outputs which trigger this bug.
    
    v2. factor out common code into function
        move expecting_events into right branch
    
    Signed-off-by: Marek Chalupa <mchqwerty at gmail.com>

diff --git a/hw/xwayland/xwayland-output.c b/hw/xwayland/xwayland-output.c
index 28aec8e..1546eaa 100644
--- a/hw/xwayland/xwayland-output.c
+++ b/hw/xwayland/xwayland-output.c
@@ -113,29 +113,47 @@ output_handle_mode(void *data, struct wl_output *wl_output, uint32_t flags,
                  xwl_output->rotation, NULL, 1, &xwl_output->randr_output);
 }
 
+static inline void
+output_get_new_size(struct xwl_output *xwl_output,
+		    int *height, int *width)
+{
+    if (*width < xwl_output->x + xwl_output->width)
+        *width = xwl_output->x + xwl_output->width;
+
+    if (*height < xwl_output->y + xwl_output->height)
+        *height = xwl_output->y + xwl_output->height;
+}
+
 static void
 output_handle_done(void *data, struct wl_output *wl_output)
 {
-    struct xwl_output *xwl_output = data;
+    struct xwl_output *it, *xwl_output = data;
     struct xwl_screen *xwl_screen = xwl_output->xwl_screen;
-    int width, height;
+    int width = 0, height = 0, has_this_output = 0;
 
-    xorg_list_append(&xwl_output->link, &xwl_screen->output_list);
+    xorg_list_for_each_entry(it, &xwl_screen->output_list, link) {
+        /* output done event is sent even when some property
+         * of output is changed. That means that we may already
+         * have this output. If it is true, we must not add it
+         * into the output_list otherwise we'll corrupt it */
+        if (it == xwl_output)
+            has_this_output = 1;
 
-    width = 0;
-    height = 0;
-    xorg_list_for_each_entry(xwl_output, &xwl_screen->output_list, link) {
-        if (width < xwl_output->x + xwl_output->width)
-            width = xwl_output->x + xwl_output->width;
-        if (height < xwl_output->y + xwl_output->height)
-            height = xwl_output->y + xwl_output->height;
+        output_get_new_size(it, &height, &width);
+    }
+
+    if (!has_this_output) {
+        xorg_list_append(&xwl_output->link, &xwl_screen->output_list);
+
+        /* we did not check this output for new screen size, do it now */
+        output_get_new_size(xwl_output, &height, &width);
+
+	--xwl_screen->expecting_event;
     }
 
     xwl_screen->width = width;
     xwl_screen->height = height;
     RRScreenSizeNotify(xwl_screen->screen);
-
-    xwl_screen->expecting_event--;
 }
 
 static void
commit 95014ad2a7815282efdecc895bf14742b4b3ccb3
Author: Dima Ryazanov <dima at gmail.com>
Date:   Tue May 12 10:21:18 2015 -0700

    xwayland: Remove the output from the list after destroying it
    
    [Marek Chalupa]: rebased to master
    
    Signed-off-by: Dima Ryazanov <dima at gmail.com>

diff --git a/hw/xwayland/xwayland-output.c b/hw/xwayland/xwayland-output.c
index 927224a..28aec8e 100644
--- a/hw/xwayland/xwayland-output.c
+++ b/hw/xwayland/xwayland-output.c
@@ -185,6 +185,7 @@ void
 xwl_output_destroy(struct xwl_output *xwl_output)
 {
     wl_output_destroy(xwl_output->output);
+    xorg_list_del(&xwl_output->link);
     free(xwl_output);
 }
 
commit 550984c95ef0bee1886dbb54e35edc0852772e2f
Author: Dima Ryazanov <dima at gmail.com>
Date:   Fri May 15 22:38:28 2015 -0700

    xwayland: Destroy xwl_output when wl_output gets removed
    
    This makes Xwayland correctly handle a monitor getting unplugged.
    
    [Marek]: use xorg_list_for_each_entry_safe
    
    Signed-off-by: Dima Ryazanov <dima at gmail.com>
    Signed-off-by: Marek Chalupa <mchqwerty at gmail.com>

diff --git a/hw/xwayland/xwayland-output.c b/hw/xwayland/xwayland-output.c
index dd169e8..927224a 100644
--- a/hw/xwayland/xwayland-output.c
+++ b/hw/xwayland/xwayland-output.c
@@ -165,6 +165,7 @@ xwl_output_create(struct xwl_screen *xwl_screen, uint32_t id)
 
     xwl_output->output = wl_registry_bind(xwl_screen->registry, id,
                                           &wl_output_interface, 2);
+    xwl_output->server_output_id = id;
     wl_output_add_listener(xwl_output->output, &output_listener, xwl_output);
 
     snprintf(name, sizeof name, "XWAYLAND%d", serial++);
diff --git a/hw/xwayland/xwayland.c b/hw/xwayland/xwayland.c
index f25bc00..e31becf 100644
--- a/hw/xwayland/xwayland.c
+++ b/hw/xwayland/xwayland.c
@@ -410,7 +410,16 @@ registry_global(void *data, struct wl_registry *registry, uint32_t id,
 static void
 global_remove(void *data, struct wl_registry *registry, uint32_t name)
 {
-    /* Nothing to do here, wl_compositor and wl_shm should not be removed */
+    struct xwl_screen *xwl_screen = data;
+    struct xwl_output *xwl_output, *tmp_xwl_output;
+
+    xorg_list_for_each_entry_safe(xwl_output, tmp_xwl_output,
+                                  &xwl_screen->output_list, link) {
+        if (xwl_output->server_output_id == name) {
+            xwl_output_destroy(xwl_output);
+            break;
+        }
+    }
 }
 
 static const struct wl_registry_listener registry_listener = {
diff --git a/hw/xwayland/xwayland.h b/hw/xwayland/xwayland.h
index 53ca420..a7d7119 100644
--- a/hw/xwayland/xwayland.h
+++ b/hw/xwayland/xwayland.h
@@ -142,6 +142,7 @@ struct xwl_seat {
 struct xwl_output {
     struct xorg_list link;
     struct wl_output *output;
+    uint32_t server_output_id;
     struct xwl_screen *xwl_screen;
     RROutputPtr randr_output;
     RRCrtcPtr randr_crtc;
commit 6ca496b7c3ccfd677c8c1bee88cc509a5e3c9e04
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Sep 21 22:36:41 2015 -0700

    dri2: better checks for integer overflow in GetBuffers*
    
    Check for integer overflow before using stuff->count in a multiplication,
    to avoid compiler optimizing out due to undefined behaviour, but only
    after we've checked to make sure stuff->count is in the range of the
    request we're parsing.
    
    Reported-by: jes at posteo.de
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/hw/xfree86/dri2/dri2ext.c b/hw/xfree86/dri2/dri2ext.c
index 221ec53..520b7cf 100644
--- a/hw/xfree86/dri2/dri2ext.c
+++ b/hw/xfree86/dri2/dri2ext.c
@@ -269,9 +269,11 @@ ProcDRI2GetBuffers(ClientPtr client)
     int status, width, height, count;
     unsigned int *attachments;
 
-    REQUEST_FIXED_SIZE(xDRI2GetBuffersReq, stuff->count * 4);
-    if (stuff->count > (INT_MAX / 4))
+    REQUEST_AT_LEAST_SIZE(xDRI2GetBuffersReq);
+    /* stuff->count is a count of CARD32 attachments that follows */
+    if (stuff->count > (INT_MAX / sizeof(CARD32)))
         return BadLength;
+    REQUEST_FIXED_SIZE(xDRI2GetBuffersReq, stuff->count * sizeof(CARD32));
 
     if (!validDrawable(client, stuff->drawable, DixReadAccess | DixWriteAccess,
                        &pDrawable, &status))
@@ -297,7 +299,13 @@ ProcDRI2GetBuffersWithFormat(ClientPtr client)
     int status, width, height, count;
     unsigned int *attachments;
 
-    REQUEST_FIXED_SIZE(xDRI2GetBuffersReq, stuff->count * (2 * 4));
+    REQUEST_AT_LEAST_SIZE(xDRI2GetBuffersReq);
+    /* stuff->count is a count of pairs of CARD32s (attachments & formats)
+       that follows */
+    if (stuff->count > (INT_MAX / (2 * sizeof(CARD32))))
+        return BadLength;
+    REQUEST_FIXED_SIZE(xDRI2GetBuffersReq,
+                       stuff->count * (2 * sizeof(CARD32)));
     if (!validDrawable(client, stuff->drawable, DixReadAccess | DixWriteAccess,
                        &pDrawable, &status))
         return status;
commit 6c2c6fb5a7b44f50811722eb8621afb272aff2e8
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Sep 21 07:16:14 2015 +0100

    Xext, os: Remove OS-internal usages within XACE and XSELinux
    
    These extensions were accessing internal OS functions and
    structures. Expose the necessary functionality to them and remove
    their use of osdep.h
    
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/xace.c b/Xext/xace.c
index b3c67f6..fcb38db 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -29,11 +29,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "gcstruct.h"
 #include "xacestr.h"
 
-#define XSERV_t
-#define TRANS_SERVER
-#include <X11/Xtrans/Xtrans.h>
-#include "../os/osdep.h"
-
 _X_EXPORT CallbackListPtr XaceHooks[XACE_NUM_HOOKS] = { 0 };
 
 /* Special-cased hook functions.  Called by Xserver.
@@ -342,15 +337,11 @@ XaceCensorImage(ClientPtr client,
 int
 XaceGetConnectionNumber(ClientPtr client)
 {
-    XtransConnInfo ci = ((OsCommPtr) client->osPrivate)->trans_conn;
-
-    return _XSERVTransGetConnectionNumber(ci);
+    return GetClientFd(client);
 }
 
 int
 XaceIsLocal(ClientPtr client)
 {
-    XtransConnInfo ci = ((OsCommPtr) client->osPrivate)->trans_conn;
-
-    return _XSERVTransIsLocal(ci);
+    return ClientIsLocal(client);
 }
diff --git a/Xext/xselinux_hooks.c b/Xext/xselinux_hooks.c
index e69bfe7..d9f2f68 100644
--- a/Xext/xselinux_hooks.c
+++ b/Xext/xselinux_hooks.c
@@ -41,7 +41,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "extnsionst.h"
 #include "xacestr.h"
 #include "client.h"
-#include "../os/osdep.h"
 #define _XSELINUX_NEED_FLASK_MAP
 #include "xselinuxint.h"
 
diff --git a/include/os.h b/include/os.h
index b2b96c8..9937f2e 100644
--- a/include/os.h
+++ b/include/os.h
@@ -415,6 +415,7 @@ typedef struct {
 
 extern _X_EXPORT int
 GetLocalClientCreds(ClientPtr, LocalClientCredRec **);
+
 extern _X_EXPORT void
 FreeLocalClientCreds(LocalClientCredRec *);
 
@@ -422,6 +423,12 @@ extern _X_EXPORT int
 ChangeAccessControl(ClientPtr /*client */ , int /*fEnabled */ );
 
 extern _X_EXPORT int
+GetClientFd(ClientPtr);
+
+extern _X_EXPORT Bool
+ClientIsLocal(ClientPtr client);
+
+extern _X_EXPORT int
 GetAccessControl(void);
 
 extern _X_EXPORT void
diff --git a/os/access.c b/os/access.c
index 54f0690..2499a9f 100644
--- a/os/access.c
+++ b/os/access.c
@@ -1574,6 +1574,20 @@ GetAccessControl(void)
     return AccessEnabled;
 }
 
+int
+GetClientFd(ClientPtr client)
+{
+    return ((OsCommPtr) client->osPrivate)->fd;
+}
+
+Bool
+ClientIsLocal(ClientPtr client)
+{
+    XtransConnInfo ci = ((OsCommPtr) client->osPrivate)->trans_conn;
+
+    return _XSERVTransIsLocal(ci);
+}
+
 /*****************************************************************************
  * FamilyServerInterpreted host entry implementation
  *
commit 9af111fe045d82192bacc722940e1d92a8ba4cbd
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Sep 21 07:16:13 2015 +0100

    Xext/xselinux: Warning fixes
    
    There's a 'const char *' adventure here that I'm mostly ignoring; some
    client information gets const poisoned. Worked around by adding a
    couple of casts. Ick.
    
    Added an _X_ATTRIBUTE_PRINTF to SELinuxLog.
    
    Ignore a couple of unused return values.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/xselinux_hooks.c b/Xext/xselinux_hooks.c
index 48219a9..e69bfe7 100644
--- a/Xext/xselinux_hooks.c
+++ b/Xext/xselinux_hooks.c
@@ -147,7 +147,7 @@ SELinuxLabelClient(ClientPtr client)
         strncpy(subj->command, cmdname, COMMAND_LEN - 1);
 
         if (!cached)
-            free(cmdname);     /* const char * */
+            free((void *) cmdname);     /* const char * */
     }
 
  finish:
@@ -295,6 +295,9 @@ SELinuxAudit(void *auditdata,
 }
 
 static int
+SELinuxLog(int type, const char *fmt, ...) _X_ATTRIBUTE_PRINTF(2, 3);
+
+static int
 SELinuxLog(int type, const char *fmt, ...)
 {
     va_list ap;
@@ -316,6 +319,7 @@ SELinuxLog(int type, const char *fmt, ...)
     va_start(ap, fmt);
     vsnprintf(buf, MAX_AUDIT_MESSAGE_LENGTH, fmt, ap);
     rc = audit_log_user_avc_message(audit_fd, aut, buf, NULL, NULL, NULL, 0);
+    (void) rc;
     va_end(ap);
     LogMessageVerb(X_WARNING, 0, "%s", buf);
     return 0;
@@ -476,7 +480,7 @@ SELinuxExtension(CallbackListPtr *pcbl, void *unused, void *calldata)
     }
 
     /* Perform the security check */
-    auditdata.extension = rec->ext->name;
+    auditdata.extension = (char *) rec->ext->name;
     rc = SELinuxDoCheck(subj, obj, SECCLASS_X_EXTENSION, rec->access_mode,
                         &auditdata);
     if (rc != Success)
commit 9ee05c8987245350976ebc0df4953c60da6bcc70
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Thu Aug 13 13:11:31 2015 +0100

    debug output format fix in RRMonitorCrtcName()
    
    xorg/xserver/randr/rrmonitor.c:35:5: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 3 has type ‘RRCrtc’ [-Werror=format=]
    
    RRCrtc is XID is CARD32, which inside the server is unsigned long or int
    depending on architecture, so a cast is required.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>

diff --git a/randr/rrmonitor.c b/randr/rrmonitor.c
index 05285dd..c37dcf8 100644
--- a/randr/rrmonitor.c
+++ b/randr/rrmonitor.c
@@ -32,7 +32,7 @@ RRMonitorCrtcName(RRCrtcPtr crtc)
         RROutputPtr     output = crtc->outputs[0];
         return MakeAtom(output->name, output->nameLength, TRUE);
     }
-    sprintf(name, "Monitor-%08x", crtc->id);
+    sprintf(name, "Monitor-%08lx", (unsigned long int)crtc->id);
     return MakeAtom(name, strlen(name), TRUE);
 }
 
commit fe253296035277f7a3adfad6eb239fee41714d22
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Thu Aug 13 13:11:37 2015 +0100

    debug output format fix in xf86Helper.c
    
    xserver/hw/xfree86/common/xf86Helper.c:1834:12: error: format ‘%ld’ expects argument of type ‘long int’, but argument 3 has type ‘Atom’ [-Werror=format=]
    xserver/hw/xfree86/common/xf86Helper.c:1834:12: error: format ‘%ld’ expects argument of type ‘long int’, but argument 4 has type ‘Atom’ [-Werror=format=]
    
    Atom is unfortunately unsigned long or unsigned int depending on the
    architecture, so a cast is required.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>

diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index 359bac7..c42e93e 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -1831,7 +1831,7 @@ xf86RegisterRootWindowProperty(int ScrnIndex, Atom property, Atom type,
     Bool existing = FALSE;
 
     DebugF("xf86RegisterRootWindowProperty(%d, %ld, %ld, %d, %ld, %p)\n",
-           ScrnIndex, property, type, format, len, value);
+           ScrnIndex, (long)property, (long)type, format, len, value);
 
     if (ScrnIndex < 0 || ScrnIndex >= xf86NumScreens) {
         return BadMatch;
commit dc2998bf060957b1fdd6bd2ea4f76c5154233a1b
Author: Dima Ryazanov <dima at gmail.com>
Date:   Tue May 12 10:21:19 2015 -0700

    xwayland: Remove a useless out-of-memory check
    
    snprintf does not allocate memory, so we can never get an out-of-memory
    error.
    
    (Also, the error handler would free xwl_output after it was already
    registered as an event listener.)
    
    Signed-off-by: Dima Ryazanov <dima at gmail.com>
    Reviewed-by: Marek Chalupa <mchqwerty at gmail.com>

diff --git a/hw/xwayland/xwayland-output.c b/hw/xwayland/xwayland-output.c
index 7e5484c..dd169e8 100644
--- a/hw/xwayland/xwayland-output.c
+++ b/hw/xwayland/xwayland-output.c
@@ -167,11 +167,7 @@ xwl_output_create(struct xwl_screen *xwl_screen, uint32_t id)
                                           &wl_output_interface, 2);
     wl_output_add_listener(xwl_output->output, &output_listener, xwl_output);
 
-    if (snprintf(name, sizeof name, "XWAYLAND%d", serial++) < 0) {
-        ErrorF("create_output ENOMEM\n");
-        free(xwl_output);
-        return NULL;
-    }
+    snprintf(name, sizeof name, "XWAYLAND%d", serial++);
 
     xwl_output->xwl_screen = xwl_screen;
     xwl_output->randr_crtc = RRCrtcCreate(xwl_screen->screen, xwl_output);
commit b469fc72d2dd0cf60760fa0828ed73771c2a0512
Author: Adam Jackson <ajax at redhat.com>
Date:   Wed Feb 25 16:03:13 2015 -0500

    composite: Factor out backing store transition
    
    No functional change.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/composite/compinit.c b/composite/compinit.c
index cf61f2a..791fec9 100644
--- a/composite/compinit.c
+++ b/composite/compinit.c
@@ -105,6 +105,20 @@ compInstallColormap(ColormapPtr pColormap)
     pScreen->InstallColormap = compInstallColormap;
 }
 
+static void
+compCheckBackingStore(WindowPtr pWin)
+{
+    if (pWin->backingStore != NotUseful && !pWin->backStorage) {
+        compRedirectWindow(serverClient, pWin, CompositeRedirectAutomatic);
+        pWin->backStorage = TRUE;
+    }
+    else if (pWin->backingStore == NotUseful && pWin->backStorage) {
+        compUnredirectWindow(serverClient, pWin,
+                             CompositeRedirectAutomatic);
+        pWin->backStorage = FALSE;
+    }
+}
+
 /* Fake backing store via automatic redirection */
 static Bool
 compChangeWindowAttributes(WindowPtr pWin, unsigned long mask)
@@ -117,17 +131,8 @@ compChangeWindowAttributes(WindowPtr pWin, unsigned long mask)
     ret = pScreen->ChangeWindowAttributes(pWin, mask);
 
     if (ret && (mask & CWBackingStore) &&
-        pScreen->backingStoreSupport != NotUseful) {
-        if (pWin->backingStore != NotUseful && !pWin->backStorage) {
-            compRedirectWindow(serverClient, pWin, CompositeRedirectAutomatic);
-            pWin->backStorage = TRUE;
-        }
-        else if (pWin->backingStore == NotUseful && pWin->backStorage) {
-            compUnredirectWindow(serverClient, pWin,
-                                 CompositeRedirectAutomatic);
-            pWin->backStorage = FALSE;
-        }
-    }
+        pScreen->backingStoreSupport != NotUseful)
+        compCheckBackingStore(pWin);
 
     pScreen->ChangeWindowAttributes = compChangeWindowAttributes;
 
commit 6da3f5d04f6a1cda0c858280f9561f9fbc323275
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Sep 23 11:19:00 2015 +1000

    glx: fix regression with copy sub buffer disappearing
    
    So copy sub buffer isn't a core extensions it's a driver extension
    which means we are using totally the wrong interface to query for it
    here, which means bad things happen when you roll out this code,
    for instance MESA_copy_sub_buffer stops working.
    
    This is just the hack I'm sticking in Fedora to avoid the regression
    for now, but hopefully will inspire us.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/glx/glxdriswrast.c b/glx/glxdriswrast.c
index 9add2a1..e8e53bf 100644
--- a/glx/glxdriswrast.c
+++ b/glx/glxdriswrast.c
@@ -396,6 +396,9 @@ initializeExtensions(__GLXDRIscreen * screen)
     const __DRIextension **extensions;
     int i;
 
+    __glXEnableExtension(screen->glx_enable_bits, "GLX_MESA_copy_sub_buffer");
+    LogMessage(X_INFO, "AIGLX: enabled GLX_MESA_copy_sub_buffer\n");
+
     if (screen->swrast->base.version >= 3) {
         __glXEnableExtension(screen->glx_enable_bits,
                              "GLX_ARB_create_context");
@@ -416,8 +419,6 @@ initializeExtensions(__GLXDRIscreen * screen)
         if (strcmp(extensions[i]->name, __DRI_COPY_SUB_BUFFER) == 0) {
             screen->copySubBuffer =
                 (const __DRIcopySubBufferExtension *) extensions[i];
-            __glXEnableExtension(screen->glx_enable_bits,
-                                 "GLX_MESA_copy_sub_buffer");
         }
 
         if (strcmp(extensions[i]->name, __DRI_TEX_BUFFER) == 0) {
commit 5e9457c41c05b65da7e39bd8944ec761479f19dd
Author: Eric Anholt <eric at anholt.net>
Date:   Mon May 5 11:10:07 2014 -0700

    fbdevhw: Fix a const qualifier warning
    
    We're passing string literals to these functions.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/hw/xfree86/fbdevhw/fbdevhw.c b/hw/xfree86/fbdevhw/fbdevhw.c
index eb458fb..b50ae5e 100644
--- a/hw/xfree86/fbdevhw/fbdevhw.c
+++ b/hw/xfree86/fbdevhw/fbdevhw.c
@@ -122,7 +122,7 @@ fbdevHWGetFD(ScrnInfoPtr pScrn)
 
 #if DEBUG
 static void
-print_fbdev_mode(char *txt, struct fb_var_screeninfo *var)
+print_fbdev_mode(const char *txt, struct fb_var_screeninfo *var)
 {
     ErrorF("fbdev %s mode:\t%d   %d %d %d %d   %d %d %d %d   %d %d:%d:%d\n",
            txt, var->pixclock,
@@ -133,7 +133,7 @@ print_fbdev_mode(char *txt, struct fb_var_screeninfo *var)
 }
 
 static void
-print_xfree_mode(char *txt, DisplayModePtr mode)
+print_xfree_mode(const char *txt, DisplayModePtr mode)
 {
     ErrorF("xfree %s mode:\t%d   %d %d %d %d   %d %d %d %d\n",
            txt, mode->Clock,
commit 88355cedfc9b3940b9fe1599fbf6e0272c57f8a9
Author: Eric Anholt <eric at anholt.net>
Date:   Mon May 5 11:10:08 2014 -0700

    kdrive: Remove dead debug arrays.
    
    These have never been used in the history of the tree, and were
    producing string literal const loss warnings.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
index 057f53b..4bb9315 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -1641,41 +1641,6 @@ KdClassifyInput(KdPointerInfo * pi, int type, int x, int y, int z, int b)
     return keyboard;
 }
 
-#ifdef DEBUG
-char *kdStateNames[] = {
-    "start",
-    "button_1_pend",
-    "button_1_down",
-    "button_2_down",
-    "button_3_pend",
-    "button_3_down",
-    "synth_2_down_13",
-    "synth_2_down_3",
-    "synthetic_2_down_1",
-    "num_input_states"
-};
-
-char *kdClassNames[] = {
-    "down_1", "up_1",
-    "down_2", "up_2",
-    "down_3", "up_3",
-    "motion", "ouside_box",
-    "keyboard", "timeout",
-    "num_input_class"
-};
-
-char *kdActionNames[] = {
-    "noop",
-    "hold",
-    "setto",
-    "deliver",
-    "release",
-    "clearto",
-    "gen_down_2",
-    "gen_up_2",
-};
-#endif                          /* DEBUG */
-
 /* We return true if we're stealing the event. */
 static Bool
 KdRunMouseMachine(KdPointerInfo * pi, KdInputClass c, int type, int x, int y,
commit e6f8a0340b72113474ccfbf1ea447558b705995a
Author: Eric Anholt <eric at anholt.net>
Date:   Mon May 5 11:10:06 2014 -0700

    x86emu: Fix some set-but-not-used warnings.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/hw/xfree86/x86emu/debug.c b/hw/xfree86/x86emu/debug.c
index cbea994..72a06ff 100644
--- a/hw/xfree86/x86emu/debug.c
+++ b/hw/xfree86/x86emu/debug.c
@@ -233,9 +233,7 @@ X86EMU_dump_memory(u16 seg, u16 off, u32 amt)
     u32 start = off & 0xfffffff0;
     u32 end = (off + 16) & 0xfffffff0;
     u32 i;
-    u32 current;
 
-    current = start;
     while (end <= off + amt) {
         printk("%04x:%04x ", seg, start);
         for (i = start; i < off; i++)
@@ -261,8 +259,6 @@ x86emu_single_step(void)
     static int breakpoint;
     static int noDecode = 1;
 
-    char *p;
-
     if (DEBUG_BREAK()) {
         if (M.x86.saved_ip != breakpoint) {
             return;
@@ -279,7 +275,7 @@ x86emu_single_step(void)
     offset = M.x86.saved_ip;
     while (!done) {
         printk("-");
-        p = fgets(s, 1023, stdin);
+        (void)fgets(s, 1023, stdin);
         cmd = parse_line(s, ps, &ntok);
         switch (cmd) {
         case 'u':
commit fca98ce5e7d6424265c35a1219c2240d3342f627
Author: Egbert Eich <eich at freedesktop.org>
Date:   Fri Feb 7 16:21:48 2014 +0100

    libxf86config: libxf86config_internal -> libxf86config
    
    Now since the installable libxf86config is gone, rename
    libxf86config_internal to libxf86config.
    
    Signed-off-by: Egbert Eich <eich at freedesktop.org>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/Makefile.am b/hw/xfree86/Makefile.am
index 27f2cc6..c45d8c9 100644
--- a/hw/xfree86/Makefile.am
+++ b/hw/xfree86/Makefile.am
@@ -59,7 +59,7 @@ LOCAL_LIBS = \
             loader/libloader.la \
             common/libcommon.la \
             os-support/libxorgos.la \
-            parser/libxf86config_internal.la \
+            parser/libxf86config.la \
             dixmods/libdixmods.la \
             modes/libxf86modes.la \
             ramdac/libramdac.la \
diff --git a/hw/xfree86/parser/Makefile.am b/hw/xfree86/parser/Makefile.am
index 8e496bf..9aa8cfe 100644
--- a/hw/xfree86/parser/Makefile.am
+++ b/hw/xfree86/parser/Makefile.am
@@ -1,4 +1,4 @@
-noinst_LTLIBRARIES = libxf86config_internal.la
+noinst_LTLIBRARIES = libxf86config.la
 
 INTERNAL_SOURCES= \
 	Device.c \
@@ -20,7 +20,7 @@ INTERNAL_SOURCES= \
 	DRI.c \
 	Extensions.c
 
-libxf86config_internal_la_SOURCES = \
+libxf86config_la_SOURCES = \
 	$(INTERNAL_SOURCES)
 
 AM_CFLAGS = $(DIX_CFLAGS) $(XORG_CFLAGS) \
diff --git a/test/Makefile.am b/test/Makefile.am
index 82578d9..4d935a2 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -49,7 +49,7 @@ libxservertest_la_LIBADD += \
             $(top_builddir)/hw/xfree86/loader/libloader.la \
             $(top_builddir)/hw/xfree86/os-support/libxorgos.la \
             $(top_builddir)/hw/xfree86/common/libcommon.la \
-            $(top_builddir)/hw/xfree86/parser/libxf86config_internal.la \
+            $(top_builddir)/hw/xfree86/parser/libxf86config.la \
             $(top_builddir)/hw/xfree86/dixmods/libdixmods.la \
             $(top_builddir)/hw/xfree86/modes/libxf86modes.la \
             $(top_builddir)/hw/xfree86/ramdac/libramdac.la \
commit dabf7c3590b427c185089128ecfd967f188f2658
Author: Egbert Eich <eich at freedesktop.org>
Date:   Fri Feb 7 16:21:47 2014 +0100

    libxf86config: Remove
    
    The library used by the Xserver to read and parse the configuration file
    could be built so that it culd be installed as a separate lib and used
    by external programs.
    
    Apparently there has not been any interest in this for quite a while as
    this library has been broken for a long time now in the sense that it
    was calling functions provided by the Xserver which were not implemented
    for the external library.
    
    Since this library is useless as it is anyway when built let's drop
    support for it.
    
    Signed-off-by: Egbert Eich <eich at freedesktop.org>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index f38345a..e434720 100644
--- a/configure.ac
+++ b/configure.ac
@@ -565,11 +565,6 @@ AC_ARG_ENABLE(sparkle,AS_HELP_STRING([--enable-sparkle], [Enable updating of X11
 				[ XQUARTZ_SPARKLE="${enableval}" ],
 				[ XQUARTZ_SPARKLE="no" ])
 AC_SUBST([XQUARTZ_SPARKLE])
-AC_ARG_ENABLE(install-libxf86config,
-				AS_HELP_STRING([--enable-install-libxf86config],
-				[Install libxf86config (default: disabled)]),
-				[INSTALL_LIBXF86CONFIG=$enableval],
-				[INSTALL_LIBXF86CONFIG=no])
 AC_ARG_ENABLE(visibility,     AS_HELP_STRING([--enable-visibility], [Enable symbol visibility (default: auto)]),
 				[SYMBOL_VISIBILITY=$enableval],
 				[SYMBOL_VISIBILITY=auto])
@@ -695,9 +690,6 @@ AM_CONDITIONAL(INT10_VM86, [test "x$INT10" = xvm86])
 AM_CONDITIONAL(INT10_X86EMU, [test "x$INT10" = xx86emu])
 AM_CONDITIONAL(INT10_STUB, [test "x$INT10" = xstub])
 
-dnl Handle installing libxf86config
-AM_CONDITIONAL(INSTALL_LIBXF86CONFIG, [test "x$INSTALL_LIBXF86CONFIG" = xyes])
-
 dnl DDX Detection... Yes, it's ugly to have it here... but we need to
 dnl handle this early on so that we don't require unsupported extensions
 case $host_os in
diff --git a/hw/xfree86/parser/Makefile.am b/hw/xfree86/parser/Makefile.am
index 4d0bb4f..8e496bf 100644
--- a/hw/xfree86/parser/Makefile.am
+++ b/hw/xfree86/parser/Makefile.am
@@ -1,12 +1,4 @@
-if INSTALL_LIBXF86CONFIG
 noinst_LTLIBRARIES = libxf86config_internal.la
-lib_LTLIBRARIES = libxf86config.la
-LIBHEADERS = \
-	xf86Optrec.h \
-	xf86Parser.h
-else
-noinst_LTLIBRARIES = libxf86config_internal.la
-endif
 
 INTERNAL_SOURCES= \
 	Device.c \
@@ -31,12 +23,6 @@ INTERNAL_SOURCES= \
 libxf86config_internal_la_SOURCES = \
 	$(INTERNAL_SOURCES)
 
-libxf86config_la_SOURCES = \
-	$(top_srcdir)/os/xprintf.c \
-	$(INTERNAL_SOURCES)
-libxf86config_la_CFLAGS = $(AM_CFLAGS)
-libxf86config_la_LDFLAGS = -static
-
 AM_CFLAGS = $(DIX_CFLAGS) $(XORG_CFLAGS) \
 	-DSYSCONFDIR=\"$(sysconfdir)\" \
 	-DDATADIR=\"$(datadir)\"
diff --git a/hw/xfree86/parser/configProcs.h b/hw/xfree86/parser/configProcs.h
index e6c231e..171f8e8 100644
--- a/hw/xfree86/parser/configProcs.h
+++ b/hw/xfree86/parser/configProcs.h
@@ -27,8 +27,7 @@
 
 /* Private procs.  Public procs are in xf86Parser.h and xf86Optrec.h */
 
-/* exported functions are/were used by the X Server, and need to be
- * made public when installing libxf86config */
+/* exported functions are/were used by the X Server */
 
 /* Device.c */
 XF86ConfDevicePtr xf86parseDeviceSection(void);
commit c7f84c880bbbb508016ad80390a11961b1c4214d
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Jan 27 09:44:48 2014 +0000

    render: Fix leak of filter params
    
    ==11097== 2,048 (+1,640) bytes in 32 (+26) blocks are definitely lost in loss record 1,570 of 1,719
    ==11097==    at 0x4C2A2DB: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==11097==    by 0x225EF3: SetPicturePictFilter (filter.c:339)
    ==11097==    by 0x22DF4F: ProcRenderSetPictureFilter (render.c:1773)
    ==11097==    by 0x15D25D: Dispatch (dispatch.c:432)
    ==11097==    by 0x14C7B9: main (main.c:298)
    
    [ajax: Fixed whitespace]
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/render/picture.c b/render/picture.c
index acdd0ae..3d52dec 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -1398,6 +1398,7 @@ FreePicture(void *value, XID pid)
 
     if (--pPicture->refcnt == 0) {
         free(pPicture->transform);
+        free(pPicture->filter_params);
 
         if (pPicture->pSourcePict) {
             if (pPicture->pSourcePict->type != SourcePictTypeSolidFill)
commit 98e170971c6b06d64a5bc7418bf6ae6ae985a3ae
Author: Ville Syrjälä <ville.syrjala at linux.intel.com>
Date:   Mon Oct 14 17:07:29 2013 +0300

    xfree86: Fix the 1792x1344-75 EST III mode
    
    The correct refresh rate for this mode is 75, not 85.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>

diff --git a/hw/xfree86/modes/xf86EdidModes.c b/hw/xfree86/modes/xf86EdidModes.c
index 6fb0f9b..f24294e 100644
--- a/hw/xfree86/modes/xf86EdidModes.c
+++ b/hw/xfree86/modes/xf86EdidModes.c
@@ -713,7 +713,7 @@ static const struct {
     {1600, 1200, 75, 0},
     {1600, 1200, 85, 0},
     {1792, 1344, 60, 0},
-    {1792, 1344, 85, 0},
+    {1792, 1344, 75, 0},
     {1856, 1392, 60, 0},
     {1856, 1392, 75, 0},
     {1920, 1200, 60, 1},
commit 91c7acfc3447a0073dd1db260cf05115d94ce7e8
Author: Michal Srb <msrb at suse.com>
Date:   Mon Oct 7 17:57:14 2013 +0300

    randr: Allow RRSelectInput for ProviderChange and ResourceChange events
    
    [ajax: To be clear, we already have code to emit these events, and it
     looks like it works, but to get them you'd have had to also ask for one
     of the other notify types.  This makes it possible to listen for e.g.
     ProviderChange alone.]
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Michal Srb <msrb at suse.com>

diff --git a/randr/rrdispatch.c b/randr/rrdispatch.c
index 13ac6b1..314e4ea 100644
--- a/randr/rrdispatch.c
+++ b/randr/rrdispatch.c
@@ -92,7 +92,9 @@ ProcRRSelectInput(ClientPtr client)
                          RRCrtcChangeNotifyMask |
                          RROutputChangeNotifyMask |
                          RROutputPropertyNotifyMask |
-                         RRProviderPropertyNotifyMask)) {
+                         RRProviderChangeNotifyMask |
+                         RRProviderPropertyNotifyMask |
+                         RRResourceChangeNotifyMask)) {
         ScreenPtr pScreen = pWin->drawable.pScreen;
 
         rrScrPriv(pScreen);
commit 5437949a51fa6d9c9c83336d46ae57398f390ee3
Author: Egbert Eich <eich at freedesktop.org>
Date:   Sat Oct 5 13:57:13 2013 +0200

    fbdevhw: Disable FBIOBLANK ioctl if not supported
    
    Some ioctls may not be supported by the kernel however their failure
    is non-fatal to the driver. Unfortunately we only know once we try
    to execute the ioctl however the sematics of the fbdev driver API
    doesn't allow upper layers to disable the call.
    Instead of changing the fbdevHW driver API just disable the call to
    this ioctl on the module level when detecting such a case.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Egbert Eich <eich at freedesktop.org>

diff --git a/hw/xfree86/fbdevhw/fbdevhw.c b/hw/xfree86/fbdevhw/fbdevhw.c
index 8cd2079..eb458fb 100644
--- a/hw/xfree86/fbdevhw/fbdevhw.c
+++ b/hw/xfree86/fbdevhw/fbdevhw.c
@@ -76,8 +76,14 @@ typedef struct {
     /* buildin video mode */
     DisplayModeRec buildin;
 
+    /* disable non-fatal unsupported ioctls */
+    CARD32 unsupported_ioctls;
 } fbdevHWRec, *fbdevHWPtr;
 
+enum {
+    FBIOBLANK_UNSUPPORTED = 0,
+};
+
 Bool
 fbdevHWGetRec(ScrnInfoPtr pScrn)
 {
@@ -831,6 +837,9 @@ fbdevHWDPMSSet(ScrnInfoPtr pScrn, int mode, int flags)
     if (!pScrn->vtSema)
         return;
 
+    if (fPtr->unsupported_ioctls & (1 << FBIOBLANK_UNSUPPORTED))
+        return;
+
     switch (mode) {
     case DPMSModeOn:
         fbmode = 0;
@@ -848,9 +857,23 @@ fbdevHWDPMSSet(ScrnInfoPtr pScrn, int mode, int flags)
         return;
     }
 
-    if (-1 == ioctl(fPtr->fd, FBIOBLANK, (void *) fbmode))
-        xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-                   "FBIOBLANK: %s\n", strerror(errno));
+RETRY:
+    if (-1 == ioctl(fPtr->fd, FBIOBLANK, (void *) fbmode)) {
+        switch (errno) {
+        case EAGAIN:
+            xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+                       "FBIOBLANK: %s\n", strerror(errno));
+	    break;
+        case EINTR:
+        case ERESTART:
+            goto RETRY;
+        default:
+            fPtr->unsupported_ioctls |= (1 << FBIOBLANK_UNSUPPORTED);
+            xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+                       "FBIOBLANK: %s (Screen blanking not supported "
+                       "by kernel - disabling)\n", strerror(errno));
+        }
+    }
 }
 
 Bool
@@ -863,11 +886,27 @@ fbdevHWSaveScreen(ScreenPtr pScreen, int mode)
     if (!pScrn->vtSema)
         return TRUE;
 
+    if (fPtr->unsupported_ioctls & (1 << FBIOBLANK_UNSUPPORTED))
+        return FALSE;
+
     unblank = xf86IsUnblank(mode);
 
+RETRY:
     if (-1 == ioctl(fPtr->fd, FBIOBLANK, (void *) (1 - unblank))) {
-        xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-                   "FBIOBLANK: %s\n", strerror(errno));
+        switch (errno) {
+        case EAGAIN:
+            xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+                       "FBIOBLANK: %s\n", strerror(errno));
+            break;
+        case EINTR:
+        case ERESTART:
+            goto RETRY;
+        default:
+            fPtr->unsupported_ioctls |= (1 << FBIOBLANK_UNSUPPORTED);
+            xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+                       "FBIOBLANK: %s (Screen blanking not supported "
+                       "by kernel - disabling)\n", strerror(errno));
+        }
         return FALSE;
     }
 
commit 49fe4ee7b7085b616028d6afe67767a60a8adf82
Author: Matt Turner <mattst88 at gmail.com>
Date:   Thu Feb 7 17:29:00 2013 -0800

    compiler.h: Remove dead STANDALONE_MMIO
    
    The only drivers I can find that used this are the r128 and radeon DRI
    drivers. r128 is dead and the radeon driver wasn't including Xorg's
    compiler.h and still worked.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Matt Turner <mattst88 at gmail.com>

diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h
index 1653574..85fb35c 100644
--- a/hw/xfree86/common/compiler.h
+++ b/hw/xfree86/common/compiler.h
@@ -1036,18 +1036,7 @@ inl(unsigned short port)
 /* entry points for Mmio memory access routines */
 extern _X_EXPORT int (*xf86ReadMmio8) (void *, unsigned long);
 extern _X_EXPORT int (*xf86ReadMmio16) (void *, unsigned long);
-
-#ifndef STANDALONE_MMIO
 extern _X_EXPORT int (*xf86ReadMmio32) (void *, unsigned long);
-#else
-/* Some DRI 3D drivers need MMIO_IN32. */
-static __inline__ int
-xf86ReadMmio32(void *Base, unsigned long Offset)
-{
-    mem_barrier();
-    return *(volatile unsigned int *) ((unsigned long) Base + (Offset));
-}
-#endif
 extern _X_EXPORT void (*xf86WriteMmio8) (int, void *, unsigned long);
 extern _X_EXPORT void (*xf86WriteMmio16) (int, void *, unsigned long);
 extern _X_EXPORT void (*xf86WriteMmio32) (int, void *, unsigned long);
@@ -1059,11 +1048,7 @@ extern _X_EXPORT void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int);
 /* Changed to kill noise generated by gcc's -Wcast-align */
 #define MMIO_IN8(base, offset) (*xf86ReadMmio8)(base, offset)
 #define MMIO_IN16(base, offset) (*xf86ReadMmio16)(base, offset)
-#ifndef STANDALONE_MMIO
 #define MMIO_IN32(base, offset) (*xf86ReadMmio32)(base, offset)
-#else
-#define MMIO_IN32(base, offset) xf86ReadMmio32(base, offset)
-#endif
 
 #define MMIO_OUT32(base, offset, val) \
     do { \
commit d2a6962474978437545120ebc1fcfb909d901d55
Author: Andy Ritger <aritger at nvidia.com>
Date:   Wed Jun 20 11:52:34 2012 -0700

    mi: Log an error if mieqProcessInputEvents() recurses.
    
    v2:
    
    Uses BUG_WARN_MSG to also provide a stack trace. (Peter Hutterer)
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Andy Ritger <aritger at nvidia.com>

diff --git a/mi/mieq.c b/mi/mieq.c
index f7d8721..01812bd 100644
--- a/mi/mieq.c
+++ b/mi/mieq.c
@@ -579,11 +579,20 @@ mieqProcessInputEvents(void)
     InternalEvent event;
     DeviceIntPtr dev = NULL, master = NULL;
     size_t n_enqueued;
+    static Bool inProcessInputEvents = FALSE;
 
 #ifdef XQUARTZ
     pthread_mutex_lock(&miEventQueueMutex);
 #endif
 
+    /*
+     * report an error if mieqProcessInputEvents() is called recursively;
+     * this can happen, e.g., if something in the mieqProcessDeviceEvent()
+     * call chain calls UpdateCurrentTime() instead of UpdateCurrentTimeIf()
+     */
+    BUG_WARN_MSG(inProcessInputEvents, "[mi] mieqProcessInputEvents() called recursively.\n");
+    inProcessInputEvents = TRUE;
+
     /* Grow our queue if we are reaching capacity: < 2 * QUEUE_RESERVED_SIZE remaining */
     n_enqueued = mieqNumEnqueued(&miEventQueue);
     if (n_enqueued >= (miEventQueue.nevents - (2 * QUEUE_RESERVED_SIZE)) &&
@@ -642,6 +651,9 @@ mieqProcessInputEvents(void)
         pthread_mutex_lock(&miEventQueueMutex);
 #endif
     }
+
+    inProcessInputEvents = FALSE;
+
 #ifdef XQUARTZ
     pthread_mutex_unlock(&miEventQueueMutex);
 #endif
commit cc57ab4fc8b9dc15531f0dd9f5b352fa99a80cd0
Author: Andy Ritger <aritger at nvidia.com>
Date:   Wed Jun 20 11:52:33 2012 -0700

    Remove static qualifier on mieqProcessInputEvents()'s 'event'
    
    This isn't necessary.
    
    Signed-off-by: Andy Ritger <aritger at nvidia.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/mi/mieq.c b/mi/mieq.c
index b7be193..f7d8721 100644
--- a/mi/mieq.c
+++ b/mi/mieq.c
@@ -576,7 +576,7 @@ mieqProcessInputEvents(void)
 {
     EventRec *e = NULL;
     ScreenPtr screen;
-    static InternalEvent event;
+    InternalEvent event;
     DeviceIntPtr dev = NULL, master = NULL;
     size_t n_enqueued;
 
commit 44ea291b78b39ed5fd03f9693ac9525b866e183b
Author: Tomas Carnecky <tomas.carnecky at gmail.com>
Date:   Mon May 21 19:47:01 2012 +0000

    Remove NO_LIBCWRAPPER define
    
    I'll just refer to 1faba79 (Death to libcwrapper., 2007-12-03).
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Tomas Carnecky <tomas.carnecky at gmail.com>

diff --git a/configure.ac b/configure.ac
index bb56529..f38345a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1536,8 +1536,6 @@ AC_DEFINE_UNQUOTED(VENDOR_NAME_SHORT, ["$VENDOR_NAME_SHORT"], [Vendor name])
 AC_DEFINE_UNQUOTED(VENDOR_RELEASE, [$VENDOR_RELEASE], [Vendor release])
 AC_DEFINE_UNQUOTED(VENDOR_MAN_VERSION, ["$VENDOR_MAN_VERSION"], [Vendor man version])
 
-AC_DEFINE(NO_LIBCWRAPPER, 1, [Define to 1 if modules should avoid the libcwrapper])
-
 if test "x$DEBUGGING" = xyes; then
        AC_DEFINE(DEBUG, 1, [Enable debugging code])
 fi
commit 1e95a7df5f2e919ce59c5188d2ad1b30c3ac8595
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Mar 15 13:46:56 2012 +1000

    dix: put warning in for scroll increments of 0
    
    If the increment is 0 but this is a scroll axis, it's definitely a bug.
    Nonetheless, it has happened, so put a warning in and a return statement
    that we avoid the infinite loop and hopefully be able to reproduce later.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/dix/getevents.c b/dix/getevents.c
index fa5890e..7ebddc4 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -1540,6 +1540,10 @@ emulate_scroll_button_events(InternalEvent *events,
     ax = &dev->valuator->axes[axis];
     incr = ax->scroll.increment;
 
+    BUG_WARN_MSG(incr == 0, "for device %s\n", dev->name);
+    if (incr == 0)
+        return 0;
+
     if (type != ButtonPress && type != ButtonRelease)
         flags |= POINTER_EMULATED;
 
commit 63efa2e7e91349dfecc849d30c5de84b3c911fe9
Author: Bryce Harrington <bryce at canonical.com>
Date:   Wed Nov 30 12:54:29 2011 -0800

    test: Fix typo and drop documentation references to glib.
    
    The X server doesn't use glib for the tests any more.
    
    Signed-off-by: Bryce Harrington <bryce at canonical.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/test/README b/test/README
index 5759a72..618130c 100644
--- a/test/README
+++ b/test/README
@@ -1,8 +1,7 @@
                         X server test suite
 
 This suite contains a set of tests to verify the behaviour of functions used
-internally to the server. This test suite is based on glib's testing
-framework [1].
+internally to the server.
 
 = How it works =
 Through some automake abuse, we link the test programs with the same static
@@ -15,7 +14,7 @@ of the X server. Unless the test suite replicates the expected state, which
 may be difficult.
 
 = How to run the tests =
-Run "make check" the test directory. This will compile the tests and execute
+Run "make check" in the test directory. This will compile the tests and execute
 them in the order specified in the TESTS variable in test/Makefile.am.
 
 Each set of tests related to a subsystem are available as a binary that can be
@@ -23,14 +22,4 @@ executed directly. For example, run "xkb" to perform some xkb-related tests.
 
 == Adding a new test ==
 When adding a new test, ensure that you add a short description of what the
-test does and what the expected outcome is. If the test reproduces a
-particular bug, using g_test_bug().
-
-== Misc ==
-
-The programs "gtester" and "gtester-report" may be used to generate XML/HTML
-log files of tests succeeded and failed.
-
----------
-
-[1] http://library.gnome.org/devel/glib/stable/glib-Testing.html
+test does and what the expected outcome is.
commit 4c7cefe24001279a558dd875949d40ede49ef702
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Oct 20 11:44:28 2011 +0100

    exa: initialise mask_off_x and mask_off_y
    
    These get used at the end of the function in a calculation,
    even though the result isn't used its not pretty.
    
    Pointed out by coverity.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/exa/exa_render.c b/exa/exa_render.c
index e3e5526..fc3ddea 100644
--- a/exa/exa_render.c
+++ b/exa/exa_render.c
@@ -636,7 +636,7 @@ exaTryDriverComposite(CARD8 op,
     RegionRec region;
     BoxPtr pbox;
     int nbox;
-    int src_off_x, src_off_y, mask_off_x, mask_off_y, dst_off_x, dst_off_y;
+    int src_off_x, src_off_y, mask_off_x = 0, mask_off_y = 0, dst_off_x, dst_off_y;
     PixmapPtr pSrcPix = NULL, pMaskPix = NULL, pDstPix;
     ExaPixmapPrivPtr pSrcExaPix = NULL, pMaskExaPix = NULL, pDstExaPix;
 
commit 668cce3f5a175109442f0ef9b50354db95e66b44
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Fri Sep 23 14:11:17 2011 -0400

    dmx: fix typo in the title
    
    [ajax: fix typo in the commit message]
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/hw/dmx/doc/dmx.xml b/hw/dmx/doc/dmx.xml
index 6d7df41..40b9e42 100644
--- a/hw/dmx/doc/dmx.xml
+++ b/hw/dmx/doc/dmx.xml
@@ -8,7 +8,7 @@
 
   <articleinfo>
     <!-- Title information -->
-    <title>Distributed Multihead X design</title>
+    <title>Distributed Multihead X Design</title>
     <authorgroup>
       <author><firstname>Kevin E.</firstname><surname>Martin</surname></author>
       <author><firstname>David H.</firstname><surname>Dawes</surname></author>
commit 7ed0c3912e1cbab960df308b9d4ea618be757fd2
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Wed Jul 27 10:52:31 2011 +0200

    render: Allow single-stop gradients
    
    The Render specification allows single-stop gradients and pixman 0.22
    (X server requires >= 0.27.2 now) can rasterize them correctly.
    
    [ajax: update commit message]
    
    Signed-off-by: Andrea Canciani <ranma42 at gmail.com>
    Reviewed-by: Soren Sandmann <ssp at redhat.com>

diff --git a/render/picture.c b/render/picture.c
index 506aec4..acdd0ae 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -902,7 +902,7 @@ CreateLinearGradientPicture(Picture pid, xPointFixed * p1, xPointFixed * p2,
 {
     PicturePtr pPicture;
 
-    if (nStops < 2) {
+    if (nStops < 1) {
         *error = BadValue;
         return 0;
     }
@@ -942,7 +942,7 @@ CreateRadialGradientPicture(Picture pid, xPointFixed * inner,
     PicturePtr pPicture;
     PictRadialGradient *radial;
 
-    if (nStops < 2) {
+    if (nStops < 1) {
         *error = BadValue;
         return 0;
     }
@@ -985,7 +985,7 @@ CreateConicalGradientPicture(Picture pid, xPointFixed * center, xFixed angle,
 {
     PicturePtr pPicture;
 
-    if (nStops < 2) {
+    if (nStops < 1) {
         *error = BadValue;
         return 0;
     }
commit 3d9f578e6f0d13ecada7dc677fe61a4dd3d05e18
Author: Cyril Brulebois <kibi at debian.org>
Date:   Mon Jun 6 02:25:11 2011 +0200

    doc: Convert an \fP pair into appropriate tags.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Cyril Brulebois <kibi at debian.org>

diff --git a/doc/Xinput.xml b/doc/Xinput.xml
index 21eabfa..083b109 100644
--- a/doc/Xinput.xml
+++ b/doc/Xinput.xml
@@ -1060,7 +1060,7 @@ valuator0 through valuator5 - the values of the valuators.
 <!-- .LP -->
 In order to pass this information to the input extension library, two 32-byte
 wire events must be generated by DDX.  The first has an event type of 
-<function>DeviceKeyPress</function>, and the second has an event type of \fPDeviceValuator\fP.
+<function>DeviceKeyPress</function>, and the second has an event type of <function>DeviceValuator</function>.
 </para>
 <para>
 <!-- .LP -->
commit d97ffef1ab95546634a74618ed2661cfd6d980b1
Author: Cyril Brulebois <kibi at debian.org>
Date:   Mon Jun 6 02:25:10 2011 +0200

    doc: Try to avoid repetitions.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Cyril Brulebois <kibi at debian.org>

diff --git a/doc/Xinput.xml b/doc/Xinput.xml
index 36bfa7e..21eabfa 100644
--- a/doc/Xinput.xml
+++ b/doc/Xinput.xml
@@ -1003,7 +1003,7 @@ initialized.
 </para>
 <para>
 <!-- .LP -->
-The data structures that define these
+The data structures that describe these
 events are defined in the file <function>extensions/include/XIproto.h</function>.  Other
 input extension constants needed by DDX are defined in the file
 <function>extensions/include/XI.h</function>.
commit 2cce6ffc350d3840337a4d045d5cf14bb7bf2b32
Author: Cyril Brulebois <kibi at debian.org>
Date:   Mon Jun 6 02:25:08 2011 +0200

    doc: Fix punctuation.
    
    [ajax: s/ponct/punct/]
    
    Signed-off-by: Cyril Brulebois <kibi at debian.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/doc/Xinput.xml b/doc/Xinput.xml
index 9c8dc5d..36bfa7e 100644
--- a/doc/Xinput.xml
+++ b/doc/Xinput.xml
@@ -420,7 +420,7 @@ FocusClass - the device can be focused.
   </listitem>
   <listitem>
     <para>
-FeedbackClass - the device supports some kind of feedback
+FeedbackClass - the device supports some kind of feedback.
 <!-- .in -5n -->
 <!-- .RE -->
     </para>
@@ -702,7 +702,7 @@ InitStringFeedbackClassDeviceStruct(dev, controlProc, max_symbols,
 	num_symbols_supported, symbols)
     DeviceIntPtr dev;
     void (*controlProc)();
-    int max_symbols:
+    int max_symbols;
     int num_symbols_supported;
     KeySym *symbols;
 </literallayout>
@@ -1035,7 +1035,7 @@ deviceid - the identifier of the device that generated the event.
   </listitem>
   <listitem>
     <para>
-device_state - the state of any modifiers on the device that generated the event
+device_state - the state of any modifiers on the device that generated the event.
     </para>
   </listitem>
   <listitem>
commit e7e3320098cad585d46f74d8a0c6946a080b0263
Author: Cyril Brulebois <kibi at debian.org>
Date:   Mon Jun 6 02:25:07 2011 +0200

    doc: Fix extraneous &gt;
    
    It looks like it serves no special purpose.
    
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Signed-off-by: Cyril Brulebois <kibi at debian.org>

diff --git a/doc/Xinput.xml b/doc/Xinput.xml
index 5521510..9c8dc5d 100644
--- a/doc/Xinput.xml
+++ b/doc/Xinput.xml
@@ -362,7 +362,7 @@ server to begin checking for available input from this device.
 </para>
 <para>
 <!-- .LP -->
-&gt;From InitAndStartDevices, EnableDevice is called for all devices that have
+From InitAndStartDevices, EnableDevice is called for all devices that have
 the "inited" and "startup" fields in the DeviceIntRec set to TRUE.  The
 "inited" field is set by InitAndStartDevices to the value returned by
 the deviceproc when called with a mode value of DEVICE_INIT.  The "startup"
commit 9b4f10d7490f6610a65d401958296c95ce891c8b
Author: Cyril Brulebois <kibi at debian.org>
Date:   Mon Jun 6 02:25:06 2011 +0200

    doc: Fix grammar and typos.
    
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Signed-off-by: Cyril Brulebois <kibi at debian.org>

diff --git a/doc/Xinput.xml b/doc/Xinput.xml
index 6f86752..5521510 100644
--- a/doc/Xinput.xml
+++ b/doc/Xinput.xml
@@ -61,7 +61,7 @@ The functionality is implemented by
 routines that typically reside in the server source tree directory 
 extensions/server/xinput.
 This extension includes functions to enable and disable input extension devices,
-select input, grab and focus those device, query and change key 
+select input, grab and focus those devices, query and change key
 and button mappings, and others.  The only input extension requirements 
 for the device-dependent part of X are that the input devices be 
 correctly initialized and input events from those devices be correctly
@@ -446,7 +446,7 @@ This function is provided to allocate and initialize a KeyClassRec, and
 should be called for extension devices that have keys.  It is passed a pointer
 to the device, and pointers to arrays of keysyms and modifiers reported by
 the device.  It returns FALSE if the KeyClassRec could not be allocated,
-or if the maps for the keysyms and and modifiers could not be allocated.
+or if the maps for the keysyms and modifiers could not be allocated.
 Its parameters are:
 </para>
 <para>
@@ -905,7 +905,7 @@ such a device.
 <para>
 <!-- .LP -->
 The default implementation is to always return a BadMatch error.  If the
-implementation does not support any input devices that are allow their
+implementation does not support any input devices that allow their
 valuators to be set, the default implementation may be left unchanged.
 </para>
 </sect2>
commit 5b92a0a84a067b653cc457d8ec0fe25f36a9d207
Author: Cyril Brulebois <kibi at debian.org>
Date:   Mon Jun 6 02:25:05 2011 +0200

    doc: Fix alignment.
    
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Signed-off-by: Cyril Brulebois <kibi at debian.org>

diff --git a/doc/Xinput.xml b/doc/Xinput.xml
index 7f576a1..6f86752 100644
--- a/doc/Xinput.xml
+++ b/doc/Xinput.xml
@@ -1078,7 +1078,7 @@ The following code fragment shows how the two wire events could be initialized:
     deviceKeyButtonPointer *xev = (deviceKeyButtonPointer *) xE;
     deviceValuator *xv;
 
-    xev-&gt;type = DeviceKeyPress;                /* defined by input extension */
+    xev-&gt;type = DeviceKeyPress;         /* defined by input extension */
     xev-&gt;detail = keycode;              /* key pressed on this device */
     xev-&gt;time = timestamp;              /* same as for core events    */
     xev-&gt;rootX = pointerx;              /* x location of core pointer */
@@ -1093,7 +1093,7 @@ The following code fragment shows how the two wire events could be initialized:
     /*                                                                */
     /******************************************************************/
 
-    xev-&gt;deviceid = dev-&gt;id | MORE_EVENTS;        /* sending more than 1*/
+    xev-&gt;deviceid = dev-&gt;id | MORE_EVENTS;     /* sending more than 1 */
 
     /******************************************************************/
     /* Fields in the second 32-byte wire event:                       */
@@ -1152,7 +1152,7 @@ The following code fragment shows how the two wire events could be initialized:
     /*                                                                */
     /******************************************************************/
 
-    xev-&gt;deviceid = dev-&gt;id | MORE_EVENTS;        /* sending more than 1*/
+    xev-&gt;deviceid = dev-&gt;id | MORE_EVENTS;     /* sending more than 1 */
 
     /******************************************************************/
     /* Fields in the second 32-byte wire event:                       */
commit 0b8fca667b45f00249a3dd9ee79d2a77a4177b24
Author: Cyril Brulebois <kibi at debian.org>
Date:   Mon Jun 6 02:24:59 2011 +0200

    doc: Fix typo.
    
    Signed-off-by: Cyril Brulebois <kibi at debian.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/doc/c-extensions b/doc/c-extensions
index 4a90061..e5fde34 100644
--- a/doc/c-extensions
+++ b/doc/c-extensions
@@ -21,7 +21,7 @@ extensions, although the results may not be optimal.
                  table.
     * _X_INTERNAL: like _X_HIDDEN, but attempt to ensure that this function
                    is never called from another module.
-    * _X_INLINE: inline this functon if possible (generally obeyed unless
+    * _X_INLINE: inline this function if possible (generally obeyed unless
                  disabling optimisations).
     * _X_DEPRECATED: warn on use of this function.
 
commit 1226f7ddd78da5dc8b6f6442600ac2deb3986e8d
Author: Cyril Brulebois <kibi at debian.org>
Date:   Mon Jun 6 02:25:01 2011 +0200

    doc: Get rid of RCS tags.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Cyril Brulebois <kibi at debian.org>

diff --git a/doc/smartsched b/doc/smartsched
index 057a759..bd76274 100644
--- a/doc/smartsched
+++ b/doc/smartsched
@@ -196,9 +196,3 @@ updated in three ways:
 
 The effect of these changes is to both improve interactive application
 response and benchmark numbers at the same time.
-
-
-
-
-
-$XFree86: $
commit 4803f7139131cee7bbf50b32d667d6e60302df09
Author: Cyril Brulebois <kibi at debian.org>
Date:   Sun Jun 5 23:32:26 2011 +0200

    man: Fix case for MIT-unspecified.
    
    include/site.h says that COMPILEDDISPLAYCLASS is MIT-unspecified, rather
    than MIT-Unspecified. Fix the manpage accordingly.
    
    Signed-off-by: Cyril Brulebois <kibi at debian.org>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/man/Xserver.man b/man/Xserver.man
index ea000e1..d927913 100644
--- a/man/Xserver.man
+++ b/man/Xserver.man
@@ -396,7 +396,7 @@ ends.
 .B \-class \fIdisplay-class\fP
 XDMCP has an additional display qualifier used in resource lookup for
 display-specific options.  This option sets that value, by default it
-is "MIT-Unspecified" (not a very useful value).
+is "MIT-unspecified" (not a very useful value).
 .TP 8
 .B \-cookie \fIxdm-auth-bits\fP
 When testing XDM-AUTHENTICATION-1, a private key is shared between the
commit 593270038d8983b99aa0aaa24509da3cb944be5c
Author: Tiago Vignatti <tiago.vignatti at nokia.com>
Date:   Tue Sep 7 15:50:26 2010 +0300

    dix: remove dead extensions to protocol.txt
    
    lbx and mbe.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Tiago Vignatti <tiago.vignatti at nokia.com>

diff --git a/dix/protocol.txt b/dix/protocol.txt
index f78ed58..4633e08 100644
--- a/dix/protocol.txt
+++ b/dix/protocol.txt
@@ -248,51 +248,6 @@ E009 GLX:BadFBConfig
 E010 GLX:BadPbuffer
 E011 GLX:BadCurrentDrawable
 E012 GLX:BadWindow
-R000 LBX:QueryVersion
-R001 LBX:StartProxy
-R002 LBX:StopProxy
-R003 LBX:Switch
-R004 LBX:NewClient
-R005 LBX:CloseClient
-R006 LBX:ModifySequence
-R007 LBX:AllowMotion
-R008 LBX:IncrementPixel
-R009 LBX:Delta
-R010 LBX:GetModifierMapping
-R011 LBX:QueryTag
-R012 LBX:InvalidateTag
-R013 LBX:PolyPoint
-R014 LBX:PolyLine
-R015 LBX:PolySegment
-R016 LBX:PolyRectangle
-R017 LBX:PolyArc
-R018 LBX:FillPoly
-R019 LBX:PolyFillRectangle
-R020 LBX:PolyFillArc
-R021 LBX:GetKeyboardMapping
-R022 LBX:QueryFont
-R023 LBX:ChangeProperty
-R024 LBX:GetProperty
-R025 LBX:TagData
-R026 LBX:CopyArea
-R027 LBX:CopyPlane
-R028 LBX:PolyText8
-R029 LBX:PolyText16
-R030 LBX:ImageText8
-R031 LBX:ImageText16
-R032 LBX:QueryExtension
-R033 LBX:PutImage
-R034 LBX:GetImage
-R035 LBX:BeginLargeRequest
-R036 LBX:LargeRequestData
-R037 LBX:EndLargeRequest
-R038 LBX:InternAtoms
-R039 LBX:GetWinAttrAndGeom
-R040 LBX:GrabCmap
-R041 LBX:ReleaseCmap
-R042 LBX:AllocColor
-R043 LBX:Sync
-E000 LBX:BadLbxClient
 R000 MIT-SCREEN-SAVER:QueryVersion
 R001 MIT-SCREEN-SAVER:QueryInfo
 R002 MIT-SCREEN-SAVER:SelectInput
@@ -310,20 +265,6 @@ V000 MIT-SHM:Completion
 E000 MIT-SHM:BadShmSeg
 R000 MIT-SUNDRY-NONSTANDARD:SetBugMode
 R001 MIT-SUNDRY-NONSTANDARD:GetBugMode
-R000 Multi-Buffering:GetBufferVersion
-R001 Multi-Buffering:CreateImageBuffers
-R002 Multi-Buffering:DestroyImageBuffers
-R003 Multi-Buffering:DisplayImageBuffers
-R004 Multi-Buffering:SetMBufferAttributes
-R005 Multi-Buffering:GetMBufferAttributes
-R006 Multi-Buffering:SetBufferAttributes
-R007 Multi-Buffering:GetBufferAttributes
-R008 Multi-Buffering:GetBufferInfo
-R009 Multi-Buffering:CreateStereoWindow
-R010 Multi-Buffering:ClearImageBufferArea
-V000 Multi-Buffering:ClobberNotify
-V001 Multi-Buffering:UpdateNotify
-E000 Multi-Buffering:BadBuffer
 R000 RANDR:QueryVersion
 R001 RANDR:OldGetScreenInfo
 R002 RANDR:SetScreenConfig
commit 3cd56dd2cfbfcce6ba68c22450d51139208993ab
Author: Robert Hooker <sarvatt at ubuntu.com>
Date:   Fri Dec 3 23:42:27 2010 -0500

    Add new GLX events errors and requests to protocol.txt
    
    Based off of glproto 1.4.11.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Robert Hooker <robert.hooker at canonical.com>

diff --git a/dix/protocol.txt b/dix/protocol.txt
index fa2fcb1..f78ed58 100644
--- a/dix/protocol.txt
+++ b/dix/protocol.txt
@@ -159,6 +159,20 @@ R017 GLX:VendorPrivateWithReply
 R018 GLX:QueryExtensionsString
 R019 GLX:QueryServerString
 R020 GLX:ClientInfo
+R021 GLX:GetFBConfigs
+R022 GLX:CreatePixmap
+R023 GLX:DestroyPixmap
+R024 GLX:CreateNewContext
+R025 GLX:QueryContext
+R026 GLX:MakeContextCurrent
+R027 GLX:CreatePbuffer
+R028 GLX:DestroyPbuffer
+R029 GLX:GetDrawableAttributes
+R030 GLX:ChangeDrawableAttributes
+R031 GLX:CreateWindow
+R032 GLX:DeleteWindow
+R033 GLX:SetClientInfoARB
+R034 GLX:CreateContextAttribsARB
 R101 GLX:NewList
 R102 GLX:EndList
 R103 GLX:DeleteLists
@@ -201,6 +215,26 @@ R139 GLX:GetTexLevelParameteriv
 R140 GLX:IsEnabled
 R141 GLX:IsList
 R142 GLX:Flush
+R143 GLX:AreTexturesResident
+R144 GLX:DeleteTextures
+R145 GLX:GenTextures
+R146 GLX:IsTexture
+R147 GLX:GetColorTable
+R148 GLX:GetColorTableParameterfv
+R149 GLX:GetColorTableParameterfv
+R150 GLX:GetConvolutionFilter
+R151 GLX:GetConvolutionParameterfv
+R152 GLX:GetConvolutionParameteriv
+R153 GLX:GetSeparableFilter
+R154 GLX:GetHistogram
+R155 GLX:GetHistogramParameterfv
+R156 GLX:GetHistogramParameteriv
+R157 GLX:GetMinmax
+R158 GLX:GetMinmaxParameterfv
+R159 GLX:GetMinmaxParameteriv
+R160 GLX:GetCompressedTexImage
+V000 GLX:PbufferClobber
+V001 GLX:BufferSwapComplete
 E000 GLX:BadContext
 E001 GLX:BadContextState
 E002 GLX:BadDrawable
@@ -210,6 +244,10 @@ E005 GLX:BadCurrentWindow
 E006 GLX:BadRenderRequest
 E007 GLX:BadLargeRequest
 E008 GLX:UnsupportedPrivateRequest
+E009 GLX:BadFBConfig
+E010 GLX:BadPbuffer
+E011 GLX:BadCurrentDrawable
+E012 GLX:BadWindow
 R000 LBX:QueryVersion
 R001 LBX:StartProxy
 R002 LBX:StopProxy
commit 272ba9f021c6d08ebd6a2d96da3737f5630bcbd5
Author: Robert Hooker <sarvatt at ubuntu.com>
Date:   Fri Dec 3 23:39:51 2010 -0500

    Add DRI2 2.2/2.3 events and requests to protocol.txt
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Robert Hooker <robert.hooker at canonical.com>

diff --git a/dix/protocol.txt b/dix/protocol.txt
index c223795..fa2fcb1 100644
--- a/dix/protocol.txt
+++ b/dix/protocol.txt
@@ -124,6 +124,13 @@ R004 DRI2:DestroyDrawable
 R005 DRI2:GetBuffers
 R006 DRI2:CopyRegion
 R007 DRI2:GetBuffersWithFormat
+R008 DRI2:SwapBuffers
+R009 DRI2:GetMSC
+R010 DRI2:WaitMSC
+R011 DRI2:WaitSBC
+R012 DRI2:SwapInterval
+V000 DRI2:BufferSwapComplete
+V001 DRI2:InvalidateBuffers
 R000 Extended-Visual-Information:QueryVersion
 R001 Extended-Visual-Information:GetVisualInfo
 R000 FontCache:QueryVersion
commit 64e6124f27e9900809d0009b95c7c0b5b8788e6b
Author: Emil Velikov <emil.l.velikov at gmail.com>
Date:   Tue Sep 22 15:35:40 2015 +0100

    glamor: move GL_OES_EGL_image check next to EGL_EXT_image_dma_buf_import
    
    We're using the former only as the latter is present. Thus in some cases
    we might incorrectly error out if it's missing.
    
    Namely - glamor_glx, glamor_egl without gbm, EGL_KHR_gl_texture_2D_image
    or EGL_EXT_image_dma_buf_import.
    
    Fixes 58d54ee82df(glamor: explicitly check for GL_OES_EGL_image)
    Cc: Eric Anholt <eric at anholt.net>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Suggested-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>

diff --git a/glamor/glamor.c b/glamor/glamor.c
index 8178785..d4a0236 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -545,11 +545,6 @@ glamor_init(ScreenPtr screen, unsigned int flags)
         }
     }
 
-    if (!epoxy_has_gl_extension("GL_OES_EGL_image")) {
-        ErrorF("GL_OES_EGL_image not available\n");
-        goto fail;
-    }
-
     glamor_priv->has_rw_pbo = FALSE;
     if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP)
         glamor_priv->has_rw_pbo = TRUE;
diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
index 8ff1d03..dcff443 100644
--- a/glamor/glamor_egl.c
+++ b/glamor/glamor_egl.c
@@ -870,7 +870,8 @@ glamor_egl_init(ScrnInfoPtr scrn, int fd)
     if (epoxy_has_egl_extension(glamor_egl->display,
                                 "EGL_KHR_gl_texture_2D_image") &&
         epoxy_has_egl_extension(glamor_egl->display,
-                                "EGL_EXT_image_dma_buf_import"))
+                                "EGL_EXT_image_dma_buf_import") &&
+        epoxy_has_gl_extension("GL_OES_EGL_image"))
         glamor_egl->dri3_capable = TRUE;
 #endif
 
commit aa5606be1c0ea72b38de48ca333c7da5436368ef
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Fri May 15 10:25:46 2015 -0700

    Make configure test for LD_NO_UNDEFINED_FLAG on Solaris work w/autoconf 2.69
    
    After upgrading from autoconf 2.68 to 2.69, this test started failing with
    "conftest.c", line 149: undefined symbol: NULL
    so use a raw 0 pointer to avoid header dependencies in the autoconf
    generated test case.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Mark Kettenis <kettenis at openbsd.org>

diff --git a/configure.ac b/configure.ac
index 0ab756d..bb56529 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1760,7 +1760,7 @@ case "$host_os" in
 #		 XORG_DRIVER_LIBS="-Wl,-z,defs -Wl,-z,parent=${bindir}/Xorg"
          ],[],
 		[AC_LANG_SOURCE([extern int main(int argc, char **argv);
-			int call_main(void) { return main(0, NULL); }])])
+			int call_main(void) { return main(0, (void *)0); }])])
 	     rm -f conftest.parent
 	    ])
 	;;
commit fa0bb01899d586e02cf51892c17edd22e462a46c
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Sep 21 15:23:23 2015 -0400

    rootless: Fix bogus handling of broken root clip
    
    gcc quite correctly complains about this:
    
        In file included from ../../include/scrnintstr.h:51:0,
                         from rootlessValTree.c:98:
        In function 'RegionUninit.isra.1',
            inlined from 'RegionEmpty' at ../../include/regionstr.h:194:5,
            inlined from 'RootlessMiValidateTree' at rootlessValTree.c:490:9:
        ../../include/regionstr.h:166:9: warning: attempt to free a non-heap object 'RegionBrokenData' [-Wfree-nonheap-object]
                 free((_pReg)->data);
    
    So that'd crash if you ever got there.  RegionNull will do almost the
    same thing only without the free(), so let's do that instead; it might
    still not be an entirely sane way to recover, but it at least won't
    crash.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/miext/rootless/rootlessValTree.c b/miext/rootless/rootlessValTree.c
index 0f7b76c..409e6a0 100644
--- a/miext/rootless/rootlessValTree.c
+++ b/miext/rootless/rootlessValTree.c
@@ -487,7 +487,7 @@ RootlessMiValidateTree(WindowPtr pRoot, /* Parent to validate */
     if (RegionBroken(&pRoot->clipList) && !RegionBroken(&pRoot->borderClip)) {
         // fixme this might not work, but hopefully doesn't happen anyway.
         kind = VTBroken;
-        RegionEmpty(&pRoot->clipList);
+        RegionNull(&pRoot->clipList);
         ErrorF("ValidateTree: BUSTED!\n");
     }
 
commit b25f7d0c165c4d32c73fbdf9080012503d319ba1
Merge: db1089e 1ba4fde
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Sep 21 17:34:48 2015 -0400

    Merge commit '1ba4fde1015fc6da19dfbfdf0f77f1071416e215'
    
    This is ofourdan/xwayland, minus:
    
        xwayland: Always update the wl_pointer cursor on pointer focus
    
    which was rejected for ABI and design issues.

commit db1089eafc1c5371fa0030202de588d2e2b4f8e5
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Sep 21 07:16:17 2015 +0100

    os/xdmcp: Just send XDMCP keepalive packets once every three minutes
    
    There was a complicated scheme to increase the time between keepalives
    from 3 minutes up to as much as 24 hours in an attempt to reduce
    network traffic from idle X terminals. X terminals receiving X
    traffic, or receiving user input would use the 3 minute value; X
    terminals without any network traffic would use a longer value.
    
    However, this was actually broken -- any activity in the X server,
    either client requests or user input, would end up resetting the
    keepalive timeout, so a user mashing on the keyboard would never
    discover that the XDMCP master had disappeared and have the session
    terminated, which was precisely the design goal of the XDMCP keepalive
    mechanism.
    
    Instead of attempting to fix this, accept the cost of a pair of XDMCP
    packets once every three minutes and just perform keepalives
    regularly.
    
    This will also make reworking the block and wakeup handler APIs to
    eliminate select masks easier.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/os/xdmcp.c b/os/xdmcp.c
index b1ee5d2..7939b41 100644
--- a/os/xdmcp.c
+++ b/os/xdmcp.c
@@ -84,8 +84,6 @@ static int req_socklen;
 static CARD32 SessionID;
 static CARD32 timeOutTime;
 static int timeOutRtx;
-static CARD32 defaultKeepaliveDormancy = XDM_DEF_DORMANCY;
-static CARD32 keepaliveDormancy = XDM_DEF_DORMANCY;
 static CARD16 DisplayNumber;
 static xdmcp_states XDM_INIT_STATE = XDM_OFF;
 
@@ -632,6 +630,7 @@ XdmcpOpenDisplay(int sock)
     if (state != XDM_AWAIT_MANAGE_RESPONSE)
         return;
     state = XDM_RUN_SESSION;
+    timeOutTime = GetTimeInMillis() + XDM_DEF_DORMANCY * 1000;
     sessionSocket = sock;
 }
 
@@ -689,7 +688,6 @@ XdmcpWakeupHandler(void *data,        /* unused */
                    int i, void *pReadmask)
 {
     fd_set *last_select_mask = (fd_set *) pReadmask;
-    fd_set devicesReadable;
 
     if (state == XDM_OFF)
         return;
@@ -704,13 +702,6 @@ XdmcpWakeupHandler(void *data,        /* unused */
             FD_CLR(xdmcpSocket6, last_select_mask);
         }
 #endif
-        XFD_ANDSET(&devicesReadable, last_select_mask, &EnabledDevices);
-        if (XFD_ANYSET(&devicesReadable)) {
-            if (state == XDM_RUN_SESSION)
-                keepaliveDormancy = defaultKeepaliveDormancy;
-        }
-        if (XFD_ANYSET(&AllClients) && state == XDM_RUN_SESSION)
-            timeOutTime = GetTimeInMillis() + keepaliveDormancy * 1000;
     }
     else if (timeOutTime && (int) (GetTimeInMillis() - timeOutTime) >= 0) {
         if (state == XDM_RUN_SESSION) {
@@ -1399,15 +1390,8 @@ recv_alive_msg(unsigned length)
     if (XdmcpReadCARD8(&buffer, &SessionRunning) &&
         XdmcpReadCARD32(&buffer, &AliveSessionID)) {
         if (SessionRunning && AliveSessionID == SessionID) {
-            /* backoff dormancy period */
             state = XDM_RUN_SESSION;
-            if ((GetTimeInMillis() - LastEventTime(XIAllDevices).milliseconds) >
-                keepaliveDormancy * 1000) {
-                keepaliveDormancy <<= 1;
-                if (keepaliveDormancy > XDM_MAX_DORMANCY)
-                    keepaliveDormancy = XDM_MAX_DORMANCY;
-            }
-            timeOutTime = GetTimeInMillis() + keepaliveDormancy * 1000;
+            timeOutTime = GetTimeInMillis() + XDM_DEF_DORMANCY * 1000;
         }
         else {
             XdmcpDeadSession("Alive response indicates session dead");
commit a3a40291330bad10401fe2bcdbc097ce742b026a
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Sep 21 07:16:16 2015 +0100

    os/xdmcp: Remove dead 'restart' code
    
    The X server used to wait for the user to hit a key or move the mouse
    before restarting the session after a keepalive failure. This,
    presumably, was to avoid having the X server continuously spew XDMCP
    protocol on the network while the XDM server was dead.
    
    Switching into this state was removed from the server some time before
    XFree86 4.3.99.16, so the remaining bits of code have been dead for
    over a decade, and no-one ever noticed.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/os/xdmcp.c b/os/xdmcp.c
index b265db3..b1ee5d2 100644
--- a/os/xdmcp.c
+++ b/os/xdmcp.c
@@ -199,8 +199,6 @@ static void send_packet(void);
 
 static void timeout(void);
 
-static void restart(void);
-
 static void XdmcpBlockHandler(void              *data ,
                               struct timeval    **wt,
                               void              *LastSelectMask);
@@ -708,9 +706,7 @@ XdmcpWakeupHandler(void *data,        /* unused */
 #endif
         XFD_ANDSET(&devicesReadable, last_select_mask, &EnabledDevices);
         if (XFD_ANYSET(&devicesReadable)) {
-            if (state == XDM_AWAIT_USER_INPUT)
-                restart();
-            else if (state == XDM_RUN_SESSION)
+            if (state == XDM_RUN_SESSION)
                 keepaliveDormancy = defaultKeepaliveDormancy;
         }
         if (XFD_ANYSET(&AllClients) && state == XDM_RUN_SESSION)
@@ -936,14 +932,6 @@ timeout(void)
     send_packet();
 }
 
-static void
-restart(void)
-{
-    state = XDM_INIT_STATE;
-    timeOutRtx = 0;
-    send_packet();
-}
-
 static int
 XdmcpCheckAuthentication(ARRAY8Ptr Name, ARRAY8Ptr Data, int packet_type)
 {
commit 3cd7d33380953f2a315dd79ab74d7340c83fd80a
Author: Egbert Eich <eich at freedesktop.org>
Date:   Tue Mar 31 09:06:46 2015 +0200

    randr: Remove senseless checks for xf86RandR12Key
    
    When xf86RandR12Key is not set we will not get to the places where
    these tests are done as the functions in question are not called.
    In most cases we would have crashed before these checks anyway.
    
    Signed-off-by: Egbert Eich <eich at freedesktop.org>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index 0d446da..eae7016 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -683,11 +683,9 @@ xf86RandR12ScreenSetSize(ScreenPtr pScreen,
     Bool ret = FALSE;
     int c;
 
-    if (xf86RandR12Key) {
-        if (randrp->virtualX == -1 || randrp->virtualY == -1) {
-            randrp->virtualX = pScrn->virtualX;
-            randrp->virtualY = pScrn->virtualY;
-        }
+    if (randrp->virtualX == -1 || randrp->virtualY == -1) {
+        randrp->virtualX = pScrn->virtualX;
+        randrp->virtualY = pScrn->virtualY;
     }
     if (pRoot && pScrn->vtSema)
         (*pScrn->EnableDisableFBAccess) (pScrn, FALSE);
@@ -730,7 +728,7 @@ xf86RandR12ScreenSetSize(ScreenPtr pScreen,
     if (pRoot && pScrn->vtSema)
         (*pScrn->EnableDisableFBAccess) (pScrn, TRUE);
 #if RANDR_12_INTERFACE
-    if (xf86RandR12Key && pScreen->root && ret)
+    if (pScreen->root && ret)
         RRScreenSizeNotify(pScreen);
 #endif
     return ret;
@@ -826,9 +824,6 @@ xf86RandR12CreateScreenResources(ScreenPtr pScreen)
         xf86RandR12ScreenSetSize(pScreen, width, height, mmWidth, mmHeight);
     }
 
-    if (xf86RandR12Key == NULL)
-        return TRUE;
-
     if (randrp->virtualX == -1 || randrp->virtualY == -1) {
         randrp->virtualX = pScrn->virtualX;
         randrp->virtualY = pScrn->virtualY;
commit 245040f0d0b937efe14d947468a641a95398776a
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Oct 6 10:02:22 2014 +0100

    randr/prime: Don't stop on the first pipe when disabling ReplaceScanoutPixmap
    
    As we define sizeFits based on whether a CRTC is active, and skip trying
    to redirect the scanout on a disable pipe, we then attempt to undo it
    later and fail because crtc->scanout_pixmap != DRI2_Pixmap and
    !sizeFits. Paper over this failure by skipping unredirected CRTC when
    disabling.
    
    v2: Unwind upon failure
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=84653
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
    Cc: Dave Airlie <airlied at redhat.com>
    Reported-by: Christoph Haag <haagch at frickel.club>
    Tested-by: Christoph Haag <haagch at frickel.club>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>

diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index 050d975..9bc456b 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -1695,23 +1695,30 @@ Bool
 RRReplaceScanoutPixmap(DrawablePtr pDrawable, PixmapPtr pPixmap, Bool enable)
 {
     rrScrPriv(pDrawable->pScreen);
-    int i;
-    Bool size_fits = FALSE;
-    Bool changed = FALSE;
     Bool ret = TRUE;
+    PixmapPtr *saved_scanout_pixmap;
+    int i;
+
+    saved_scanout_pixmap = malloc(sizeof(PixmapPtr)*pScrPriv->numCrtcs);
+    if (saved_scanout_pixmap == NULL)
+        return FALSE;
 
     for (i = 0; i < pScrPriv->numCrtcs; i++) {
         RRCrtcPtr crtc = pScrPriv->crtcs[i];
+        Bool size_fits;
+
+        saved_scanout_pixmap[i] = crtc->scanout_pixmap;
 
         if (!crtc->mode && enable)
             continue;
+        if (!crtc->scanout_pixmap && !enable)
+            continue;
 
-        changed = FALSE;
-        if (crtc->mode && crtc->x == pDrawable->x &&
-            crtc->y == pDrawable->y &&
-            crtc->mode->mode.width == pDrawable->width &&
-            crtc->mode->mode.height == pDrawable->height)
-            size_fits = TRUE;
+        size_fits = (crtc->mode &&
+                     crtc->x == pDrawable->x &&
+                     crtc->y == pDrawable->y &&
+                     crtc->mode->mode.width == pDrawable->width &&
+                     crtc->mode->mode.height == pDrawable->height);
 
         /* is the pixmap already set? */
         if (crtc->scanout_pixmap == pPixmap) {
@@ -1719,32 +1726,48 @@ RRReplaceScanoutPixmap(DrawablePtr pDrawable, PixmapPtr pPixmap, Bool enable)
             if (enable == FALSE) {
                 /* set scanout to NULL */
                 crtc->scanout_pixmap = NULL;
-                changed = TRUE;
-            } else {
-                /* if the size fits then we are already setup */
-                if (size_fits)
-                    return TRUE;
+            }
+            else if (!size_fits) {
                 /* if the size no longer fits then drop off */
                 crtc->scanout_pixmap = NULL;
-                changed = TRUE;
+                pScrPriv->rrCrtcSetScanoutPixmap(crtc, crtc->scanout_pixmap);
+
+                (*pScrPriv->rrCrtcSet) (pDrawable->pScreen, crtc, crtc->mode, crtc->x, crtc->y,
+                                        crtc->rotation, crtc->numOutputs, crtc->outputs);
+                saved_scanout_pixmap[i] = crtc->scanout_pixmap;
                 ret = FALSE;
             }
-        } else {
+            else {
+                /* if the size fits then we are already setup */
+            }
+        }
+        else {
             if (!size_fits)
-                return FALSE;
-            if (enable) {
+                ret = FALSE;
+            else if (enable)
                 crtc->scanout_pixmap = pPixmap;
-                pScrPriv->rrCrtcSetScanoutPixmap(crtc, pPixmap);
-                changed = TRUE;
-            }
+            else
+                /* reject an attempt to disable someone else's scanout_pixmap */
+                ret = FALSE;
         }
+    }
 
-        if (changed && pScrPriv->rrCrtcSet) {
+    for (i = 0; i < pScrPriv->numCrtcs; i++) {
+        RRCrtcPtr crtc = pScrPriv->crtcs[i];
+
+        if (crtc->scanout_pixmap == saved_scanout_pixmap[i])
+            continue;
+
+        if (ret) {
             pScrPriv->rrCrtcSetScanoutPixmap(crtc, crtc->scanout_pixmap);
 
             (*pScrPriv->rrCrtcSet) (pDrawable->pScreen, crtc, crtc->mode, crtc->x, crtc->y,
                                     crtc->rotation, crtc->numOutputs, crtc->outputs);
         }
+        else
+            crtc->scanout_pixmap = saved_scanout_pixmap[i];
     }
+    free(saved_scanout_pixmap);
+
     return ret;
 }
commit 9d65a0de95a20632f2a6a04ba596dcdd76d9f5e2
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Fri Sep 18 08:44:07 2015 -0700

    Remove DECnet from Xserver.man
    
    DECnet support died in modularization (X11R7.0)
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/man/Xserver.man b/man/Xserver.man
index 8a09888..ea000e1 100644
--- a/man/Xserver.man
+++ b/man/Xserver.man
@@ -433,7 +433,7 @@ elapse between autorepeat-generated keystrokes).
 loads keyboard description in \fIfilename\fP on server startup.
 .SH "NETWORK CONNECTIONS"
 The X server supports client connections via a platform-dependent subset of
-the following transport types: TCP/IP, Unix Domain sockets, DECnet,
+the following transport types: TCP/IP, Unix Domain sockets,
 and several varieties of SVR4 local connections.  See the DISPLAY
 NAMES section of the \fIX\fP(__miscmansuffix__) manual page to learn how to
 specify which transport type clients should try to use.
@@ -462,8 +462,8 @@ If no other authorization mechanism is being used,
 this list initially consists of the host on which the server is running as
 well as any machines listed in the file \fI/etc/X\fBn\fI.hosts\fR, where
 \fBn\fP is the display number of the server.  Each line of the file should
-contain either an Internet hostname (e.g. expo.lcs.mit.edu) or a DECnet
-hostname in double colon format (e.g. hydra::) or a complete name in the format
+contain either an Internet hostname (e.g. expo.lcs.mit.edu)
+or a complete name in the format
 \fIfamily\fP:\fIname\fP as described in the \fIxhost\fP(1) manual page.
 There should be no leading or trailing spaces on any lines.  For example:
 .sp
@@ -471,7 +471,6 @@ There should be no leading or trailing spaces on any lines.  For example:
 .nf
 joesworkstation
 corporate.company.com
-star::
 inet:bigcpu
 local:
 .fi
commit 82eb490b0a341729f25d0c42a937fe29d99da521
Author: Aaron Plattner <aplattner at nvidia.com>
Date:   Thu Sep 17 16:04:33 2015 -0700

    privates: Clear screen-specific keys during CloseScreen
    
    The modesetting driver corrupts memory when used after a server regeneration
    because not enough memory is allocated for its pixmap privates.  This happens
    because its call to dixRegisterScreenSpecificPrivateKey() does nothing because
    key->initialized is still TRUE from the first server generation.  However, the
    key is not in the screen's linked list of screen-specific privates because
    that's freed and reallocated during the server generation loop in dix_main().
    
    Fix this by clearing key->initialized before CloseScreen and add a call to
    dixFreeScreenSpecificPrivates() for GPU screens.
    
    v2: Just set key->initialized to FALSE and move dixFreeScreenSpecificPrivates()
    calls to after CloseScreen.
    
    v3: Move dixFreeScreenSpecificPrivates() calls back to just before CloseScreen.
    
    Signed-off-by: Aaron Plattner <aplattner at nvidia.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/dix/main.c b/dix/main.c
index d7a9cda..5495676 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -339,6 +339,7 @@ dix_main(int argc, char *argv[], char *envp[])
         for (i = screenInfo.numGPUScreens - 1; i >= 0; i--) {
             ScreenPtr pScreen = screenInfo.gpuscreens[i];
             FreeScratchPixmapsForScreen(pScreen);
+            dixFreeScreenSpecificPrivates(pScreen);
             (*pScreen->CloseScreen) (pScreen);
             dixFreePrivates(pScreen->devPrivates, PRIVATE_SCREEN);
             free(pScreen);
diff --git a/dix/privates.c b/dix/privates.c
index e03b225..969d014 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -642,6 +642,15 @@ dixRegisterScreenSpecificPrivateKey(ScreenPtr pScreen, DevPrivateKey key,
 void
 dixFreeScreenSpecificPrivates(ScreenPtr pScreen)
 {
+    DevPrivateType t;
+
+    for (t = PRIVATE_XSELINUX; t < PRIVATE_LAST; t++) {
+        DevPrivateKey key;
+
+        for (key = pScreen->screenSpecificPrivates[t].key; key; key = key->next) {
+            key->initialized = FALSE;
+        }
+    }
 }
 
 /* Initialize screen-specific privates in AddScreen */
commit 18a93da9b1f429bc54a8b236fcdd38dab58375cd
Author: Jasper St. Pierre <jstpierre at mecheye.net>
Date:   Wed Feb 18 12:41:25 2015 -0800

    test/xi1: Update .gitignore
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/test/xi1/.gitignore b/test/xi1/.gitignore
new file mode 100644
index 0000000..c1b9024
--- /dev/null
+++ b/test/xi1/.gitignore
@@ -0,0 +1 @@
+protocol-xchangedevicecontrol
commit cdd1d58159140759052ec043bc9828d94ba97bc7
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Mon Jul 6 17:15:44 2015 +0100

    mingw: Fix NO_LOCAL_CLIENT_CRED build
    
    Commit 4b4b9086 "os: support new implicit local user access mode [CVE-2015-3164
    2/3]" carefully places the relevant code it adds under !NO_LOCAL_CLIENT_CRED,
    but unfortunately doesn't notice that NO_LOCAL_CLIENT_CRED is defined as a
    side-effect in the middle of GetLocalClientCreds(), so many of these checks
    precede its definition.
    
    Move the check if NO_LOCAL_CLIENT_CRED should be defined to configure.ac, so it
    always occurs before it's first use.
    
    v2:
    Move check to configure.ac
    
    v3:
    Use AC_CACHE_CHECK and name cache varaible appropriately
    
    [ajax: Massaged commit message]
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Ray Strode <rstrode at redhat.com>

diff --git a/configure.ac b/configure.ac
index bab7d89..0ab756d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -223,6 +223,24 @@ AC_REPLACE_FUNCS([reallocarray strcasecmp strcasestr strlcat strlcpy strndup])
 
 AC_CHECK_DECLS([program_invocation_short_name], [], [], [[#include <errno.h>]])
 
+dnl Check for SO_PEERCRED #define
+AC_CACHE_CHECK([for SO_PEERCRED in sys/socket.h],
+	       [xorg_cv_sys_have_so_peercred],
+	       [AC_EGREP_CPP(yes_have_so_peercred,[
+#include <sys/types.h>
+#include <sys/socket.h>
+#ifdef SO_PEERCRED
+yes_have_so_peercred
+#endif
+],
+	       [xorg_cv_sys_have_so_peercred=yes],
+	       [xorg_cv_sys_have_so_peercred=no])])
+
+dnl define NO_LOCAL_CLIENT_CRED if no getpeereid, getpeerucred or SO_PEERCRED
+if test "x$ac_cv_func_getpeereid" = xno && test "x$ac_cv_func_getpeerucred" = xno && test "x$xorg_cv_sys_have_so_peercred" = xno ; then
+	AC_DEFINE([NO_LOCAL_CLIENT_CRED], 1, [Define to 1 if no local socket credentials interface exists])
+fi
+
 dnl Find the math libary, then check for cbrt function in it.
 AC_CHECK_LIB(m, sqrt)
 AC_CHECK_FUNCS([cbrt])
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index c2ba434..daaff8d 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -518,4 +518,7 @@
 /* Listen on local socket */
 #undef LISTEN_LOCAL
 
+/* Define if no local socket credentials interface exists */
+#undef NO_LOCAL_CLIENT_CRED
+
 #endif /* _DIX_CONFIG_H_ */
diff --git a/os/access.c b/os/access.c
index 75e7a69..54f0690 100644
--- a/os/access.c
+++ b/os/access.c
@@ -1221,7 +1221,6 @@ GetLocalClientCreds(ClientPtr client, LocalClientCredRec ** lccp)
 #endif
 #else
     /* No system call available to get the credentials of the peer */
-#define NO_LOCAL_CLIENT_CRED
     return -1;
 #endif
 }
commit f8a2c087c89ed5b638a2e62987f255d3f04f914e
Author: Javier Jardón <jjardon at gnome.org>
Date:   Sun Mar 22 03:52:03 2015 +0000

    configure.ac: Add support for new versions of systemd
    
    ... that only provide a unique libsystemd.pc file
    
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Javier Jardón <jjardon at gnome.org>

diff --git a/configure.ac b/configure.ac
index 8d6a950..bab7d89 100644
--- a/configure.ac
+++ b/configure.ac
@@ -822,7 +822,9 @@ AC_ARG_WITH([systemd-daemon],
 		[support systemd socket activation (default: auto)]),
 	[WITH_SYSTEMD_DAEMON=$withval], [WITH_SYSTEMD_DAEMON=auto])
 PKG_CHECK_MODULES([SYSTEMD_DAEMON], [libsystemd-daemon],
-                  [HAVE_SYSTEMD_DAEMON=yes], [HAVE_SYSTEMD_DAEMON=no])
+                  [HAVE_SYSTEMD_DAEMON=yes],
+                  [PKG_CHECK_MODULES([SYSTEMD_DAEMON], [libsystemd],
+                                     [HAVE_SYSTEMD_DAEMON=yes], [HAVE_SYSTEMD_DAEMON=no])])
 if test "x$WITH_SYSTEMD_DAEMON" = xauto; then
 	WITH_SYSTEMD_DAEMON="$HAVE_SYSTEMD_DAEMON"
 fi
commit 67dd34fa734085ed67ba7790820fe4743d48b60f
Author: Adam Jackson <ajax at redhat.com>
Date:   Wed Jun 10 13:20:59 2015 -0400

    render: Simplify SProcRenderScale
    
    Since ProcRenderScale throws BadImplementation anyway it's pointless to
    waste time carefully swapping the request.
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/render/render.c b/render/render.c
index 88d8a26..b777991 100644
--- a/render/render.c
+++ b/render/render.c
@@ -2099,20 +2099,7 @@ SProcRenderComposite(ClientPtr client)
 static int
 SProcRenderScale(ClientPtr client)
 {
-    REQUEST(xRenderScaleReq);
-    REQUEST_SIZE_MATCH(xRenderScaleReq);
-    swaps(&stuff->length);
-    swapl(&stuff->src);
-    swapl(&stuff->dst);
-    swapl(&stuff->colorScale);
-    swapl(&stuff->alphaScale);
-    swaps(&stuff->xSrc);
-    swaps(&stuff->ySrc);
-    swaps(&stuff->xDst);
-    swaps(&stuff->yDst);
-    swaps(&stuff->width);
-    swaps(&stuff->height);
-    return (*ProcRenderVector[stuff->renderReqType]) (client);
+    return BadImplementation;
 }
 
 static int
commit a579e6ba7763749d51d16e3a54941e06939df07a
Author: Ian Scott <ian.scott at arteris.com>
Date:   Thu May 21 16:13:12 2015 -0700

    Xephyr: Paint with subimage for non-Glamor & non-XSHM case
    
    This improves the case for when we paint an area without SHM.
    xcb_image_subimage() is used to create a subimage for the damaged area, which
    is converted to native format if necessary.
    
    Signed-off-by: Ian Scott <ian.scott at arteris.com>
    Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index 5406938..3991c51 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -1047,11 +1047,13 @@ hostx_paint_rect(KdScreenInfo *screen,
                           sx, sy, dx, dy, width, height, FALSE);
     }
     else {
-        /* This is slow and could be done better */
-        xcb_image_t *img = xcb_image_native (HostX.conn, scrpriv->ximg, 1);
-        xcb_image_put(HostX.conn, scrpriv->win, HostX.gc, img, 0, 0, 0);
-        if (scrpriv->ximg != img)
+        xcb_image_t *subimg = xcb_image_subimage(scrpriv->ximg, sx, sy,
+                                                 width, height, 0, 0, 0);
+        xcb_image_t *img = xcb_image_native(HostX.conn, subimg, 1);
+        xcb_image_put(HostX.conn, scrpriv->win, HostX.gc, img, dx, dy, 0);
+        if (subimg != img)
             xcb_image_destroy(img);
+        xcb_image_destroy(subimg);
     }
 
     xcb_aux_sync(HostX.conn);
commit a6c0564f7f00aa66fd19180f75b6b09904444f06
Author: Laércio de Sousa <laerciosousa at sme-mogidascruzes.sp.gov.br>
Date:   Mon Mar 23 10:58:03 2015 -0300

    ephyr: move host_has_extension() implementation to hostx.c
    
    This is a trivial patch that moves host_has_extension() implementation
    from ephyr.c to hostx.c so that it can be called by hostx.c internal
    functions. Also rename function to hostx_has_extension() for consistency.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Laércio de Sousa <laerciosousa at sme-mogidascruzes.sp.gov.br>

diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index e6e72d3..1909a06 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -71,16 +71,6 @@ Bool EphyrWantResize = 0;
 Bool EphyrWantNoHostGrab = 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);
@@ -670,7 +660,7 @@ ephyrInitScreen(ScreenPtr pScreen)
     }
 #endif /*XV*/
 #ifdef XF86DRI
-    if (!ephyrNoDRI && !host_has_extension(&xcb_xf86dri_id)) {
+    if (!ephyrNoDRI && !hostx_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 748b608..3703adf 100644
--- a/hw/kdrive/ephyr/ephyrdriext.c
+++ b/hw/kdrive/ephyr/ephyrdriext.c
@@ -1321,12 +1321,12 @@ ephyrDRIExtensionInit(ScreenPtr a_screen)
     EphyrDRIScreenPrivPtr screen_priv = NULL;
 
     EPHYR_LOG("enter\n");
-    if (!host_has_extension(&xcb_xf86dri_id)) {
+    if (!hostx_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 (!host_has_extension(&xcb_shape_id)) {
+    if (!hostx_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 248689e..c6d1569 100644
--- a/hw/kdrive/ephyr/ephyrglxext.c
+++ b/hw/kdrive/ephyr/ephyrglxext.c
@@ -84,7 +84,7 @@ ephyrHijackGLXExtension(void)
 {
     const void *(*dispatch_functions)[2];
 
-    if (!host_has_extension(&xcb_glx_id)) {
+    if (!hostx_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 dc265d5..5406938 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -99,6 +99,16 @@ int ephyrResNameFromCmd = 0;
 char *ephyrTitle = NULL;
 Bool ephyr_glamor = FALSE;
 
+Bool
+hostx_has_extension(xcb_extension_t *extension)
+{
+    const xcb_query_extension_reply_t *rep;
+
+    rep = xcb_get_extension_data(HostX.conn, extension);
+
+    return rep && rep->present;
+}
+
 static void
  hostx_set_fullscreen_hint(void);
 
@@ -240,7 +250,7 @@ hostx_get_output_geometry(const char *output,
     xcb_randr_get_crtc_info_reply_t *crtc_info_r;
 
     /* First of all, check for extension */
-    if (!xcb_get_extension_data(HostX.conn, &xcb_randr_id)->present)
+    if (!hostx_has_extension(&xcb_randr_id))
     {
         fprintf(stderr, "\nHost X server does not support RANDR extension (or it's disabled).\n");
         exit(1);
@@ -422,7 +432,6 @@ hostx_init(void)
     char *tmpstr;
     char *class_hint;
     size_t class_len;
-    const xcb_query_extension_reply_t *shm_rep;
     xcb_screen_t *xscreen;
     xcb_rectangle_t rect = { 0, 0, 1, 1 };
 
@@ -632,8 +641,7 @@ hostx_init(void)
     }
 
     /* 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")) {
+    if (!hostx_has_extension(&xcb_shm_id) || getenv("XEPHYR_NO_SHM")) {
         fprintf(stderr, "\nXephyr unable to use SHM XImages\n");
         HostX.have_shm = FALSE;
     }
diff --git a/hw/kdrive/ephyr/hostx.h b/hw/kdrive/ephyr/hostx.h
index 93aaa50..9299e8d 100644
--- a/hw/kdrive/ephyr/hostx.h
+++ b/hw/kdrive/ephyr/hostx.h
@@ -182,7 +182,7 @@ 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 host_has_extension(xcb_extension_t *extension);
+int hostx_has_extension(xcb_extension_t *extension);
 
 #ifdef XF86DRI
 int hostx_lookup_peer_window(void *a_local_window,
commit 9414ba3683231afe9bee0f941c53998dea218615
Author: Jürg Billeter <j at bitron.ch>
Date:   Sun Feb 8 11:34:18 2015 +0100

    ephyr: fix -no-host-grab argument processing
    
    Signed-off-by: Jürg Billeter <j at bitron.ch>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/hw/kdrive/ephyr/ephyrinit.c b/hw/kdrive/ephyr/ephyrinit.c
index 8fbaf1d..d86baf2 100644
--- a/hw/kdrive/ephyr/ephyrinit.c
+++ b/hw/kdrive/ephyr/ephyrinit.c
@@ -367,7 +367,7 @@ ddxProcessArgument(int argc, char **argv, int i)
     /* end Xnest compat */
     else if (!strcmp(argv[i], "-no-host-grab")) {
         EphyrWantNoHostGrab = 1;
-        return 2;
+        return 1;
     }
 
     return KdProcessArgument(argc, argv, i);
commit 1f915e8b524dd02011158aa038935970684c7630
Author: Daniel Drake <drake at endlessm.com>
Date:   Wed May 20 13:16:12 2015 -0600

    Keep SIGALRM restart flag after Popen
    
    Commit 94ab7455 added SA_RESTART to the SIGALRM handler.  However, the
    Popen code tears down and recreates the SIGALRM handler via OsSignal(),
    and this flag is dropped at this time.
    
    Clean the code to use just a single codepath for creating this signal
    handler, always applying SA_RESTART.
    
    [ajax: Fixed commit id]
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Daniel Drake <drake at endlessm.com>

diff --git a/os/utils.c b/os/utils.c
index 9b6fb30..b45719e 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -1243,14 +1243,15 @@ SmartScheduleTimer(int sig)
     SmartScheduleTime += SmartScheduleInterval;
 }
 
-void
-SmartScheduleInit(void)
+static int
+SmartScheduleEnable(void)
 {
+    int ret = 0;
 #ifdef SMART_SCHEDULE_POSSIBLE
     struct sigaction act;
 
     if (SmartScheduleDisable)
-        return;
+        return 0;
 
     memset((char *) &act, 0, sizeof(struct sigaction));
 
@@ -1259,11 +1260,40 @@ SmartScheduleInit(void)
     act.sa_handler = SmartScheduleTimer;
     sigemptyset(&act.sa_mask);
     sigaddset(&act.sa_mask, SIGALRM);
-    if (sigaction(SIGALRM, &act, 0) < 0) {
+    ret = sigaction(SIGALRM, &act, 0);
+#endif
+    return ret;
+}
+
+static int
+SmartSchedulePause(void)
+{
+    int ret = 0;
+#ifdef SMART_SCHEDULE_POSSIBLE
+    struct sigaction act;
+
+    if (SmartScheduleDisable)
+        return 0;
+
+    memset((char *) &act, 0, sizeof(struct sigaction));
+
+    act.sa_handler = SIG_IGN;
+    sigemptyset(&act.sa_mask);
+    ret = sigaction(SIGALRM, &act, 0);
+#endif
+    return ret;
+}
+
+void
+SmartScheduleInit(void)
+{
+    if (SmartScheduleDisable)
+        return;
+
+    if (SmartScheduleEnable() < 0) {
         perror("sigaction for smart scheduler");
         SmartScheduleDisable = TRUE;
     }
-#endif
 }
 
 #ifdef SIG_BLOCK
@@ -1438,8 +1468,6 @@ static struct pid {
     int pid;
 } *pidlist;
 
-OsSigHandlerPtr old_alarm = NULL;       /* XXX horrible awful hack */
-
 void *
 Popen(const char *command, const char *type)
 {
@@ -1462,8 +1490,7 @@ Popen(const char *command, const char *type)
     }
 
     /* Ignore the smart scheduler while this is going on */
-    old_alarm = OsSignal(SIGALRM, SIG_IGN);
-    if (old_alarm == SIG_ERR) {
+    if (SmartSchedulePause() < 0) {
         close(pdes[0]);
         close(pdes[1]);
         free(cur);
@@ -1476,7 +1503,7 @@ Popen(const char *command, const char *type)
         close(pdes[0]);
         close(pdes[1]);
         free(cur);
-        if (OsSignal(SIGALRM, old_alarm) == SIG_ERR)
+        if (SmartScheduleEnable() < 0)
             perror("signal");
         return NULL;
     case 0:                    /* child */
@@ -1651,7 +1678,7 @@ Pclose(void *iop)
     /* allow EINTR again */
     OsReleaseSignals();
 
-    if (old_alarm && OsSignal(SIGALRM, old_alarm) == SIG_ERR) {
+    if (SmartScheduleEnable() < 0) {
         perror("signal");
         return -1;
     }
commit 94ab7455abc213fc96760e29ab2e943ec682fb22
Author: Daniel Drake <drake at endlessm.com>
Date:   Tue May 12 16:39:22 2015 -0600

    Allow system call restarts upon signal interruption
    
    The X server frequently deals with SIGIO and SIGALRM interruptions.
    If process execution is inside certain blocking system calls
    when these signals arrive, e.g. with the kernel blocked on
    a contended semaphore, the system calls will be interrupted.
    
    Some system calls are automatically restartable (the kernel re-executes
    them with the same parameters once the signal handler returns) but
    only if the signal handler allows it.
    
    Set SA_RESTART on the signal handlers to enable this convenient
    behaviour.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Daniel Drake <drake at endlessm.com>

diff --git a/hw/xfree86/os-support/shared/sigio.c b/hw/xfree86/os-support/shared/sigio.c
index 45949f7..c746d02 100644
--- a/hw/xfree86/os-support/shared/sigio.c
+++ b/hw/xfree86/os-support/shared/sigio.c
@@ -178,7 +178,7 @@ xf86InstallSIGIOHandler(int fd, void (*f) (int, void *), void *closure)
             }
             sigemptyset(&sa.sa_mask);
             sigaddset(&sa.sa_mask, SIGIO);
-            sa.sa_flags = 0;
+            sa.sa_flags = SA_RESTART;
             sa.sa_handler = xf86SIGIO;
             sigaction(SIGIO, &sa, &osa);
             xf86SigIOFuncs[i].fd = fd;
diff --git a/os/utils.c b/os/utils.c
index 868eb04..9b6fb30 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -1255,6 +1255,7 @@ SmartScheduleInit(void)
     memset((char *) &act, 0, sizeof(struct sigaction));
 
     /* Set up the timer signal function */
+    act.sa_flags = SA_RESTART;
     act.sa_handler = SmartScheduleTimer;
     sigemptyset(&act.sa_mask);
     sigaddset(&act.sa_mask, SIGALRM);
commit 1ba4fde1015fc6da19dfbfdf0f77f1071416e215
Author: Boyan Ding <stu_dby at 126.com>
Date:   Mon Aug 4 21:16:34 2014 +0800

    xwayland: Activate and enable device on first capability reporting
    
    Commit 2172714c changed behavior of capability handling, but it only
    solved part of the problem. If Xwayland is launched without a capability
    (e.g. no pointer device is connected when Xwayland was spinned up), and
    later that capability comes, the device added will not be automatically
    initialized. This patch initializes the device when the capability is
    reported for the first time, thus avoiding the problem.
    
    Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=81819
    Signed-off-by: Boyan Ding <stu_dby at 126.com>
    Reviewed-by: Daniel Stone <daniels at collabora.com>

diff --git a/hw/xwayland/xwayland-input.c b/hw/xwayland/xwayland-input.c
index a29ba78..010d28c 100644
--- a/hw/xwayland/xwayland-input.c
+++ b/hw/xwayland/xwayland-input.c
@@ -692,13 +692,13 @@ seat_handle_capabilities(void *data, struct wl_seat *seat,
         wl_pointer_add_listener(xwl_seat->wl_pointer,
                                 &pointer_listener, xwl_seat);
 
-        if (xwl_seat->pointer)
-            EnableDevice(xwl_seat->pointer, TRUE);
-        else {
+        if (xwl_seat->pointer == NULL) {
             xwl_seat_set_cursor(xwl_seat);
             xwl_seat->pointer =
                 add_device(xwl_seat, "xwayland-pointer", xwl_pointer_proc);
+            ActivateDevice(xwl_seat->pointer, TRUE);
         }
+        EnableDevice(xwl_seat->pointer, TRUE);
     } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && xwl_seat->wl_pointer) {
         wl_pointer_release(xwl_seat->wl_pointer);
         xwl_seat->wl_pointer = NULL;
@@ -712,12 +712,12 @@ seat_handle_capabilities(void *data, struct wl_seat *seat,
         wl_keyboard_add_listener(xwl_seat->wl_keyboard,
                                  &keyboard_listener, xwl_seat);
 
-        if (xwl_seat->keyboard)
-            EnableDevice(xwl_seat->keyboard, TRUE);
-        else {
+        if (xwl_seat->keyboard == NULL) {
             xwl_seat->keyboard =
                 add_device(xwl_seat, "xwayland-keyboard", xwl_keyboard_proc);
+            ActivateDevice(xwl_seat->keyboard, TRUE);
         }
+        EnableDevice(xwl_seat->keyboard, TRUE);
     } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && xwl_seat->wl_keyboard) {
         wl_keyboard_release(xwl_seat->wl_keyboard);
         xwl_seat->wl_keyboard = NULL;
commit f1995de1c43733a9e586605674c4071357a58e78
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Aug 28 14:28:11 2015 +1000

    xwayland: call through to miPointerWarpCursor on warp_cursor
    
    This is (eventually) called during
    InitializeSprite() → *pScreen->SetCursorPosition → miPointerSetCursorPosition
    when a device is set to floating. We don't do anything special outselves, but
    we need to pass on to the next layer to make sure the device is initialized
    properly. Otherwise, pScreen stays NULL and eventually crashes the server when
    we try to clean up behind us.
    
    Test case: grab a device → floats it, ungrab again → crash
    
    Reported-by: Jason Gerecke <killertofu at gmail.com>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Olivier Fourdan <ofourdan at redhat.com>

diff --git a/hw/xwayland/xwayland-cursor.c b/hw/xwayland/xwayland-cursor.c
index c137e1e..76729db 100644
--- a/hw/xwayland/xwayland-cursor.c
+++ b/hw/xwayland/xwayland-cursor.c
@@ -199,6 +199,7 @@ xwl_cross_screen(ScreenPtr pScreen, Bool entering)
 static void
 xwl_pointer_warp_cursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y)
 {
+    miPointerWarpCursor(pDev, pScreen, x, y);
 }
 
 static miPointerScreenFuncRec xwl_pointer_screen_funcs = {
commit 373599ab008f0ecf8f3fb62455a5474f5ec8f499
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Aug 28 14:28:10 2015 +1000

    xwayland: fix crash on enter/leave for a grabbed slave device
    
    When grabbed, the slave device is floating, i.e. the master device is NULL.
    CheckMotion() isn't happy with NULL. Make sure we pass the right device in,
    either the master device when the device is attached, or the device itself
    when it is floating.
    
    Reported-by: Jason Gerecke <killertofu at gmail.com>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Olivier Fourdan <ofourdan at redhat.com>

diff --git a/hw/xwayland/xwayland-input.c b/hw/xwayland/xwayland-input.c
index 143a801..a29ba78 100644
--- a/hw/xwayland/xwayland-input.c
+++ b/hw/xwayland/xwayland-input.c
@@ -231,7 +231,7 @@ pointer_handle_enter(void *data, struct wl_pointer *pointer,
     xwl_seat->focus_window = wl_surface_get_user_data(surface);
 
     (*pScreen->SetCursorPosition) (dev, pScreen, sx, sy, TRUE);
-    CheckMotion(NULL, GetMaster(dev, MASTER_POINTER));
+    CheckMotion(NULL, GetMaster(dev, POINTER_OR_FLOAT));
 
     /* Ideally, X clients shouldn't see these button releases.  When
      * the pointer leaves a window with buttons down, it means that
@@ -259,7 +259,7 @@ pointer_handle_leave(void *data, struct wl_pointer *pointer,
     xwl_seat->xwl_screen->serial = serial;
 
     xwl_seat->focus_window = NULL;
-    CheckMotion(NULL, GetMaster(dev, MASTER_POINTER));
+    CheckMotion(NULL, GetMaster(dev, POINTER_OR_FLOAT));
 }
 
 static void
commit f1ba8858d5baa63cde6361492e6d349ce1b38d21
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Aug 28 14:28:09 2015 +1000

    xwayland: use the device pointer we already have
    
    No functional changes.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Olivier Fourdan <ofourdan at redhat.com>

diff --git a/hw/xwayland/xwayland-input.c b/hw/xwayland/xwayland-input.c
index d26a786..143a801 100644
--- a/hw/xwayland/xwayland-input.c
+++ b/hw/xwayland/xwayland-input.c
@@ -246,7 +246,7 @@ pointer_handle_enter(void *data, struct wl_pointer *pointer,
     valuator_mask_zero(&mask);
     for (i = 0; i < dev->button->numButtons; i++)
         if (BitIsOn(dev->button->down, i))
-            QueuePointerEvents(xwl_seat->pointer, ButtonRelease, i, 0, &mask);
+            QueuePointerEvents(dev, ButtonRelease, i, 0, &mask);
 }
 
 static void
commit 44f250a7e8eb86d3f41da5d186d839e7a14648a3
Author: Carlos Garnacho <carlosg at gnome.org>
Date:   Wed May 27 18:42:00 2015 +0200

    xwayland: Remove related touchpoints when unrealizing windows
    
    These sequences are forgotten to all purposes.
    
    Signed-off-by: Carlos Garnacho <carlosg at gnome.org>
    Reviewed-by: Olivier Fourdan <ofourdan at redhat.com>

diff --git a/hw/xwayland/xwayland-input.c b/hw/xwayland/xwayland-input.c
index ef38e6a..d26a786 100644
--- a/hw/xwayland/xwayland-input.c
+++ b/hw/xwayland/xwayland-input.c
@@ -845,6 +845,20 @@ DDXRingBell(int volume, int pitch, int duration)
 }
 
 void
+xwl_seat_clear_touch(struct xwl_seat *xwl_seat, WindowPtr window)
+{
+    struct xwl_touch *xwl_touch, *next_xwl_touch;
+
+    xorg_list_for_each_entry_safe(xwl_touch, next_xwl_touch,
+                                  &xwl_seat->touches, link_touch) {
+        if (xwl_touch->window->window == window) {
+            xorg_list_del(&xwl_touch->link_touch);
+            free(xwl_touch);
+        }
+    }
+}
+
+void
 InitInput(int argc, char *argv[])
 {
     ScreenPtr pScreen = screenInfo.screens[0];
diff --git a/hw/xwayland/xwayland.c b/hw/xwayland/xwayland.c
index bc92beb..f25bc00 100644
--- a/hw/xwayland/xwayland.c
+++ b/hw/xwayland/xwayland.c
@@ -287,10 +287,10 @@ xwl_unrealize_window(WindowPtr window)
     xwl_screen = xwl_screen_get(screen);
 
     xorg_list_for_each_entry(xwl_seat, &xwl_screen->seat_list, link) {
-        if (!xwl_seat->focus_window)
-            continue;
-        if (xwl_seat->focus_window->window == window)
+        if (xwl_seat->focus_window && xwl_seat->focus_window->window == window)
             xwl_seat->focus_window = NULL;
+
+        xwl_seat_clear_touch(xwl_seat, window);
     }
 
     screen->UnrealizeWindow = xwl_screen->UnrealizeWindow;
diff --git a/hw/xwayland/xwayland.h b/hw/xwayland/xwayland.h
index 857650e..53ca420 100644
--- a/hw/xwayland/xwayland.h
+++ b/hw/xwayland/xwayland.h
@@ -159,6 +159,8 @@ void xwl_seat_set_cursor(struct xwl_seat *xwl_seat);
 
 void xwl_seat_destroy(struct xwl_seat *xwl_seat);
 
+void xwl_seat_clear_touch(struct xwl_seat *xwl_seat, WindowPtr window);
+
 Bool xwl_screen_init_output(struct xwl_screen *xwl_screen);
 
 struct xwl_output *xwl_output_create(struct xwl_screen *xwl_screen,
commit b7cd48f71d269101e28ae6855b895057378715f9
Author: Carlos Garnacho <carlosg at gnome.org>
Date:   Wed May 27 18:41:59 2015 +0200

    xwayland: Implement the wl_touch interface
    
    A DeviceIntPtr with touch valuators is also created in order to deliver
    the translated touch events. The lifetime of xwl_touch structs is tied
    to the wayland ones, finishing in either wl_touch.up() or wl_touch.cancel()
    
    Signed-off-by: Carlos Garnacho <carlosg at gnome.org>
    Reviewed-by: Olivier Fourdan <ofourdan at redhat.com>

diff --git a/hw/xwayland/xwayland-input.c b/hw/xwayland/xwayland-input.c
index 997b90f..ef38e6a 100644
--- a/hw/xwayland/xwayland-input.c
+++ b/hw/xwayland/xwayland-input.c
@@ -148,6 +148,61 @@ xwl_keyboard_proc(DeviceIntPtr device, int what)
     return BadMatch;
 }
 
+static int
+xwl_touch_proc(DeviceIntPtr device, int what)
+{
+#define NTOUCHPOINTS 20
+#define NBUTTONS 1
+#define NAXES 2
+    struct xwl_seat *xwl_seat = device->public.devicePrivate;
+    Atom btn_labels[NBUTTONS] = { 0 };
+    Atom axes_labels[NAXES] = { 0 };
+    BYTE map[NBUTTONS + 1] = { 0 };
+
+    switch (what) {
+    case DEVICE_INIT:
+        device->public.on = FALSE;
+
+        axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_MT_POSITION_X);
+        axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_MT_POSITION_Y);
+
+        if (!InitValuatorClassDeviceStruct(device, NAXES, axes_labels,
+                                           GetMotionHistorySize(), Absolute))
+            return BadValue;
+
+        if (!InitButtonClassDeviceStruct(device, NBUTTONS, btn_labels, map))
+            return BadValue;
+
+        if (!InitTouchClassDeviceStruct(device, NTOUCHPOINTS,
+                                        XIDirectTouch, NAXES))
+            return BadValue;
+
+        /* Valuators */
+        /* FIXME: devices might be mapped to a single wl_output */
+        InitValuatorAxisStruct(device, 0, axes_labels[0],
+                               0, xwl_seat->xwl_screen->width,
+                               10000, 0, 10000, Absolute);
+        InitValuatorAxisStruct(device, 1, axes_labels[1],
+                               0, xwl_seat->xwl_screen->height,
+                               10000, 0, 10000, Absolute);
+        return Success;
+
+    case DEVICE_ON:
+        device->public.on = TRUE;
+        return Success;
+
+    case DEVICE_OFF:
+    case DEVICE_CLOSE:
+        device->public.on = FALSE;
+        return Success;
+    }
+
+    return BadMatch;
+#undef NAXES
+#undef NBUTTONS
+#undef NTOUCHPOINTS
+}
+
 static void
 pointer_handle_enter(void *data, struct wl_pointer *pointer,
                      uint32_t serial, struct wl_surface *surface,
@@ -480,6 +535,129 @@ static const struct wl_keyboard_listener keyboard_listener = {
     keyboard_handle_repeat_info,
 };
 
+static struct xwl_touch *
+xwl_seat_lookup_touch(struct xwl_seat *xwl_seat, int32_t id)
+{
+    struct xwl_touch *xwl_touch, *next_xwl_touch;
+
+    xorg_list_for_each_entry_safe(xwl_touch, next_xwl_touch,
+                                  &xwl_seat->touches, link_touch) {
+        if (xwl_touch->id == id)
+            return xwl_touch;
+    }
+
+    return NULL;
+}
+
+static void
+xwl_touch_send_event(struct xwl_touch *xwl_touch,
+                     struct xwl_seat *xwl_seat, int type)
+{
+    int32_t dx, dy;
+    ValuatorMask mask;
+
+    dx = xwl_touch->window->window->drawable.x;
+    dy = xwl_touch->window->window->drawable.y;
+
+    valuator_mask_zero(&mask);
+    valuator_mask_set(&mask, 0, dx + xwl_touch->x);
+    valuator_mask_set(&mask, 1, dy + xwl_touch->y);
+    QueueTouchEvents(xwl_seat->touch, type, xwl_touch->id, 0, &mask);
+}
+
+static void
+touch_handle_down(void *data, struct wl_touch *wl_touch,
+                  uint32_t serial, uint32_t time,
+                  struct wl_surface *surface,
+                  int32_t id, wl_fixed_t sx_w, wl_fixed_t sy_w)
+{
+    struct xwl_seat *xwl_seat = data;
+    struct xwl_touch *xwl_touch;
+
+    if (surface == NULL)
+        return;
+
+    xwl_touch = calloc(sizeof *xwl_touch, 1);
+    if (xwl_touch == NULL) {
+        ErrorF("touch_handle_down ENOMEM");
+        return;
+    }
+
+    xwl_touch->window = wl_surface_get_user_data(surface);
+    xwl_touch->id = id;
+    xwl_touch->x = wl_fixed_to_int(sx_w);
+    xwl_touch->y = wl_fixed_to_int(sy_w);
+    xorg_list_add(&xwl_touch->link_touch, &xwl_seat->touches);
+
+    xwl_touch_send_event(xwl_touch, xwl_seat, XI_TouchBegin);
+}
+
+static void
+touch_handle_up(void *data, struct wl_touch *wl_touch,
+                uint32_t serial, uint32_t time, int32_t id)
+{
+    struct xwl_touch *xwl_touch;
+    struct xwl_seat *xwl_seat = data;
+
+    xwl_touch = xwl_seat_lookup_touch(xwl_seat, id);
+
+    if (!xwl_touch)
+        return;
+
+    xwl_touch_send_event(xwl_touch, xwl_seat, XI_TouchEnd);
+    xorg_list_del(&xwl_touch->link_touch);
+    free(xwl_touch);
+}
+
+static void
+touch_handle_motion(void *data, struct wl_touch *wl_touch,
+                    uint32_t time, int32_t id,
+                    wl_fixed_t sx_w, wl_fixed_t sy_w)
+{
+    struct xwl_seat *xwl_seat = data;
+    struct xwl_touch *xwl_touch;
+
+    xwl_touch = xwl_seat_lookup_touch(xwl_seat, id);
+
+    if (!xwl_touch)
+        return;
+
+    xwl_touch->x = wl_fixed_to_int(sx_w);
+    xwl_touch->y = wl_fixed_to_int(sy_w);
+    xwl_touch_send_event(xwl_touch, xwl_seat, XI_TouchUpdate);
+}
+
+static void
+touch_handle_frame(void *data, struct wl_touch *wl_touch)
+{
+}
+
+static void
+touch_handle_cancel(void *data, struct wl_touch *wl_touch)
+{
+    struct xwl_seat *xwl_seat = data;
+    struct xwl_touch *xwl_touch, *next_xwl_touch;
+
+    xorg_list_for_each_entry_safe(xwl_touch, next_xwl_touch,
+                                  &xwl_seat->touches, link_touch) {
+        /* We can't properly notify of cancellation to the X client
+         * once it thinks it has the ownership, send at least a
+         * TouchEnd event.
+         */
+        xwl_touch_send_event(xwl_touch, xwl_seat, XI_TouchEnd);
+        xorg_list_del(&xwl_touch->link_touch);
+        free(xwl_touch);
+    }
+}
+
+static const struct wl_touch_listener touch_listener = {
+    touch_handle_down,
+    touch_handle_up,
+    touch_handle_motion,
+    touch_handle_frame,
+    touch_handle_cancel
+};
+
 static DeviceIntPtr
 add_device(struct xwl_seat *xwl_seat,
            const char *driver, DeviceProc device_proc)
@@ -548,8 +726,26 @@ seat_handle_capabilities(void *data, struct wl_seat *seat,
             DisableDevice(xwl_seat->keyboard, TRUE);
     }
 
+    if (caps & WL_SEAT_CAPABILITY_TOUCH && xwl_seat->wl_touch == NULL) {
+        xwl_seat->wl_touch = wl_seat_get_touch(seat);
+        wl_touch_add_listener(xwl_seat->wl_touch,
+                              &touch_listener, xwl_seat);
+
+        if (xwl_seat->touch)
+            EnableDevice(xwl_seat->touch, TRUE);
+        else {
+            xwl_seat->touch =
+                add_device(xwl_seat, "xwayland-touch", xwl_touch_proc);
+        }
+    } else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && xwl_seat->wl_touch) {
+        wl_touch_release(xwl_seat->wl_touch);
+        xwl_seat->wl_touch = NULL;
+
+        if (xwl_seat->touch)
+            DisableDevice(xwl_seat->touch, TRUE);
+    }
+
     xwl_seat->xwl_screen->expecting_event--;
-    /* FIXME: Touch ... */
 }
 
 static void
diff --git a/hw/xwayland/xwayland.h b/hw/xwayland/xwayland.h
index 3c10862..857650e 100644
--- a/hw/xwayland/xwayland.h
+++ b/hw/xwayland/xwayland.h
@@ -116,10 +116,12 @@ struct xwl_touch {
 struct xwl_seat {
     DeviceIntPtr pointer;
     DeviceIntPtr keyboard;
+    DeviceIntPtr touch;
     struct xwl_screen *xwl_screen;
     struct wl_seat *seat;
     struct wl_pointer *wl_pointer;
     struct wl_keyboard *wl_keyboard;
+    struct wl_touch *wl_touch;
     struct wl_array keys;
     struct xwl_window *focus_window;
     uint32_t id;
commit d96eccc057094be31c1ee4e3b3246675934cb19d
Author: Carlos Garnacho <carlosg at gnome.org>
Date:   Wed May 27 18:41:58 2015 +0200

    xwayland: Add xwl_touch struct
    
    This struct holds information about each individual, ongoing touchpoint.
    A list of these is held by the xwl_seat.
    
    Signed-off-by: Carlos Garnacho <carlosg at gnome.org>
    Reviewed-by: Olivier Fourdan <ofourdan at redhat.com>

diff --git a/hw/xwayland/xwayland-input.c b/hw/xwayland/xwayland-input.c
index 4a166ef..997b90f 100644
--- a/hw/xwayland/xwayland-input.c
+++ b/hw/xwayland/xwayland-input.c
@@ -586,11 +586,21 @@ create_input_device(struct xwl_screen *xwl_screen, uint32_t id, uint32_t version
     xwl_seat->cursor = wl_compositor_create_surface(xwl_screen->compositor);
     wl_seat_add_listener(xwl_seat->seat, &seat_listener, xwl_seat);
     wl_array_init(&xwl_seat->keys);
+
+    xorg_list_init(&xwl_seat->touches);
 }
 
 void
 xwl_seat_destroy(struct xwl_seat *xwl_seat)
 {
+    struct xwl_touch *xwl_touch, *next_xwl_touch;
+
+    xorg_list_for_each_entry_safe(xwl_touch, next_xwl_touch,
+                                  &xwl_seat->touches, link_touch) {
+        xorg_list_del(&xwl_touch->link_touch);
+        free(xwl_touch);
+    }
+
     wl_seat_destroy(xwl_seat->seat);
     wl_surface_destroy(xwl_seat->cursor);
     if (xwl_seat->cursor_frame_cb)
diff --git a/hw/xwayland/xwayland.h b/hw/xwayland/xwayland.h
index cd728ca..3c10862 100644
--- a/hw/xwayland/xwayland.h
+++ b/hw/xwayland/xwayland.h
@@ -106,6 +106,13 @@ struct xwl_window {
 
 #define MODIFIER_META 0x01
 
+struct xwl_touch {
+    struct xwl_window *window;
+    int32_t id;
+    int x, y;
+    struct xorg_list link_touch;
+};
+
 struct xwl_seat {
     DeviceIntPtr pointer;
     DeviceIntPtr keyboard;
@@ -123,6 +130,8 @@ struct xwl_seat {
     struct wl_callback *cursor_frame_cb;
     Bool cursor_needs_update;
 
+    struct xorg_list touches;
+
     size_t keymap_size;
     char *keymap;
     struct wl_surface *keyboard_focus;
commit c1565f3ca663aa4ba4316d7248737ab817116fbd
Author: Jasper St. Pierre <jstpierre at mecheye.net>
Date:   Sat Feb 21 11:53:59 2015 -0800

    xwayland-input: Remove our XYToWindow handler
    
    This was built as a hack for simple Wayland compositors like Weston
    which were lazy and didn't want to configure windows server-side when
    moved.
    
    Since comboboxes and menus are separate toplevel O-R windows, this hack
    breaks input as it needs to be traced normally, not simply sent to the
    focused window.
    
    X11 toolkits really do need their windows to be configured correctly
    for their O-R windows comboboxes or menus other things, so let's fix
    the lazy compositors and remove this.
    
    I have tested this patch with both Weston and Mutter and neither of
    them require any changes, and it fixes comboboxes and menus.
    
    If somebody then wants to revert 73698d4, that's fine by me, so we
    reduce the amount of API that DDXen have.
    
    Signed-off-by: Jasper St. Pierre <jstpierre at mecheye.net>
    Reviewed-by: Daniel Stone <daniels at collabora.com>

diff --git a/hw/xwayland/xwayland-input.c b/hw/xwayland/xwayland-input.c
index 32007de..4a166ef 100644
--- a/hw/xwayland/xwayland-input.c
+++ b/hw/xwayland/xwayland-input.c
@@ -638,37 +638,6 @@ DDXRingBell(int volume, int pitch, int duration)
 {
 }
 
-static WindowPtr
-xwl_xy_to_window(ScreenPtr screen, SpritePtr sprite, int x, int y)
-{
-    struct xwl_seat *xwl_seat = NULL;
-    DeviceIntPtr device;
-
-    for (device = inputInfo.devices; device; device = device->next) {
-        if (device->deviceProc == xwl_pointer_proc &&
-            device->spriteInfo->sprite == sprite) {
-            xwl_seat = device->public.devicePrivate;
-            break;
-        }
-    }
-
-    if (xwl_seat == NULL) {
-        /* XTEST device */
-        sprite->spriteTraceGood = 1;
-        return sprite->spriteTrace[0];
-    }
-
-    if (xwl_seat->focus_window) {
-        sprite->spriteTraceGood = 2;
-        sprite->spriteTrace[1] = xwl_seat->focus_window->window;
-        return miSpriteTrace(sprite, x, y);
-    }
-    else {
-        sprite->spriteTraceGood = 1;
-        return sprite->spriteTrace[0];
-    }
-}
-
 void
 InitInput(int argc, char *argv[])
 {
@@ -681,9 +650,6 @@ InitInput(int argc, char *argv[])
     wl_registry_add_listener(xwl_screen->input_registry, &input_listener,
                              xwl_screen);
 
-    xwl_screen->XYToWindow = pScreen->XYToWindow;
-    pScreen->XYToWindow = xwl_xy_to_window;
-
     xwl_screen->expecting_event = 0;
     wl_display_roundtrip(xwl_screen->display);
     while (xwl_screen->expecting_event)
diff --git a/hw/xwayland/xwayland.h b/hw/xwayland/xwayland.h
index 28b0c99..cd728ca 100644
--- a/hw/xwayland/xwayland.h
+++ b/hw/xwayland/xwayland.h
@@ -62,7 +62,6 @@ struct xwl_screen {
     DestroyWindowProcPtr DestroyWindow;
     RealizeWindowProcPtr RealizeWindow;
     UnrealizeWindowProcPtr UnrealizeWindow;
-    XYToWindowProcPtr XYToWindow;
 
     struct xorg_list output_list;
     struct xorg_list seat_list;
commit 58d54ee82dfae5486bc09d04d2760c922d54d631
Author: Emil Velikov <emil.l.velikov at gmail.com>
Date:   Wed Sep 16 22:10:22 2015 +0100

    glamor: explicitly check for GL_OES_EGL_image
    
    Otherwise we'll fail miserably later on as we try to use
    glEGLImageTargetTexture2DOES.
    
    Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>

diff --git a/glamor/glamor.c b/glamor/glamor.c
index d4a0236..8178785 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -545,6 +545,11 @@ glamor_init(ScreenPtr screen, unsigned int flags)
         }
     }
 
+    if (!epoxy_has_gl_extension("GL_OES_EGL_image")) {
+        ErrorF("GL_OES_EGL_image not available\n");
+        goto fail;
+    }
+
     glamor_priv->has_rw_pbo = FALSE;
     if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP)
         glamor_priv->has_rw_pbo = TRUE;
commit 139e36dd5cbab80a9296129f3d25379dc01442b3
Author: Ilia Mirkin <imirkin at alum.mit.edu>
Date:   Fri Sep 4 18:56:19 2015 -0400

    modesetting: fix up output naming convention
    
    A user on a nouveau-driven card ran into a problem where DVI-D-1 and
    DVI-I-1 were aliasing. The simplest fix is to provide the full connector
    names. While we're at it, rename the output names to match what is in
    the kernel, and start counting the connectors from 1 rather than 0. The
    only deviation is HDMI vs HDMI-A, which kept its original name.
    
    This will break backwards compatibility with existing xorg.conf's that
    reference output names, but the alternative is to create a separate
    counting system, further disconnecting from the kernel names.
    
    Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 4d8892f..736bfc4 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -1292,17 +1292,17 @@ static int subpixel_conv_table[7] = {
 static const char *const output_names[] = {
     "None",
     "VGA",
-    "DVI",
-    "DVI",
-    "DVI",
+    "DVI-I",
+    "DVI-D",
+    "DVI-A",
     "Composite",
-    "S-video",
+    "SVIDEO",
     "LVDS",
-    "CTV",
+    "Component",
     "DIN",
-    "DisplayPort",
-    "HDMI",
+    "DP",
     "HDMI",
+    "HDMI-B",
     "TV",
     "eDP",
     "Virtual",
@@ -1377,13 +1377,13 @@ drmmode_create_name(ScrnInfoPtr pScrn, drmModeConnectorPtr koutput, char *name,
 
  fallback:
     if (koutput->connector_type >= MS_ARRAY_SIZE(output_names))
-        snprintf(name, 32, "Unknown-%d", koutput->connector_type_id - 1);
+        snprintf(name, 32, "Unknown%d-%d", koutput->connector_type, koutput->connector_type_id);
 #ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
     else if (pScrn->is_gpu)
-        snprintf(name, 32, "%s-%d-%d", output_names[koutput->connector_type], pScrn->scrnIndex - GPU_SCREEN_OFFSET + 1, koutput->connector_type_id - 1);
+        snprintf(name, 32, "%s-%d-%d", output_names[koutput->connector_type], pScrn->scrnIndex - GPU_SCREEN_OFFSET + 1, koutput->connector_type_id);
 #endif
     else
-        snprintf(name, 32, "%s-%d", output_names[koutput->connector_type], koutput->connector_type_id - 1);
+        snprintf(name, 32, "%s-%d", output_names[koutput->connector_type], koutput->connector_type_id);
 }
 
 static unsigned int
commit a907ead7864ac5720854fa3333b66fd5187d5eaf
Author: Marek Chalupa <mchqwerty at gmail.com>
Date:   Thu Aug 20 07:43:51 2015 +0200

    xwayland: implement repeat_info event
    
    xwayland windows ignored any key repeating settings
    advertised by a compositor
    
    v2. don't hardcode version 4 of seat
        use AutoRepeatModeOn/Off
    
    v3. use min(version, 4) when binding seat
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Marek Chalupa <mchqwerty at gmail.com>

diff --git a/hw/xwayland/xwayland-input.c b/hw/xwayland/xwayland-input.c
index a961e30..32007de 100644
--- a/hw/xwayland/xwayland-input.c
+++ b/hw/xwayland/xwayland-input.c
@@ -441,12 +441,43 @@ keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard,
     }
 }
 
+static void
+keyboard_handle_repeat_info (void *data, struct wl_keyboard *keyboard,
+                             int32_t rate, int32_t delay)
+{
+    struct xwl_seat *xwl_seat = data;
+    DeviceIntPtr dev;
+    XkbControlsPtr ctrl;
+
+    if (rate < 0 || delay < 0) {
+	ErrorF("Wrong rate/delay: %d, %d\n", rate, delay);
+	return;
+    }
+
+    for (dev = inputInfo.devices; dev; dev = dev->next) {
+        if (dev != xwl_seat->keyboard &&
+            dev != GetMaster(xwl_seat->keyboard, MASTER_KEYBOARD))
+            continue;
+
+	if (rate != 0) {
+            ctrl = dev->key->xkbInfo->desc->ctrls;
+            ctrl->repeat_delay = delay;
+            /* rate is number of keys per second */
+            ctrl->repeat_interval = 1000 / rate;
+
+	    XkbSetRepeatKeys(dev, -1, AutoRepeatModeOn);
+	} else
+	    XkbSetRepeatKeys(dev, -1, AutoRepeatModeOff);
+    }
+}
+
 static const struct wl_keyboard_listener keyboard_listener = {
     keyboard_handle_keymap,
     keyboard_handle_enter,
     keyboard_handle_leave,
     keyboard_handle_key,
     keyboard_handle_modifiers,
+    keyboard_handle_repeat_info,
 };
 
 static DeviceIntPtr
@@ -534,7 +565,7 @@ static const struct wl_seat_listener seat_listener = {
 };
 
 static void
-create_input_device(struct xwl_screen *xwl_screen, uint32_t id)
+create_input_device(struct xwl_screen *xwl_screen, uint32_t id, uint32_t version)
 {
     struct xwl_seat *xwl_seat;
 
@@ -548,7 +579,8 @@ create_input_device(struct xwl_screen *xwl_screen, uint32_t id)
     xorg_list_add(&xwl_seat->link, &xwl_screen->seat_list);
 
     xwl_seat->seat =
-        wl_registry_bind(xwl_screen->registry, id, &wl_seat_interface, 3);
+        wl_registry_bind(xwl_screen->registry, id,
+                         &wl_seat_interface, min(version, 4));
     xwl_seat->id = id;
 
     xwl_seat->cursor = wl_compositor_create_surface(xwl_screen->compositor);
@@ -574,7 +606,7 @@ input_handler(void *data, struct wl_registry *registry, uint32_t id,
     struct xwl_screen *xwl_screen = data;
 
     if (strcmp(interface, "wl_seat") == 0 && version >= 3) {
-        create_input_device(xwl_screen, id);
+        create_input_device(xwl_screen, id, version);
         xwl_screen->expecting_event++;
     }
 }
commit e8e3368298c98a1292bb1c727e2f3d56539e2eac
Author: Felix Janda <felix.janda at posteo.de>
Date:   Mon Aug 17 20:25:53 2015 +0200

    On linux use <termios.h> instead of <termio.h>
    
    <termio.h> is obsolete. Using <termios.h> instead fixes building with
    musl libc.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Felix Janda <felix.janda at posteo.de>

diff --git a/hw/xfree86/os-support/xf86_OSlib.h b/hw/xfree86/os-support/xf86_OSlib.h
index 6190fe6..95c3a73 100644
--- a/hw/xfree86/os-support/xf86_OSlib.h
+++ b/hw/xfree86/os-support/xf86_OSlib.h
@@ -183,11 +183,7 @@ extern _X_HIDDEN char xf86SolarisFbDev[PATH_MAX];
 #include <sys/types.h>
 #include <assert.h>
 
-#ifdef __linux__
-#include <termio.h>
-#else                           /* __GLIBC__ */
 #include <termios.h>
-#endif
 #ifdef __sparc__
 #include <sys/param.h>
 #endif
commit dfa8b37cfb2589f2474f6fcc755dde77bfdd6fed
Author: Adam Jackson <ajax at redhat.com>
Date:   Wed Jul 29 11:30:15 2015 -0400

    glxproxy: Fix an obvious thinko in QueryExtensionsString
    
    gcc 5.1 throws a rather amusing warning here:
    
    glxcmdsswap.c: In function ‘__glXSwapQueryExtensionsString’:
    glxcmdsswap.c:439:1: warning: function might be candidate for attribute
    ‘noreturn’ [-Wsuggest-attribute=noreturn]
     __glXSwapQueryExtensionsString(__GLXclientState * cl, GLbyte * pc)
    
    This is entirely accurate, albeit curiously phrased: swapping some bits
    hanging off the end of a null pointer will make Xdmx crash, so from the
    perspective of code generation the function will indeed not return.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/dmx/glxProxy/glxcmdsswap.c b/hw/dmx/glxProxy/glxcmdsswap.c
index 600a6e1..5b1722d 100644
--- a/hw/dmx/glxProxy/glxcmdsswap.c
+++ b/hw/dmx/glxProxy/glxcmdsswap.c
@@ -438,7 +438,7 @@ __glXSwapUseXFont(__GLXclientState * cl, GLbyte * pc)
 int
 __glXSwapQueryExtensionsString(__GLXclientState * cl, GLbyte * pc)
 {
-    xGLXQueryExtensionsStringReq *req = NULL;
+    xGLXQueryExtensionsStringReq *req = (xGLXQueryExtensionsStringReq *) pc;
 
     __GLX_DECLARE_SWAP_VARIABLES;
 
commit 75ee874e432d959a70fbc2c9208d20dbfa5cbc5f
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Fri May 1 17:06:47 2015 +0100

    Build fix for DMX
    
    ./../dix/.libs/libdix.a(pixmap.o): In function `PixmapStartDirtyTracking':
    xorg/xserver/dix/pixmap.c:194: undefined reference to `RRTransformCompute'
    
    I'm not quite sure how 0db457b fixes this
    
    Move RANDR_LIB to after DIX_LIB, so the reference to RRTransformCompute in
    DIX_LIB is satisfied.
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Tested-by: Olivier Fourdan <ofourdan at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index 1f39331..8d6a950 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2268,7 +2268,7 @@ if test "x$DMX" = xyes; then
 	fi
 	DMX_INCLUDES="$XEXT_INC $RENDER_INC $RECORD_INC"
 	XDMX_CFLAGS="$DMXMODULES_CFLAGS"
-	XDMX_LIBS="$FB_LIB $MI_LIB $XEXT_LIB $RANDR_LIB $RENDER_LIB $RECORD_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB  $DRI3_LIB $PRESENT_LIB $MIEXT_SYNC_LIB $MIEXT_SHADOW_LIB $MIEXT_DAMAGE_LIB $COMPOSITE_LIB $DAMAGE_LIB $MAIN_LIB $DIX_LIB $CONFIG_LIB $OS_LIB $FIXES_LIB"
+	XDMX_LIBS="$FB_LIB $MI_LIB $XEXT_LIB $RENDER_LIB $RECORD_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $DRI3_LIB $PRESENT_LIB $MIEXT_SYNC_LIB $MIEXT_SHADOW_LIB $MIEXT_DAMAGE_LIB $COMPOSITE_LIB $DAMAGE_LIB $MAIN_LIB $DIX_LIB $RANDR_LIB $CONFIG_LIB $OS_LIB $FIXES_LIB"
 	XDMX_SYS_LIBS="$DMXMODULES_LIBS"
 	AC_SUBST([XDMX_CFLAGS])
 	AC_SUBST([XDMX_LIBS])
commit 634e357be2ec400f63bd5c42f706b709b6ddabc3
Author: Ingo Schwarze <schwarze at usta.de>
Date:   Sun Aug 30 15:26:40 2015 +0200

    remove bogus \/ escapes
    
    some X manuals use then escape sequence \/ when they want to render
    a slash.  That's bad because \/ is not a slash but an italic
    correction, never producing any output, having no effect at all in
    terminal output, and only changing spacing in a minor way in typeset
    output.
    
    Signed-off-by: Matthieu Herrb <matthieu at herrb.eu>
    Reviewed-by: Mark Kettenis <kettenis at openbsd.org>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/man/Xorg.man b/hw/xfree86/man/Xorg.man
index ddf1358..646a90c 100644
--- a/hw/xfree86/man/Xorg.man
+++ b/hw/xfree86/man/Xorg.man
@@ -46,7 +46,7 @@ On most platforms, the "Local" connection type is a UNIX-domain socket.
 On some System V platforms, the "local" connection types also include
 STREAMS pipes, named pipes, and some other mechanisms.
 .TP 4
-.I TCP\/IP
+.I TCP/IP
 .B Xorg
 listens on port
 .RI 6000+ n ,
diff --git a/man/Xserver.man b/man/Xserver.man
index dc4b07e..8a09888 100644
--- a/man/Xserver.man
+++ b/man/Xserver.man
@@ -433,7 +433,7 @@ elapse between autorepeat-generated keystrokes).
 loads keyboard description in \fIfilename\fP on server startup.
 .SH "NETWORK CONNECTIONS"
 The X server supports client connections via a platform-dependent subset of
-the following transport types: TCP\/IP, Unix Domain sockets, DECnet,
+the following transport types: TCP/IP, Unix Domain sockets, DECnet,
 and several varieties of SVR4 local connections.  See the DISPLAY
 NAMES section of the \fIX\fP(__miscmansuffix__) manual page to learn how to
 specify which transport type clients should try to use.
commit c74c074d8e4981eb4509e120e14d15387bdc94ef
Author: Olivier Fourdan <ofourdan at redhat.com>
Date:   Mon Aug 31 08:18:59 2015 +0200

    dix: export ResourceClientBits()
    
    ResourceClientBits() might be used by the modules as well, need to
    mark the symbol as visible to that the linker can resolve it at
    run time.
    
    /usr/bin/X: symbol lookup error:
    /usr/lib64/xorg/modules/extensions/libglx.so: undefined symbol:
    ResourceClientBits
    
    bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=91763
    Signed-off-by: Olivier Fourdan <ofourdan at redhat.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/include/resource.h b/include/resource.h
index 597f7b6..5871a4c 100644
--- a/include/resource.h
+++ b/include/resource.h
@@ -85,7 +85,7 @@ typedef uint32_t RESTYPE;
 #define RT_LASTPREDEF	((RESTYPE)9)
 #define RT_NONE		((RESTYPE)0)
 
-extern unsigned int ResourceClientBits(void);
+extern _X_EXPORT unsigned int ResourceClientBits(void);
 /* bits and fields within a resource id */
 #define RESOURCE_AND_CLIENT_COUNT   29  /* 29 bits for XIDs */
 #define RESOURCE_CLIENT_BITS        ResourceClientBits() /* client field offset */
commit dbfed3a291619c2530f314394bd73d71e2567e78
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Sep 1 19:03:33 2015 -0700

    Bump version to 1.17.99.901 (1.18 RC1)
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index 00aec2b..1f39331 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.17.99.0, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
-RELEASE_DATE="2015-02-02"
-RELEASE_NAME="Côte de veau"
+AC_INIT([xorg-server], 1.17.99.901, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
+RELEASE_DATE="2015-09-01"
+RELEASE_NAME="Nectarine"
 AC_CONFIG_SRCDIR([Makefile.am])
 AC_CONFIG_MACRO_DIR([m4])
 AM_INIT_AUTOMAKE([foreign dist-bzip2])
commit bcb60a49c5e74aa11d0256874659afddea91e53d
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Tue Jul 7 23:11:07 2015 +0100

    debug output format fix in TouchEventHistoryPush()
    
    xserver/build.x86_64/../dix/touch.c:468:16: error: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘size_t’ [-Werror=format=]
    
    %zu is C99, but is already used in a few places.  Perhaps doc/c-extensions needs
    to mention it.
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/touch.c b/dix/touch.c
index 49d16ab..54da132 100644
--- a/dix/touch.c
+++ b/dix/touch.c
@@ -464,7 +464,7 @@ TouchEventHistoryPush(TouchPointInfoPtr ti, const DeviceEvent *ev)
     /* FIXME: proper overflow fixes */
     if (ti->history_elements > ti->history_size - 1) {
         ti->history_elements = ti->history_size - 1;
-        DebugF("source device %d: history size %d overflowing for touch %u\n",
+        DebugF("source device %d: history size %zu overflowing for touch %u\n",
                ti->sourceid, ti->history_size, ti->client_id);
     }
 }
commit 1f96a0d273e56d01cd240e6a4ef8765e0ffe058c
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Fri May 1 17:40:06 2015 +0100

    debug output format fix in ephyrProcessMouseMotion()
    
    xorg/xserver/hw/kdrive/ephyr/ephyr.c:979:9: error: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘ScreenPtr’ [-Werror=format=]
    
    This looks like a genuine bug, and ephyrCursorScreen->myNum was meant here
    rather than ephyrCursorScreen
    
    v2:
    Insert a ":" as well
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index 164ebdc..e6e72d3 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -977,8 +977,8 @@ ephyrProcessMouseMotion(xcb_generic_event_t *xev)
 
     if (ephyrCursorScreen != screen->pScreen) {
         EPHYR_LOG("warping mouse cursor. "
-                  "cur_screen%d, motion_screen:%d\n",
-                  ephyrCursorScreen, screen->pScreen->myNum);
+                  "cur_screen:%d, motion_screen:%d\n",
+                  ephyrCursorScreen->myNum, screen->pScreen->myNum);
         ephyrWarpCursor(inputInfo.pointer, screen->pScreen,
                         motion->event_x, motion->event_y);
     }
commit 8cc88fbe9e4699cd2570641eb2752977b5505d16
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Fri May 1 17:33:35 2015 +0100

    debug output format fix in DRISwapContext()
    
    xorg/xserver/hw/xfree86/dri/dri.c:1695:19: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 4 has type ‘DRIContextPrivPtr’ [-Werror=format=]                   ^
    xorg/xserver/hw/xfree86/dri/dri.c:1695:19: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 5 has type ‘DRIContextPrivPtr’ [-Werror=format=]
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c
index ae92fc2..875c9cc 100644
--- a/hw/xfree86/dri/dri.c
+++ b/hw/xfree86/dri/dri.c
@@ -1691,7 +1691,7 @@ DRISwapContext(int drmFD, void *oldctx, void *newctx)
 
     if (!newContext) {
         DRIDrvMsg(pScreen->myNum, X_ERROR,
-                  "[DRI] Context Switch Error: oldContext=%x, newContext=%x\n",
+                  "[DRI] Context Switch Error: oldContext=%p, newContext=%p\n",
                   oldContext, newContext);
         return;
     }
commit 27cf5840272810ae20fdae550db71ec48cf1b02d
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Tue Jul 7 23:29:51 2015 +0100

    debug output format fix in TI.c
    
    xserver/hw/xfree86/ramdac/TI.c:118:12: error: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long unsigned int’ [-Werror=format=]
    xserver/hw/xfree86/ramdac/TI.c:118:12: error: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘long unsigned int’ [-Werror=format=]
    xserver/hw/xfree86/ramdac/TI.c:118:12: error: format ‘%d’ expects argument of type ‘int’, but argument 6 has type ‘long unsigned int’ [-Werror=format=]
    
    Use %lu for an unsigned long
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/ramdac/TI.c b/hw/xfree86/ramdac/TI.c
index f8081ca..0ae1db5 100644
--- a/hw/xfree86/ramdac/TI.c
+++ b/hw/xfree86/ramdac/TI.c
@@ -114,7 +114,7 @@ TIramdacCalculateMNPForClock(unsigned long RefClock,    /* In 100Hz units */
     VCO = 8.0 * IntRef * best_m / best_n;
     ActualClock = VCO / (1 << p);
 
-    DebugF("f_out=%ld f_vco=%.1f n=%d m=%d p=%d\n",
+    DebugF("f_out=%ld f_vco=%.1f n=%lu m=%lu p=%lu\n",
            ActualClock, VCO, *rN, *rM, *rP);
 
     return ActualClock;
commit 6cc0f3d95d62e33a5d86f865159cc3526d3a9dc5
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Tue Jul 7 23:20:29 2015 +0100

    debug output format fix in xf86Events.c
    
    xserver/hw/xfree86/common/xf86Events.c:183:5: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 3 has type ‘void *’ [-Werror=format=]
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c
index 97a1f97..6570f0b 100644
--- a/hw/xfree86/common/xf86Events.c
+++ b/hw/xfree86/common/xf86Events.c
@@ -180,7 +180,7 @@ ProcessInputEvents(void)
 void
 xf86ProcessActionEvent(ActionEvent action, void *arg)
 {
-    DebugF("ProcessActionEvent(%d,%x)\n", (int) action, arg);
+    DebugF("ProcessActionEvent(%d,%p)\n", (int) action, arg);
     switch (action) {
     case ACTION_TERMINATE:
         if (!xf86Info.dontZap) {
commit d206c240c0b85c4da44f073d6e9a692afb6b96d2
Author: Olivier Fourdan <ofourdan at redhat.com>
Date:   Tue Jul 7 18:19:50 2015 +0200

    configurable maximum number of clients
    
    Make the maximum number of clients user configurable, either from the command
    line or from xorg.conf
    
    This patch works by using the MAXCLIENTS (raised to 512) as the maximum
    allowed number of clients, but allowing the actual limit to be set by the
    user to a lower value (keeping the default of 256).
    
    There is a limit size of 29 bits to be used to store both the client ID and
    the X resources ID, so by reducing the number of clients allowed to connect to
    the X server, the user can increase the number of X resources per client or
    vice-versa.
    
    Parts of this patch are based on a similar patch from Adam Jackson
    <ajax at redhat.com>
    
    This now requires at least xproto 7.0.28
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Olivier Fourdan <ofourdan at redhat.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index 98d0821..00aec2b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -400,7 +400,7 @@ case $host_os in
 	AC_DEFINE(CSRG_BASED, 1, [System is BSD-like])
 	;;
   cygwin*|mingw*)
-	CFLAGS="$CFLAGS -DFD_SETSIZE=256"
+	CFLAGS="$CFLAGS -DFD_SETSIZE=512"
 	;;
 esac
 
@@ -771,7 +771,7 @@ APPLEWMPROTO="applewmproto >= 1.4"
 LIBXSHMFENCE="xshmfence >= 1.1"
 
 dnl Required modules
-XPROTO="xproto >= 7.0.26"
+XPROTO="xproto >= 7.0.28"
 RANDRPROTO="randrproto >= 1.5.0"
 RENDERPROTO="renderproto >= 0.11"
 XEXTPROTO="xextproto >= 7.2.99.901"
diff --git a/dix/colormap.c b/dix/colormap.c
index 89a17c4..12a85b2 100644
--- a/dix/colormap.c
+++ b/dix/colormap.c
@@ -252,7 +252,7 @@ CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
 
     size = pVisual->ColormapEntries;
     sizebytes = (size * sizeof(Entry)) +
-        (MAXCLIENTS * sizeof(Pixel *)) + (MAXCLIENTS * sizeof(int));
+        (LimitClients * sizeof(Pixel *)) + (LimitClients * sizeof(int));
     if ((class | DynamicClass) == DirectColor)
         sizebytes *= 3;
     sizebytes += sizeof(ColormapRec);
@@ -277,7 +277,7 @@ CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
     sizebytes = size * sizeof(Entry);
     pmap->clientPixelsRed = (Pixel **) ((char *) pmap->red + sizebytes);
     pmap->numPixelsRed = (int *) ((char *) pmap->clientPixelsRed +
-                                  (MAXCLIENTS * sizeof(Pixel *)));
+                                  (LimitClients * sizeof(Pixel *)));
     pmap->mid = mid;
     pmap->flags = 0;            /* start out with all flags clear */
     if (mid == pScreen->defColormap)
@@ -289,8 +289,8 @@ CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
         size = NUMRED(pVisual);
     pmap->freeRed = size;
     memset((char *) pmap->red, 0, (int) sizebytes);
-    memset((char *) pmap->numPixelsRed, 0, MAXCLIENTS * sizeof(int));
-    for (pptr = &pmap->clientPixelsRed[MAXCLIENTS];
+    memset((char *) pmap->numPixelsRed, 0, LimitClients * sizeof(int));
+    for (pptr = &pmap->clientPixelsRed[LimitClients];
          --pptr >= pmap->clientPixelsRed;)
         *pptr = (Pixel *) NULL;
     if (alloc == AllocAll) {
@@ -313,26 +313,26 @@ CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
     if ((class | DynamicClass) == DirectColor) {
         pmap->freeGreen = NUMGREEN(pVisual);
         pmap->green = (EntryPtr) ((char *) pmap->numPixelsRed +
-                                  (MAXCLIENTS * sizeof(int)));
+                                  (LimitClients * sizeof(int)));
         pmap->clientPixelsGreen = (Pixel **) ((char *) pmap->green + sizebytes);
         pmap->numPixelsGreen = (int *) ((char *) pmap->clientPixelsGreen +
-                                        (MAXCLIENTS * sizeof(Pixel *)));
+                                        (LimitClients * sizeof(Pixel *)));
         pmap->freeBlue = NUMBLUE(pVisual);
         pmap->blue = (EntryPtr) ((char *) pmap->numPixelsGreen +
-                                 (MAXCLIENTS * sizeof(int)));
+                                 (LimitClients * sizeof(int)));
         pmap->clientPixelsBlue = (Pixel **) ((char *) pmap->blue + sizebytes);
         pmap->numPixelsBlue = (int *) ((char *) pmap->clientPixelsBlue +
-                                       (MAXCLIENTS * sizeof(Pixel *)));
+                                       (LimitClients * sizeof(Pixel *)));
 
         memset((char *) pmap->green, 0, (int) sizebytes);
         memset((char *) pmap->blue, 0, (int) sizebytes);
 
         memmove((char *) pmap->clientPixelsGreen,
-                (char *) pmap->clientPixelsRed, MAXCLIENTS * sizeof(Pixel *));
+                (char *) pmap->clientPixelsRed, LimitClients * sizeof(Pixel *));
         memmove((char *) pmap->clientPixelsBlue,
-                (char *) pmap->clientPixelsRed, MAXCLIENTS * sizeof(Pixel *));
-        memset((char *) pmap->numPixelsGreen, 0, MAXCLIENTS * sizeof(int));
-        memset((char *) pmap->numPixelsBlue, 0, MAXCLIENTS * sizeof(int));
+                (char *) pmap->clientPixelsRed, LimitClients * sizeof(Pixel *));
+        memset((char *) pmap->numPixelsGreen, 0, LimitClients * sizeof(int));
+        memset((char *) pmap->numPixelsBlue, 0, LimitClients * sizeof(int));
 
         /* If every cell is allocated, mark its refcnt */
         if (alloc == AllocAll) {
@@ -416,7 +416,7 @@ FreeColormap(void *value, XID mid)
     (*pmap->pScreen->DestroyColormap) (pmap);
 
     if (pmap->clientPixelsRed) {
-        for (i = 0; i < MAXCLIENTS; i++)
+        for (i = 0; i < LimitClients; i++)
             free(pmap->clientPixelsRed[i]);
     }
 
@@ -434,7 +434,7 @@ FreeColormap(void *value, XID mid)
         }
     }
     if ((pmap->class | DynamicClass) == DirectColor) {
-        for (i = 0; i < MAXCLIENTS; i++) {
+        for (i = 0; i < LimitClients; i++) {
             free(pmap->clientPixelsGreen[i]);
             free(pmap->clientPixelsBlue[i]);
         }
diff --git a/dix/dispatch.c b/dix/dispatch.c
index dbbac8b..2c20124 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -3484,7 +3484,7 @@ NextAvailableClient(void *ospriv)
     xReq data;
 
     i = nextFreeClientID;
-    if (i == MAXCLIENTS)
+    if (i == LimitClients)
         return (ClientPtr) NULL;
     clients[i] = client =
         dixAllocateObjectWithPrivates(ClientRec, PRIVATE_CLIENT);
@@ -3504,7 +3504,7 @@ NextAvailableClient(void *ospriv)
     }
     if (i == currentMaxClients)
         currentMaxClients++;
-    while ((nextFreeClientID < MAXCLIENTS) && clients[nextFreeClientID])
+    while ((nextFreeClientID < LimitClients) && clients[nextFreeClientID])
         nextFreeClientID++;
 
     /* Enable client ID tracking. This must be done before
diff --git a/dix/main.c b/dix/main.c
index db3b9c0..d7a9cda 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -165,7 +165,7 @@ dix_main(int argc, char *argv[], char *envp[])
         OsInit();
         if (serverGeneration == 1) {
             CreateWellKnownSockets();
-            for (i = 1; i < MAXCLIENTS; i++)
+            for (i = 1; i < LimitClients; i++)
                 clients[i] = NullClient;
             serverClient = calloc(sizeof(ClientRec), 1);
             if (!serverClient)
diff --git a/dix/resource.c b/dix/resource.c
index af8e162..ad71b24 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -600,6 +600,29 @@ CreateNewResourceClass(void)
 
 static ClientResourceRec clientTable[MAXCLIENTS];
 
+static unsigned int
+ilog2(int val)
+{
+    int bits;
+
+    if (val <= 0)
+	return 0;
+    for (bits = 0; val != 0; bits++)
+	val >>= 1;
+    return bits - 1;
+}
+
+/*****************
+ * ResourceClientBits
+ *    Returns the client bit offset in the client + resources ID field
+ *****************/
+
+unsigned int
+ResourceClientBits(void)
+{
+    return (ilog2(LimitClients));
+}
+
 /*****************
  * InitClientResources
  *    When a new client is created, call this to allocate space
@@ -883,7 +906,7 @@ FreeResource(XID id, RESTYPE skipDeleteFuncType)
     int *eltptr;
     int elements;
 
-    if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) {
+    if (((cid = CLIENT_ID(id)) < LimitClients) && clientTable[cid].buckets) {
         head = &clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)];
         eltptr = &clientTable[cid].elements;
 
@@ -917,7 +940,7 @@ FreeResourceByType(XID id, RESTYPE type, Bool skipFree)
     ResourcePtr res;
     ResourcePtr *prev, *head;
 
-    if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) {
+    if (((cid = CLIENT_ID(id)) < LimitClients) && clientTable[cid].buckets) {
         head = &clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)];
 
         prev = head;
@@ -952,7 +975,7 @@ ChangeResourceValue(XID id, RESTYPE rtype, void *value)
     int cid;
     ResourcePtr res;
 
-    if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets) {
+    if (((cid = CLIENT_ID(id)) < LimitClients) && clientTable[cid].buckets) {
         res = clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)];
 
         for (; res; res = res->next)
@@ -1190,7 +1213,7 @@ dixLookupResourceByType(void **result, XID id, RESTYPE rtype,
     if ((rtype & TypeMask) > lastResourceType)
         return BadImplementation;
 
-    if ((cid < MAXCLIENTS) && clientTable[cid].buckets) {
+    if ((cid < LimitClients) && clientTable[cid].buckets) {
         res = clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)];
 
         for (; res; res = res->next)
@@ -1223,7 +1246,7 @@ dixLookupResourceByClass(void **result, XID id, RESTYPE rclass,
 
     *result = NULL;
 
-    if ((cid < MAXCLIENTS) && clientTable[cid].buckets) {
+    if ((cid < LimitClients) && clientTable[cid].buckets) {
         res = clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)];
 
         for (; res; res = res->next)
diff --git a/hw/dmx/glxProxy/glxext.c b/hw/dmx/glxProxy/glxext.c
index 3c5a14b..c858272 100644
--- a/hw/dmx/glxProxy/glxext.c
+++ b/hw/dmx/glxProxy/glxext.c
@@ -347,7 +347,7 @@ GlxExtensionInit(void)
     /*
      ** Initialize table of client state.  There is never a client 0.
      */
-    for (i = 1; i <= MAXCLIENTS; i++) {
+    for (i = 1; i <= LimitClients; i++) {
         __glXClients[i] = 0;
     }
 
diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 2b4df0c..d2c3225 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -703,6 +703,7 @@ typedef enum {
     FLAG_DRI2,
     FLAG_USE_SIGIO,
     FLAG_AUTO_ADD_GPU,
+    FLAG_MAX_CLIENTS,
 } FlagValues;
 
 /**
@@ -762,6 +763,8 @@ static OptionInfoRec FlagOptions[] = {
      {0}, FALSE},
     {FLAG_AUTO_ADD_GPU, "AutoAddGPU", OPTV_BOOLEAN,
      {0}, FALSE},
+    {FLAG_MAX_CLIENTS, "MaxClients", OPTV_INTEGER,
+     {0}, FALSE },
     {-1, NULL, OPTV_NONE,
      {0}, FALSE},
 };
@@ -1052,6 +1055,19 @@ configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts)
         xf86Info.dri2From = X_CONFIG;
     }
 #endif
+
+    from = X_DEFAULT;
+    if (LimitClients != LIMITCLIENTS)
+	from = X_CMDLINE;
+    i = -1;
+    if (xf86GetOptValInteger(FlagOptions, FLAG_MAX_CLIENTS, &i)) {
+	if (i != 64 && i != 128 && i != 256 && i != 512)
+		ErrorF("MaxClients must be one of 64, 128, 256 or 512\n");
+	from = X_CONFIG;
+	LimitClients = i;
+    }
+    xf86Msg(from, "Max clients allowed: %i, resource mask: 0x%x\n",
+	    LimitClients, RESOURCE_ID_MASK);
 }
 
 Bool
diff --git a/hw/xfree86/man/xorg.conf.man b/hw/xfree86/man/xorg.conf.man
index e9b6d99..08eb7a9 100644
--- a/hw/xfree86/man/xorg.conf.man
+++ b/hw/xfree86/man/xorg.conf.man
@@ -621,6 +621,10 @@ It is only enabled for screens that have the
 .B \*qDPMS\*q
 option set (see the MONITOR section below).
 .TP 7
+.BI "Option \*qMaxClients\*q  \*q" integer \*q
+Set the maximum number of clients allowed to connect to the X server.
+Acceptable values are 64, 128, 256 or 512.
+.TP 7
 .BI "Option \*qPixmap\*q  \*q" bpp \*q
 This sets the pixmap format to use for depth 24.
 Allowed values for
diff --git a/include/misc.h b/include/misc.h
index 9b1c03a..56e138c 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -86,7 +86,8 @@ OF THIS SOFTWARE.
 #ifndef MAXGPUSCREENS
 #define MAXGPUSCREENS	16
 #endif
-#define MAXCLIENTS	256
+#define MAXCLIENTS	512
+#define LIMITCLIENTS	256     /* Must be a power of 2 and <= MAXCLIENTS */
 #define MAXEXTENSIONS   128
 #define MAXFORMATS	8
 #define MAXDEVICES	40      /* input devices */
diff --git a/include/opaque.h b/include/opaque.h
index a2c54aa..0ba0d64 100644
--- a/include/opaque.h
+++ b/include/opaque.h
@@ -36,6 +36,7 @@ from The Open Group.
 extern _X_EXPORT const char *defaultTextFont;
 extern _X_EXPORT const char *defaultCursorFont;
 extern _X_EXPORT int MaxClients;
+extern _X_EXPORT int LimitClients;
 extern _X_EXPORT volatile char isItTimeToYield;
 extern _X_EXPORT volatile char dispatchException;
 
diff --git a/include/resource.h b/include/resource.h
index 772f363..597f7b6 100644
--- a/include/resource.h
+++ b/include/resource.h
@@ -85,21 +85,10 @@ typedef uint32_t RESTYPE;
 #define RT_LASTPREDEF	((RESTYPE)9)
 #define RT_NONE		((RESTYPE)0)
 
+extern unsigned int ResourceClientBits(void);
 /* bits and fields within a resource id */
 #define RESOURCE_AND_CLIENT_COUNT   29  /* 29 bits for XIDs */
-#if MAXCLIENTS == 64
-#define RESOURCE_CLIENT_BITS	6
-#endif
-#if MAXCLIENTS == 128
-#define RESOURCE_CLIENT_BITS	7
-#endif
-#if MAXCLIENTS == 256
-#define RESOURCE_CLIENT_BITS	8
-#endif
-#if MAXCLIENTS == 512
-#define RESOURCE_CLIENT_BITS	9
-#endif
-/* client field offset */
+#define RESOURCE_CLIENT_BITS        ResourceClientBits() /* client field offset */
 #define CLIENTOFFSET	    (RESOURCE_AND_CLIENT_COUNT - RESOURCE_CLIENT_BITS)
 /* resource field */
 #define RESOURCE_ID_MASK	((1 << CLIENTOFFSET) - 1)
diff --git a/man/Xserver.man b/man/Xserver.man
index ac410cd..dc4b07e 100644
--- a/man/Xserver.man
+++ b/man/Xserver.man
@@ -320,6 +320,11 @@ sets the stack space limit of the server to the specified number of kilobytes.
 A value of zero makes the stack size as large as possible.  The default value
 of \-1 leaves the stack space limit unchanged.
 .TP 8
+.B \-maxclients
+.BR 64 | 128 | 256 | 512
+Set the maximum number of clients allowed to connect to the X server.
+Acceptable values are 64, 128, 256 or 512.
+.TP 8
 .B \-render
 .BR default | mono | gray | color
 sets the color allocation policy that will be used by the render extension.
diff --git a/os/connection.c b/os/connection.c
index c36b125..3d33c41 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -161,9 +161,9 @@ int *ConnectionTranslation = NULL;
  */
 
 #undef MAXSOCKS
-#define MAXSOCKS 500
+#define MAXSOCKS 512
 #undef MAXSELECT
-#define MAXSELECT 500
+#define MAXSELECT 512
 
 struct _ct_node {
     struct _ct_node *next;
@@ -299,7 +299,7 @@ InitConnectionLimits(void)
     if (lastfdesc > MAXCLIENTS) {
         lastfdesc = MAXCLIENTS;
         if (debug_conns)
-            ErrorF("REACHED MAXIMUM CLIENTS LIMIT %d\n", MAXCLIENTS);
+            ErrorF("REACHED MAXIMUM CLIENTS LIMIT %d\n", LimitClients);
     }
     MaxClients = lastfdesc;
 
diff --git a/os/osdep.h b/os/osdep.h
index 77a5b53..86263a5 100644
--- a/os/osdep.h
+++ b/os/osdep.h
@@ -65,7 +65,7 @@ SOFTWARE.
 
 #ifndef OPEN_MAX
 #ifdef SVR4
-#define OPEN_MAX 256
+#define OPEN_MAX 512
 #else
 #include <sys/param.h>
 #ifndef OPEN_MAX
@@ -75,7 +75,7 @@ SOFTWARE.
 #if !defined(WIN32)
 #define OPEN_MAX NOFILES_MAX
 #else
-#define OPEN_MAX 256
+#define OPEN_MAX 512
 #endif
 #endif
 #endif
@@ -89,10 +89,10 @@ SOFTWARE.
  * like sysconf(_SC_OPEN_MAX) is not supported.
  */
 
-#if OPEN_MAX <= 256
+#if OPEN_MAX <= 512
 #define MAXSOCKS (OPEN_MAX - 1)
 #else
-#define MAXSOCKS 256
+#define MAXSOCKS 512
 #endif
 
 /* MAXSELECT is the number of fds that select() can handle */
diff --git a/os/osinit.c b/os/osinit.c
index 91e3e06..ddd3fce 100644
--- a/os/osinit.c
+++ b/os/osinit.c
@@ -86,6 +86,9 @@ int limitStackSpace = -1;
 int limitNoFile = -1;
 #endif
 
+/* The actual user defined max number of clients */
+int LimitClients = LIMITCLIENTS;
+
 static OsSigWrapperPtr OsSigWrapper = NULL;
 
 OsSigWrapperPtr
diff --git a/os/utils.c b/os/utils.c
index d09ca79..868eb04 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -557,6 +557,7 @@ UseMsg(void)
 #ifdef LOCK_SERVER
     ErrorF("-nolock                disable the locking mechanism\n");
 #endif
+    ErrorF("-maxclients n          set maximum number of clients (power of two)\n");
     ErrorF("-nolisten string       don't listen on protocol\n");
     ErrorF("-listen string         listen on protocol\n");
     ErrorF("-noreset               don't reset after last client exists\n");
@@ -861,6 +862,19 @@ ProcessCommandLine(int argc, char *argv[])
                 nolock = TRUE;
         }
 #endif
+	else if ( strcmp( argv[i], "-maxclients") == 0)
+	{
+	    if (++i < argc) {
+		LimitClients = atoi(argv[i]);
+		if (LimitClients != 64 &&
+		    LimitClients != 128 &&
+		    LimitClients != 256 &&
+		    LimitClients != 512) {
+		    FatalError("maxclients must be one of 64, 128, 256 or 512\n");
+		}
+	    } else
+		UseMsg();
+	}
         else if (strcmp(argv[i], "-nolisten") == 0) {
             if (++i < argc) {
                 if (_XSERVTransNoListen(argv[i]))
commit 7ecdfbf0af3547295b245efa754123db65cabb43
Merge: bca4f4b a0b4f30
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Aug 17 18:53:25 2015 -0700

    Merge remote-tracking branch 'airlied/modesetting-zaphod'

commit bca4f4b56c7619d17f9df46f7aac392ea01a9429
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Aug 17 18:37:10 2015 -0700

    mi: Always initialize edge1 and edge2 in miLineArc
    
    This eliminates a warning generated when miLineArcD is inlined and the
    compiler can't figure out that edge1 and edge2 are always initialized
    before being used.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/mi/miwideline.c b/mi/miwideline.c
index 3baa99b..54de1d3 100644
--- a/mi/miwideline.c
+++ b/mi/miwideline.c
@@ -1454,7 +1454,7 @@ miLineArc(DrawablePtr pDraw,
     int xorgi = 0, yorgi = 0;
     Spans spanRec;
     int n;
-    PolyEdgeRec edge1, edge2;
+    PolyEdgeRec edge1 = { 0 }, edge2 = { 0 };
     int edgey1, edgey2;
     Bool edgeleft1, edgeleft2;
 
commit 5daf1295cb4f71510da595721d10f7ea3b74d1b9
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Aug 17 18:35:20 2015 -0700

    dixfont.h: Include fontutil.h before GetGlyphs is #defined
    
    This eliminates the duplicate declaration of dixGetGlyphs when
    fontutil.h gets included after dixfont.h has defined GetGlyphs as
    dixGetGlyphs.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/include/dixfont.h b/include/dixfont.h
index 1895509..b44996f 100644
--- a/include/dixfont.h
+++ b/include/dixfont.h
@@ -29,6 +29,7 @@ SOFTWARE.
 #include "closure.h"
 #include <X11/fonts/fontstruct.h>
 #include <X11/fonts/fontproto.h>
+#include <X11/fonts/fontutil.h>
 
 #define NullDIXFontProp ((DIXFontPropPtr)0)
 
commit d4710004367ab8eab794a12385ca7ed3acc9a0e0
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Aug 13 09:25:37 2015 +1000

    rootless: rename w->_w to avoid shadow warnings
    
    fixes:
    In file included from rootlessWindow.c:51:0:
    rootlessWindow.c: In function 'RootlessResizeWindow':
    rootlessCommon.h:198:19: warning: declaration of 'w' shadows a parameter [-Wshadow]
             WindowPtr w = pWin;                     \
                       ^
    rootlessWindow.c:1292:9: note: in expansion of macro 'HUGE_ROOT'
             HUGE_ROOT(pWin);
             ^
    rootlessWindow.c:1262:35: note: shadowed declaration is here
                          unsigned int w, unsigned int h, WindowPtr pSib)
                                       ^
    In file included from rootlessWindow.c:51:0:
    rootlessCommon.h:207:19: warning: declaration of 'w' shadows a parameter [-Wshadow]
             WindowPtr w = pWin;                     \
                       ^
    rootlessWindow.c:1296:9: note: in expansion of macro 'NORMAL_ROOT'
             NORMAL_ROOT(pWin);
             ^
    rootlessWindow.c:1262:35: note: shadowed declaration is here
                          unsigned int w, unsigned int h, WindowPtr pSib)
                                       ^
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/miext/rootless/rootlessCommon.h b/miext/rootless/rootlessCommon.h
index 7c26111..c3fa2a2 100644
--- a/miext/rootless/rootlessCommon.h
+++ b/miext/rootless/rootlessCommon.h
@@ -195,19 +195,19 @@ extern RegionRec rootlessHugeRoot;
 
 #define HUGE_ROOT(pWin)                         \
     do {                                        \
-        WindowPtr w = pWin;                     \
-        while (w->parent)                       \
-            w = w->parent;                      \
-        saveRoot = w->winSize;                  \
-        w->winSize = rootlessHugeRoot;          \
+        WindowPtr _w = pWin;                     \
+        while (_w->parent)                       \
+            _w = _w->parent;                      \
+        saveRoot = _w->winSize;                  \
+        _w->winSize = rootlessHugeRoot;          \
     } while (0)
 
 #define NORMAL_ROOT(pWin)                       \
     do {                                        \
-        WindowPtr w = pWin;                     \
-        while (w->parent)                       \
-            w = w->parent;                      \
-        w->winSize = saveRoot;                  \
+        WindowPtr _w = pWin;                     \
+        while (_w->parent)                       \
+            _w = _w->parent;                      \
+        _w->winSize = saveRoot;                  \
     } while (0)
 
 // Returns TRUE if this window is a top-level window (i.e. child of the root)
commit 7f506b8099d23c2f045ad26cc5cff00109b69d7b
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Aug 13 09:25:36 2015 +1000

    rootless: fix warnings due to lack of const keeping.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/miext/rootless/rootlessCommon.h b/miext/rootless/rootlessCommon.h
index aa55579..7c26111 100644
--- a/miext/rootless/rootlessCommon.h
+++ b/miext/rootless/rootlessCommon.h
@@ -70,8 +70,8 @@ extern DevPrivateKeyRec rootlessWindowOldPixmapPrivateKeyRec;
 
 // RootlessGCRec: private per-gc data
 typedef struct {
-    GCFuncs *originalFuncs;
-    GCOps *originalOps;
+    const GCFuncs *originalFuncs;
+    const GCOps *originalOps;
 } RootlessGCRec;
 
 // RootlessScreenRec: per-screen private data
diff --git a/miext/rootless/rootlessGC.c b/miext/rootless/rootlessGC.c
index 4fba26c..235b3ab 100644
--- a/miext/rootless/rootlessGC.c
+++ b/miext/rootless/rootlessGC.c
@@ -403,7 +403,7 @@ RootlessCopyClip(GCPtr pgcDst, GCPtr pgcSrc)
 #define GCOP_UNWRAP(pGC) \
     RootlessGCRec *gcrec = (RootlessGCRec *) \
         dixLookupPrivate(&(pGC)->devPrivates, rootlessGCPrivateKey); \
-    GCFuncs *saveFuncs = pGC->funcs; \
+    const GCFuncs *saveFuncs = pGC->funcs; \
     (pGC)->funcs = gcrec->originalFuncs; \
     (pGC)->ops = gcrec->originalOps;
 
commit b923443816320d0636d6fd40c3c1125b93332907
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Aug 13 09:25:35 2015 +1000

    mioverlay.c: remove shadowed pScreen.
    
    This is already defined at the function entry.
    
    fixes warning:
      CC       mivaltree.lo
    mioverlay.c: In function 'miOverlayWindowExposures':
    mioverlay.c:993:23: warning: declaration of 'pScreen' shadows a previous local [-Wshadow]
                 ScreenPtr pScreen = pWin->drawable.pScreen;
                           ^
    mioverlay.c:986:15: note: shadowed declaration is here
         ScreenPtr pScreen = pWin->drawable.pScreen;
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/mi/mioverlay.c b/mi/mioverlay.c
index 9f3ef07..b8b7a5b 100644
--- a/mi/mioverlay.c
+++ b/mi/mioverlay.c
@@ -990,7 +990,6 @@ miOverlayWindowExposures(WindowPtr pWin, RegionPtr prgn)
         int clientInterested =
             (pWin->eventMask | wOtherEventMasks(pWin)) & ExposureMask;
         if (clientInterested && (RegionNumRects(prgn) > RECTLIMIT)) {
-            ScreenPtr pScreen = pWin->drawable.pScreen;
             miOverlayScreenPtr pPriv = MIOVERLAY_GET_SCREEN_PRIVATE(pScreen);
             BoxRec box;
 
commit a0b4f30b1f584d2957c9c99e430da5740d2d4ab2
Author: Mario Kleiner <mario.kleiner.de at gmail.com>
Date:   Wed Aug 5 00:08:40 2015 +0200

    modesetting: Add more missing options to man page.
    
    Descriptions for Options PageFlip and SWCursor.
    
    Signed-off-by: Mario Kleiner <mario.kleiner.de at gmail.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/modesetting.man b/hw/xfree86/drivers/modesetting/modesetting.man
index e13a4e2..a42da1c 100644
--- a/hw/xfree86/drivers/modesetting/modesetting.man
+++ b/hw/xfree86/drivers/modesetting/modesetting.man
@@ -41,6 +41,10 @@ The following driver
 .B Options
 are supported:
 .TP
+.BI "Option \*qSWcursor\*q \*q" boolean \*q
+Selects software cursor.  The default is
+.B off.
+.TP
 .BI "Option \*qkmsdev\*q \*q" string \*q
 The framebuffer device to use. Default: /dev/dri/card0.
 .TP
@@ -50,6 +54,10 @@ Enable or disable use of the shadow framebuffer layer.  Default: on.
 .BI "Option \*qAccelMethod\*q \*q" string \*q
 One of \*qglamor\*q or \*qnone\*q.  Default: glamor
 .TP
+.BI "Option \*qPageFlip\*q \*q" boolean \*q
+Enable DRI3 page flipping.  The default is
+.B on.
+.TP
 .BI "Option \*qZaphodHeads\*q \*q" string \*q
 Specify the RandR output(s) to use with zaphod mode for a particular driver
 instance.  If you use this option you must use this option for all instances
commit 19e1dc8f6ea6d7ff5ba4a5caa0e2f40a47879408
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Jul 22 03:56:13 2015 +0100

    modesetting: add zaphod support (v3)
    
    This adds zaphod and ZaphodHeads support
    to the the in-server modesetting driver.
    
    this is based on a request from Mario,
    and on the current radeon driver, along
    with some patches from Mario to bring things
    up to the state of the art in Zaphod.
    
    v2: fixup vblank fd registring.
    v3: squash Mario's fixes.
      modesetting: Allow/Fix use of multiple ZaphodHead outputs per x-screen.
      modesetting: Take shift in crtc positions for ZaphodHeads configs into account.
      modesetting: Add ZaphodHeads description to man page.
    small cleanups (airlied).
    
    Reviewed-and-tested-by: Mario Kleiner <mario.kleiner.de at gmail.com>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 324b8bd..80abcdf 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -118,24 +118,17 @@ static SymTabRec Chipsets[] = {
     {-1, NULL}
 };
 
-typedef enum {
-    OPTION_SW_CURSOR,
-    OPTION_DEVICE_PATH,
-    OPTION_SHADOW_FB,
-    OPTION_ACCEL_METHOD,
-    OPTION_PAGEFLIP,
-} modesettingOpts;
-
 static const OptionInfoRec Options[] = {
     {OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE},
     {OPTION_DEVICE_PATH, "kmsdev", OPTV_STRING, {0}, FALSE},
     {OPTION_SHADOW_FB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE},
     {OPTION_ACCEL_METHOD, "AccelMethod", OPTV_STRING, {0}, FALSE},
     {OPTION_PAGEFLIP, "PageFlip", OPTV_BOOLEAN, {0}, FALSE},
+    {OPTION_ZAPHOD_HEADS, "ZaphodHeads", OPTV_STRING, {0}, FALSE},
     {-1, NULL, OPTV_NONE, {0}, FALSE}
 };
 
-int modesettingEntityIndex = -1;
+int ms_entity_index = -1;
 
 static MODULESETUPPROTO(Setup);
 
@@ -187,6 +180,15 @@ Identify(int flags)
                       Chipsets);
 }
 
+modesettingEntPtr ms_ent_priv(ScrnInfoPtr scrn)
+{
+    DevUnion     *pPriv;
+    modesettingPtr ms = modesettingPTR(scrn);
+    pPriv = xf86GetEntityPrivate(ms->pEnt->index,
+                                 ms_entity_index);
+    return pPriv->ptr;
+}
+
 static int
 open_hw(const char *dev)
 {
@@ -374,12 +376,40 @@ ms_platform_probe(DriverPtr driver,
 
     if (probe_hw(path, dev)) {
         scrn = xf86AllocateScreen(driver, scr_flags);
+        if (xf86IsEntitySharable(entity_num))
+            xf86SetEntityShared(entity_num);
         xf86AddEntityToScreen(scrn, entity_num);
 
         ms_setup_scrn_hooks(scrn);
 
         xf86DrvMsg(scrn->scrnIndex, X_INFO,
                    "using drv %s\n", path ? path : "default device");
+
+        {
+            DevUnion *pPriv;
+            EntityInfoPtr pEnt;
+            modesettingEntPtr pMSEnt;
+
+            xf86SetEntitySharable(entity_num);
+
+            if (ms_entity_index == -1)
+                ms_entity_index = xf86AllocateEntityPrivateIndex();
+
+            pEnt = xf86GetEntityInfo(entity_num);
+            pPriv = xf86GetEntityPrivate(pEnt->index,
+                                         ms_entity_index);
+
+            xf86SetEntityInstanceForScreen(scrn, pEnt->index, xf86GetNumEntityInstances(pEnt->index) - 1);
+
+            if (!pPriv->ptr) {
+                pPriv->ptr = xnfcalloc(sizeof(modesettingEntRec), 1);
+                pMSEnt = pPriv->ptr;
+            } else {
+                pMSEnt = pPriv->ptr;
+            }
+            pMSEnt->platform_dev = dev;
+        }
+
     }
 
     return scrn != NULL;
@@ -596,19 +626,25 @@ FreeRec(ScrnInfoPtr pScrn)
     pScrn->driverPrivate = NULL;
 
     if (ms->fd > 0) {
+        modesettingEntPtr ms_ent;
         int ret;
 
-        if (ms->pEnt->location.type == BUS_PCI)
-            ret = drmClose(ms->fd);
-        else
+        ms_ent = ms_ent_priv(pScrn);
+        ms_ent->fd_ref--;
+        if (!ms_ent->fd_ref) {
+            if (ms->pEnt->location.type == BUS_PCI)
+                ret = drmClose(ms->fd);
+            else
 #ifdef XF86_PDEV_SERVER_FD
-        if (!(ms->pEnt->location.type == BUS_PLATFORM &&
-                  (ms->pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD)))
+                if (!(ms->pEnt->location.type == BUS_PLATFORM &&
+                      (ms->pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD)))
 #endif
-            ret = close(ms->fd);
-        (void) ret;
+                    ret = close(ms->fd);
+            (void) ret;
+            ms_ent->fd = 0;
+        }
     }
-    free(ms->Options);
+    free(ms->drmmode.Options);
     free(ms);
 
 }
@@ -617,7 +653,7 @@ static void
 try_enable_glamor(ScrnInfoPtr pScrn)
 {
     modesettingPtr ms = modesettingPTR(pScrn);
-    const char *accel_method_str = xf86GetOptValString(ms->Options,
+    const char *accel_method_str = xf86GetOptValString(ms->drmmode.Options,
                                                        OPTION_ACCEL_METHOD);
     Bool do_glamor = (!accel_method_str ||
                       strcmp(accel_method_str, "glamor") == 0);
@@ -659,60 +695,26 @@ try_enable_glamor(ScrnInfoPtr pScrn)
 #endif
 
 static Bool
-PreInit(ScrnInfoPtr pScrn, int flags)
+ms_get_drm_master_fd(ScrnInfoPtr pScrn)
 {
-    modesettingPtr ms;
-    rgb defaultWeight = { 0, 0, 0 };
     EntityInfoPtr pEnt;
-    EntPtr msEnt = NULL;
+    modesettingPtr ms;
+    modesettingEntPtr ms_ent;
     char *BusID = NULL;
-    const char *devicename;
-    uint64_t value = 0;
-    int ret;
-    int bppflags;
-    int defaultdepth, defaultbpp;
-
-    if (pScrn->numEntities != 1)
-        return FALSE;
-
-    pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
-
-    if (flags & PROBE_DETECT) {
-        return FALSE;
-    }
-
-    /* Allocate driverPrivate */
-    if (!GetRec(pScrn))
-        return FALSE;
 
     ms = modesettingPTR(pScrn);
-    ms->SaveGeneration = -1;
-    ms->pEnt = pEnt;
-
-    pScrn->displayWidth = 640;  /* default it */
+    ms_ent = ms_ent_priv(pScrn);
 
-    /* Allocate an entity private if necessary */
-    if (xf86IsEntityShared(pScrn->entityList[0])) {
-        msEnt = xf86GetEntityPrivate(pScrn->entityList[0],
-                                     modesettingEntityIndex)->ptr;
-        ms->entityPrivate = msEnt;
-    }
-    else
-        ms->entityPrivate = NULL;
+    pEnt = ms->pEnt;
 
-    if (xf86IsEntityShared(pScrn->entityList[0])) {
-        if (xf86IsPrimInitDone(pScrn->entityList[0])) {
-            /* do something */
-        }
-        else {
-            xf86SetPrimInitDone(pScrn->entityList[0]);
-        }
+    if (ms_ent->fd) {
+        xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+                   " reusing fd for second head\n");
+        ms->fd = ms_ent->fd;
+        ms_ent->fd_ref++;
+        return TRUE;
     }
 
-    pScrn->monitor = pScrn->confScreen->monitor;
-    pScrn->progClock = TRUE;
-    pScrn->rgbBits = 8;
-
 #if XSERVER_PLATFORM_BUS
     if (pEnt->location.type == BUS_PLATFORM) {
 #ifdef XF86_PDEV_SERVER_FD
@@ -749,12 +751,61 @@ PreInit(ScrnInfoPtr pScrn, int flags)
         ms->fd = drmOpen(NULL, BusID);
     }
     else {
+        const char *devicename;
         devicename = xf86FindOptionValue(ms->pEnt->device->options, "kmsdev");
         ms->fd = open_hw(devicename);
     }
     if (ms->fd < 0)
         return FALSE;
 
+    ms_ent->fd = ms->fd;
+    ms_ent->fd_ref = 1;
+    return TRUE;
+}
+
+static Bool
+PreInit(ScrnInfoPtr pScrn, int flags)
+{
+    modesettingPtr ms;
+    rgb defaultWeight = { 0, 0, 0 };
+    EntityInfoPtr pEnt;
+    uint64_t value = 0;
+    int ret;
+    int bppflags;
+    int defaultdepth, defaultbpp;
+
+    if (pScrn->numEntities != 1)
+        return FALSE;
+
+    pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
+
+    if (flags & PROBE_DETECT) {
+        return FALSE;
+    }
+
+    /* Allocate driverPrivate */
+    if (!GetRec(pScrn))
+        return FALSE;
+
+    ms = modesettingPTR(pScrn);
+    ms->SaveGeneration = -1;
+    ms->pEnt = pEnt;
+    ms->drmmode.is_secondary = FALSE;
+    pScrn->displayWidth = 640;  /* default it */
+
+    if (xf86IsEntityShared(pScrn->entityList[0])) {
+        if (xf86IsPrimInitDone(pScrn->entityList[0]))
+            ms->drmmode.is_secondary = TRUE;
+        else
+            xf86SetPrimInitDone(pScrn->entityList[0]);
+    }
+
+    pScrn->monitor = pScrn->confScreen->monitor;
+    pScrn->progClock = TRUE;
+    pScrn->rgbBits = 8;
+
+    if (!ms_get_drm_master_fd(pScrn))
+        return FALSE;
     ms->drmmode.fd = ms->fd;
 
     pScrn->capabilities = 0;
@@ -794,17 +845,17 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 
     /* Process the options */
     xf86CollectOptions(pScrn, NULL);
-    if (!(ms->Options = malloc(sizeof(Options))))
+    if (!(ms->drmmode.Options = malloc(sizeof(Options))))
         return FALSE;
-    memcpy(ms->Options, Options, sizeof(Options));
-    xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->Options);
+    memcpy(ms->drmmode.Options, Options, sizeof(Options));
+    xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->drmmode.Options);
 
     if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight))
         return FALSE;
     if (!xf86SetDefaultVisual(pScrn, -1))
         return FALSE;
 
-    if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) {
+    if (xf86ReturnOptValBool(ms->drmmode.Options, OPTION_SW_CURSOR, FALSE)) {
         ms->drmmode.sw_cursor = TRUE;
     }
 
@@ -823,7 +874,7 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 
     if (ms->drmmode.glamor) {
         ms->drmmode.pageflip =
-            xf86ReturnOptValBool(ms->Options, OPTION_PAGEFLIP, TRUE);
+            xf86ReturnOptValBool(ms->drmmode.Options, OPTION_PAGEFLIP, TRUE);
     } else {
         Bool prefer_shadow = TRUE;
 
@@ -832,7 +883,7 @@ PreInit(ScrnInfoPtr pScrn, int flags)
             prefer_shadow = !!value;
         }
 
-        ms->drmmode.shadow_enable = xf86ReturnOptValBool(ms->Options,
+        ms->drmmode.shadow_enable = xf86ReturnOptValBool(ms->drmmode.Options,
                                                          OPTION_SHADOW_FB,
                                                          prefer_shadow);
 
@@ -1277,6 +1328,10 @@ CloseScreen(ScreenPtr pScreen)
 {
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     modesettingPtr ms = modesettingPTR(pScrn);
+    modesettingEntPtr ms_ent = ms_ent_priv(pScrn);
+
+    /* Clear mask of assigned crtc's in this generation */
+    ms_ent->assigned_crtcs = 0;
 
 #ifdef GLAMOR
     if (ms->drmmode.glamor) {
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index 9ae4966..14137c1 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -43,13 +43,28 @@
 
 #include "drmmode_display.h"
 #define DRV_ERROR(msg)	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, msg);
-
-typedef struct {
-    int lastInstance;
-    int refCount;
-    ScrnInfoPtr pScrn_1;
-    ScrnInfoPtr pScrn_2;
-} EntRec, *EntPtr;
+#define MS_LOGLEVEL_DEBUG 4
+
+typedef enum {
+    OPTION_SW_CURSOR,
+    OPTION_DEVICE_PATH,
+    OPTION_SHADOW_FB,
+    OPTION_ACCEL_METHOD,
+    OPTION_PAGEFLIP,
+    OPTION_ZAPHOD_HEADS,
+} modesettingOpts;
+
+typedef struct
+{
+    int fd;
+    int fd_ref;
+    unsigned long fd_wakeup_registered; /* server generation for which fd has been registered for wakeup handling */
+    int fd_wakeup_ref;
+    unsigned int assigned_crtcs;
+#ifdef XSERVER_PLATFORM_BUS
+    struct xf86_platform_device *platform_dev;
+#endif
+} modesettingEntRec, *modesettingEntPtr;
 
 typedef void (*ms_drm_handler_proc)(uint64_t frame,
                                     uint64_t usec,
@@ -74,8 +89,6 @@ struct ms_drm_queue {
 typedef struct _modesettingRec {
     int fd;
 
-    EntPtr entityPrivate;
-
     int Chipset;
     EntityInfoPtr pEnt;
 #if XSERVER_LIBPCIACCESS
@@ -88,9 +101,6 @@ typedef struct _modesettingRec {
     Bool noAccel;
     CloseScreenProcPtr CloseScreen;
 
-    /* Broken-out options. */
-    OptionInfoPtr Options;
-
     unsigned int SaveGeneration;
 
     CreateScreenResourcesProcPtr createScreenResources;
@@ -114,6 +124,7 @@ typedef struct _modesettingRec {
 } modesettingRec, *modesettingPtr;
 
 #define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate))
+modesettingEntPtr ms_ent_priv(ScrnInfoPtr scrn);
 
 uint32_t ms_drm_queue_alloc(xf86CrtcPtr crtc,
                             void *data,
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 6a13660..4d8892f 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -52,6 +52,39 @@
 
 static Bool drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height);
 
+static Bool
+drmmode_zaphod_string_matches(ScrnInfoPtr scrn, const char *s, char *output_name)
+{
+    int i = 0;
+    char s1[20];
+
+    do {
+        switch(*s) {
+        case ',':
+            s1[i] = '\0';
+            i = 0;
+            if (strcmp(s1, output_name) == 0)
+                return TRUE;
+            break;
+        case ' ':
+        case '\t':
+        case '\n':
+        case '\r':
+            break;
+        default:
+            s1[i] = *s;
+            i++;
+            break;
+        }
+    } while(*s++);
+
+    s1[i] = '\0';
+    if (strcmp(s1, output_name) == 0)
+        return TRUE;
+
+    return FALSE;
+}
+
 int
 drmmode_bo_destroy(drmmode_ptr drmmode, drmmode_bo *bo)
 {
@@ -788,15 +821,16 @@ drmmode_crtc_vblank_pipe(int crtc_id)
         return 0;
 }
 
-static void
+static unsigned int
 drmmode_crtc_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, drmModeResPtr mode_res, int num)
 {
     xf86CrtcPtr crtc;
     drmmode_crtc_private_ptr drmmode_crtc;
+    modesettingEntPtr ms_ent = ms_ent_priv(pScrn);
 
     crtc = xf86CrtcCreate(pScrn, &drmmode_crtc_funcs);
     if (crtc == NULL)
-        return;
+        return 0;
 
     drmmode_crtc = xnfcalloc(sizeof(drmmode_crtc_private_rec), 1);
     drmmode_crtc->mode_crtc =
@@ -804,6 +838,13 @@ drmmode_crtc_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, drmModeResPtr mode_res
     drmmode_crtc->drmmode = drmmode;
     drmmode_crtc->vblank_pipe = drmmode_crtc_vblank_pipe(num);
     crtc->driver_private = drmmode_crtc;
+
+    /* Mark num'th crtc as in use on this device. */
+    ms_ent->assigned_crtcs |= (1 << num);
+    xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, MS_LOGLEVEL_DEBUG,
+                   "Allocated crtc nr. %d to this screen.\n", num);
+
+    return 1;
 }
 
 static xf86OutputStatus
@@ -1345,8 +1386,8 @@ drmmode_create_name(ScrnInfoPtr pScrn, drmModeConnectorPtr koutput, char *name,
         snprintf(name, 32, "%s-%d", output_names[koutput->connector_type], koutput->connector_type_id - 1);
 }
 
-static void
-drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, drmModeResPtr mode_res, int num, Bool dynamic)
+static unsigned int
+drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, drmModeResPtr mode_res, int num, Bool dynamic, int crtcshift)
 {
     xf86OutputPtr output;
     xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
@@ -1357,11 +1398,11 @@ drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, drmModeResPtr mode_r
     char name[32];
     int i;
     drmModePropertyBlobPtr path_blob = NULL;
-
+    const char *s;
     koutput =
         drmModeGetConnector(drmmode->fd, mode_res->connectors[num]);
     if (!koutput)
-        return;
+        return 0;
 
     for (i = 0; i < koutput->count_props; i++) {
         props = drmModeGetProperty(drmmode->fd, koutput->props[i]);
@@ -1392,7 +1433,7 @@ drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, drmModeResPtr mode_r
             drmmode_output = output->driver_private;
             drmmode_output->output_id = mode_res->connectors[num];
             drmmode_output->mode_output = koutput;
-            return;
+            return 1;
         }
     }
 
@@ -1408,6 +1449,18 @@ drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, drmModeResPtr mode_r
         }
     }
 
+    if (xf86IsEntityShared(pScrn->entityList[0])) {
+        if ((s = xf86GetOptValString(drmmode->Options, OPTION_ZAPHOD_HEADS))) {
+            if (!drmmode_zaphod_string_matches(pScrn, s, name))
+                goto out_free_encoders;
+        } else {
+            if (!drmmode->is_secondary && (num != 0))
+                goto out_free_encoders;
+            else if (drmmode->is_secondary && (num != 1))
+                goto out_free_encoders;
+        }
+    }
+
     output = xf86OutputCreate(pScrn, &drmmode_output_funcs, name);
     if (!output) {
         goto out_free_encoders;
@@ -1433,7 +1486,7 @@ drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, drmModeResPtr mode_r
 
     output->possible_crtcs = 0x7f;
     for (i = 0; i < koutput->count_encoders; i++) {
-        output->possible_crtcs &= kencoders[i]->possible_crtcs;
+        output->possible_crtcs &= kencoders[i]->possible_crtcs >> crtcshift;
     }
     /* work out the possible clones later */
     output->possible_clones = 0;
@@ -1452,7 +1505,8 @@ drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, drmModeResPtr mode_r
 
     if (dynamic)
         output->randr_output = RROutputCreate(xf86ScrnToScreen(pScrn), output->name, strlen(output->name), output);
-    return;
+    return 1;
+
  out_free_encoders:
     if (kencoders) {
         for (i = 0; i < koutput->count_encoders; i++)
@@ -1461,6 +1515,7 @@ drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, drmModeResPtr mode_r
     }
     drmModeFreeConnector(koutput);
 
+    return 0;
 }
 
 static uint32_t
@@ -1682,10 +1737,13 @@ static const xf86CrtcConfigFuncsRec drmmode_xf86crtc_config_funcs = {
 Bool
 drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp)
 {
+    modesettingEntPtr ms_ent = ms_ent_priv(pScrn);
     int i;
     int ret;
     uint64_t value = 0;
+    unsigned int crtcs_needed = 0;
     drmModeResPtr mode_res;
+    int crtcshift;
 
     /* check for dumb capability */
     ret = drmGetCap(drmmode->fd, DRM_CAP_DUMB_BUFFER, &value);
@@ -1703,15 +1761,26 @@ drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp)
     if (!mode_res)
         return FALSE;
 
+    crtcshift = ffs(ms_ent->assigned_crtcs ^ 0xffffffff) - 1;
+    for (i = 0; i < mode_res->count_connectors; i++)
+        crtcs_needed += drmmode_output_init(pScrn, drmmode, mode_res, i, FALSE,
+                                            crtcshift);
+
+    xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, MS_LOGLEVEL_DEBUG,
+                   "Up to %d crtcs needed for screen.\n", crtcs_needed);
+
     xf86CrtcSetSizeRange(pScrn, 320, 200, mode_res->max_width,
                          mode_res->max_height);
     for (i = 0; i < mode_res->count_crtcs; i++)
         if (!xf86IsEntityShared(pScrn->entityList[0]) ||
-            pScrn->confScreen->device->screen == i)
-            drmmode_crtc_init(pScrn, drmmode, mode_res, i);
+            (crtcs_needed && !(ms_ent->assigned_crtcs & (1 << i))))
+            crtcs_needed -= drmmode_crtc_init(pScrn, drmmode, mode_res, i);
 
-    for (i = 0; i < mode_res->count_connectors; i++)
-        drmmode_output_init(pScrn, drmmode, mode_res, i, FALSE);
+    /* All ZaphodHeads outputs provided with matching crtcs? */
+    if (xf86IsEntityShared(pScrn->entityList[0]) && (crtcs_needed > 0))
+        xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
+                   "%d ZaphodHeads crtcs unavailable. Some outputs will stay off.\n",
+                   crtcs_needed);
 
     /* workout clones */
     drmmode_clones_init(pScrn, drmmode, mode_res);
@@ -1941,7 +2010,7 @@ drmmode_handle_uevents(int fd, void *closure)
             continue;
 
         changed = TRUE;
-        drmmode_output_init(scrn, drmmode, mode_res, i, 1);
+        drmmode_output_init(scrn, drmmode, mode_res, i, TRUE, 0);
     }
 
     if (changed) {
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index fe363c5..fca68a6 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -60,6 +60,9 @@ typedef struct {
     drmmode_bo front_bo;
     Bool sw_cursor;
 
+    /* Broken-out options. */
+    OptionInfoPtr Options;
+
     Bool glamor;
     Bool shadow_enable;
     /** Is Option "PageFlip" enabled? */
@@ -82,6 +85,8 @@ typedef struct {
     DevPrivateKeyRec pixmapPrivateKeyRec;
 
     Bool reverse_prime_offload_mode;
+
+    Bool is_secondary;
 } drmmode_rec, *drmmode_ptr;
 
 typedef struct {
diff --git a/hw/xfree86/drivers/modesetting/modesetting.man b/hw/xfree86/drivers/modesetting/modesetting.man
index 9cb27d7..e13a4e2 100644
--- a/hw/xfree86/drivers/modesetting/modesetting.man
+++ b/hw/xfree86/drivers/modesetting/modesetting.man
@@ -50,6 +50,16 @@ Enable or disable use of the shadow framebuffer layer.  Default: on.
 .BI "Option \*qAccelMethod\*q \*q" string \*q
 One of \*qglamor\*q or \*qnone\*q.  Default: glamor
 .TP
+.BI "Option \*qZaphodHeads\*q \*q" string \*q
+Specify the RandR output(s) to use with zaphod mode for a particular driver
+instance.  If you use this option you must use this option for all instances
+of the driver.
+.br
+For example:
+.B
+Option \*qZaphodHeads\*q \*qLVDS,VGA-0\*q
+will assign xrandr outputs LVDS and VGA-0 to this instance of the driver.
+.TP
 .SH "SEE ALSO"
 __xservername__(__appmansuffix__), __xconfigfile__(__filemansuffix__), Xserver(__appmansuffix__),
 X(__miscmansuffix__)
diff --git a/hw/xfree86/drivers/modesetting/vblank.c b/hw/xfree86/drivers/modesetting/vblank.c
index 0b7bf9d..77e0848 100644
--- a/hw/xfree86/drivers/modesetting/vblank.c
+++ b/hw/xfree86/drivers/modesetting/vblank.c
@@ -381,7 +381,7 @@ ms_vblank_screen_init(ScreenPtr screen)
 {
     ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
     modesettingPtr ms = modesettingPTR(scrn);
-
+    modesettingEntPtr ms_ent = ms_ent_priv(scrn);
     xorg_list_init(&ms_drm_queue);
 
     ms->event_context.version = DRM_EVENT_CONTEXT_VERSION;
@@ -392,9 +392,14 @@ ms_vblank_screen_init(ScreenPtr screen)
      * feedback on every server generation, so perform the
      * registration within ScreenInit and not PreInit.
      */
-    AddGeneralSocket(ms->fd);
-    RegisterBlockAndWakeupHandlers((BlockHandlerProcPtr)NoopDDA,
-                                   ms_drm_wakeup_handler, screen);
+    if (ms_ent->fd_wakeup_registered != serverGeneration) {
+        AddGeneralSocket(ms->fd);
+        RegisterBlockAndWakeupHandlers((BlockHandlerProcPtr)NoopDDA,
+                                       ms_drm_wakeup_handler, screen);
+        ms_ent->fd_wakeup_registered = serverGeneration;
+        ms_ent->fd_wakeup_ref = 1;
+    } else
+        ms_ent->fd_wakeup_ref++;
 
     return TRUE;
 }
@@ -404,10 +409,14 @@ ms_vblank_close_screen(ScreenPtr screen)
 {
     ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
     modesettingPtr ms = modesettingPTR(scrn);
+    modesettingEntPtr ms_ent = ms_ent_priv(scrn);
 
     ms_drm_abort_scrn(scrn);
 
-    RemoveBlockAndWakeupHandlers((BlockHandlerProcPtr)NoopDDA,
-                                 ms_drm_wakeup_handler, screen);
-    RemoveGeneralSocket(ms->fd);
+    if (ms_ent->fd_wakeup_registered == serverGeneration &&
+        !--ms_ent->fd_wakeup_ref) {
+        RemoveBlockAndWakeupHandlers((BlockHandlerProcPtr)NoopDDA,
+                                     ms_drm_wakeup_handler, screen);
+        RemoveGeneralSocket(ms->fd);
+    }
 }
commit 533fb627398e20f863234d780f4463e37007515b
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Aug 4 13:17:02 2015 -0400

    xwayland: Don't (double) destroy input resources in CloseScreen
    
    By the time we get here we've already done CloseDownDevices, so on the
    second regeneration you get:
    
        Invalid read of size 4
           at 0x43402A: RemoveDevice (devices.c:1125)
           by 0x427902: xwl_seat_destroy (xwayland-input.c:568)
           by 0x42649C: xwl_close_screen (xwayland.c:116)
           by 0x4B7F67: CursorCloseScreen (cursor.c:187)
           by 0x536003: AnimCurCloseScreen (animcur.c:106)
           by 0x539831: present_close_screen (present_screen.c:64)
           by 0x43E486: dix_main (main.c:351)
           by 0x30D70206FF: (below main) (libc-start.c:289)
         Address 0x980e1a0 is 64 bytes inside a block of size 904
    
           at 0x4A07D6A: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
           by 0x434158: RemoveDevice (devices.c:1157)
           by 0x42F77B: CloseDeviceList (devices.c:1017)
           by 0x430246: CloseDownDevices (devices.c:1047)
           by 0x43E3EB: dix_main (main.c:333)
           by 0x30D70206FF: (below main) (libc-start.c:289)
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Daniel Stone <daniels at collabora.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xwayland/xwayland-input.c b/hw/xwayland/xwayland-input.c
index a6fbab5..a961e30 100644
--- a/hw/xwayland/xwayland-input.c
+++ b/hw/xwayland/xwayland-input.c
@@ -559,8 +559,6 @@ create_input_device(struct xwl_screen *xwl_screen, uint32_t id)
 void
 xwl_seat_destroy(struct xwl_seat *xwl_seat)
 {
-    RemoveDevice(xwl_seat->pointer, FALSE);
-    RemoveDevice(xwl_seat->keyboard, FALSE);
     wl_seat_destroy(xwl_seat->seat);
     wl_surface_destroy(xwl_seat->cursor);
     if (xwl_seat->cursor_frame_cb)
commit 11f4cc47a815c5d6284b1338e748e2605b2dd779
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Aug 4 13:17:01 2015 -0400

    xwayland: Don't (double) destroy RANDR resources in CloseScreen
    
    By the time we get here we've already been through FreeAllResources,
    which has already torn down the RANDR objects, so on the second
    regeneration you get:
    
        Invalid read of size 4
           at 0x51C6F0: RRCrtcDestroy (rrcrtc.c:659)
           by 0x4285F5: xwl_output_destroy (xwayland-output.c:191)
           by 0x426464: xwl_close_screen (xwayland.c:112)
           by 0x4B7F77: CursorCloseScreen (cursor.c:187)
           by 0x536013: AnimCurCloseScreen (animcur.c:106)
           by 0x539841: present_close_screen (present_screen.c:64)
           by 0x43E496: dix_main (main.c:351)
           by 0x30D70206FF: (below main) (libc-start.c:289)
         Address 0x4cc6640 is 0 bytes inside a block of size 728 free'd
           at 0x4A07D6A: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
           by 0x51BCCF: RRCrtcDestroyResource (rrcrtc.c:689)
           by 0x45CD91: doFreeResource (resource.c:872)
           by 0x45DE56: FreeClientResources (resource.c:1138)
           by 0x45DF06: FreeAllResources (resource.c:1153)
           by 0x43E3BD: dix_main (main.c:321)
           by 0x30D70206FF: (below main) (libc-start.c:289)
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Daniel Stone <daniels at collabora.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xwayland/xwayland-output.c b/hw/xwayland/xwayland-output.c
index 155cbc1..7e5484c 100644
--- a/hw/xwayland/xwayland-output.c
+++ b/hw/xwayland/xwayland-output.c
@@ -188,8 +188,6 @@ void
 xwl_output_destroy(struct xwl_output *xwl_output)
 {
     wl_output_destroy(xwl_output->output);
-    RRCrtcDestroy(xwl_output->randr_crtc);
-    RROutputDestroy(xwl_output->randr_output);
     free(xwl_output);
 }
 
commit ea03e314f98e5d8ed7bf7a508006a3d84014bde5
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Jul 27 13:54:00 2015 -0700

    glamor: Don't try to free the pixmap priv if we fail to allocate FBO.
    
    Fixes a regression since a2a2f6e34bd49e7ae31779274d52e800595660bc.  I
    missed this in testing on x86, because we never fail to allocate an
    FBO.  We do hit this path on VC4, though.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/glamor/glamor.c b/glamor/glamor.c
index 439906a..d4a0236 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -194,7 +194,6 @@ glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth,
 
     if (fbo == NULL) {
         fbDestroyPixmap(pixmap);
-        free(pixmap_priv);
         return fbCreatePixmap(screen, w, h, depth, usage);
     }
 
commit 6916d32ab3ec1aa922094abce7fac22884ee4e83
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sun Jul 19 08:24:39 2015 -0700

    Xserver.man: -retro is used when starting the server, not the stipple
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/man/Xserver.man b/man/Xserver.man
index 3bf844f..ac410cd 100644
--- a/man/Xserver.man
+++ b/man/Xserver.man
@@ -238,7 +238,7 @@ turns off auto-repeat.
 turns on auto-repeat.
 .TP 8
 .B -retro
-starts the stipple with the classic stipple and cursor visible.  The default
+starts the server with the classic stipple and cursor visible.  The default
 is to start with a black root window, and to suppress display of the cursor
 until the first time an application calls XDefineCursor(). For kdrive
 servers, this implies -zap.
commit 0a458a908ec071a4da5d22c760581e0c5ec885ce
Author: Michel Dänzer <michel.daenzer at amd.com>
Date:   Wed Jul 22 15:37:23 2015 +0900

    glamor: Make our EGL context current before calling into GL in glamor_init
    
    Without this, the context of another screen may be current, or no context
    at all if glamor_egl_init failed for another screen.
    
    Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>

diff --git a/glamor/glamor.c b/glamor/glamor.c
index 6dcc259..439906a 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -457,6 +457,20 @@ glamor_init(ScreenPtr screen, unsigned int flags)
         goto fail;
     }
 
+    glamor_priv->saved_procs.close_screen = screen->CloseScreen;
+    screen->CloseScreen = glamor_close_screen;
+
+    /* If we are using egl screen, call egl screen init to
+     * register correct close screen function. */
+    if (flags & GLAMOR_USE_EGL_SCREEN) {
+        glamor_egl_screen_init(screen, &glamor_priv->ctx);
+    } else {
+        if (!glamor_glx_screen_init(&glamor_priv->ctx))
+            goto fail;
+    }
+
+    glamor_make_current(glamor_priv);
+
     if (epoxy_is_desktop_gl())
         glamor_priv->gl_flavor = GLAMOR_GL_DESKTOP;
     else
@@ -579,18 +593,6 @@ glamor_init(ScreenPtr screen, unsigned int flags)
 
     glamor_set_debug_level(&glamor_debug_level);
 
-    glamor_priv->saved_procs.close_screen = screen->CloseScreen;
-    screen->CloseScreen = glamor_close_screen;
-
-    /* If we are using egl screen, call egl screen init to
-     * register correct close screen function. */
-    if (flags & GLAMOR_USE_EGL_SCREEN) {
-        glamor_egl_screen_init(screen, &glamor_priv->ctx);
-    } else {
-        if (!glamor_glx_screen_init(&glamor_priv->ctx))
-            goto fail;
-    }
-
     glamor_priv->saved_procs.create_screen_resources =
         screen->CreateScreenResources;
     screen->CreateScreenResources = glamor_create_screen_resources;
commit a8a0f6464a33c12c1de495d74fd478c0d952643e
Author: Aaron Plattner <aplattner at nvidia.com>
Date:   Thu Jul 16 15:12:52 2015 -0700

    xfree86: Bump video driver ABI version to 20
    
    Commit 90db5edf119187f8b1b9207c8c384d6cd7ef9edc modified the signature of
    StartPixmapTrackingProcPtr, so drivers implementing that need to use the updated
    definition.
    
    Signed-off-by: Aaron Plattner <aplattner at nvidia.com>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/hw/xfree86/common/xf86Module.h b/hw/xfree86/common/xf86Module.h
index 66c2bb5..9e5dc6d 100644
--- a/hw/xfree86/common/xf86Module.h
+++ b/hw/xfree86/common/xf86Module.h
@@ -80,7 +80,7 @@ typedef enum {
  * mask is 0xFFFF0000.
  */
 #define ABI_ANSIC_VERSION	SET_ABI_VERSION(0, 4)
-#define ABI_VIDEODRV_VERSION	SET_ABI_VERSION(19, 0)
+#define ABI_VIDEODRV_VERSION	SET_ABI_VERSION(20, 0)
 #define ABI_XINPUT_VERSION	SET_ABI_VERSION(22, 1)
 #define ABI_EXTENSION_VERSION	SET_ABI_VERSION(9, 0)
 #define ABI_FONT_VERSION	SET_ABI_VERSION(0, 6)
commit 2fcfa532532fbe4a7f668556808e6245ff4e36bc
Merge: cb695b0 7b0f940
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Jul 17 10:15:01 2015 -0700

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

commit cb695b0f3b8def4d1ac02458fe630b65f6a5a3e6
Author: Armin K <krejzi at email.com>
Date:   Thu Jul 16 14:54:48 2015 +0200

    xfree86/os-support/linux: Fix make distcheck
    
    Header was added in 1dba5a0b194653b0effb01a918bd7338b0c6bcb9
    but not in Makefile.am, resulting in missing header in the
    distribution tarball.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/hw/xfree86/os-support/linux/Makefile.am b/hw/xfree86/os-support/linux/Makefile.am
index 50fcd1f..d8cb177 100644
--- a/hw/xfree86/os-support/linux/Makefile.am
+++ b/hw/xfree86/os-support/linux/Makefile.am
@@ -23,7 +23,7 @@ LOGIND_SRCS = systemd-logind.c
 XORG_CFLAGS += $(DBUS_CFLAGS)
 endif
 
-liblinux_la_SOURCES = lnx_init.c lnx_video.c \
+liblinux_la_SOURCES = linux.h lnx_init.c lnx_video.c \
                      lnx_agp.c lnx_kmod.c lnx_bell.c lnx_platform.c \
 		     $(srcdir)/../shared/VTsw_usl.c \
 		     $(srcdir)/../shared/posix_tty.c \
commit 29efa905ec1e22d66b517378c6e5ad47a09d6977
Author: Robert Ancell <robert.ancell at canonical.com>
Date:   Thu Jul 16 12:26:05 2015 +1200

    modesetting: Use correct types for return values of glamor BO exports.
    
    glamor_name_from_pixmap and glamor_fd_from_pixmap return CARD16 and
    CARD32 values via pointers.  The current code uses uint16_t and
    uint32_t which will probably be the same but it's safer to use the
    datatypes as specified by the function.
    
    Signed-off-by: Robert Ancell <robert.ancell at canonical.com>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/hw/xfree86/drivers/modesetting/dri2.c b/hw/xfree86/drivers/modesetting/dri2.c
index 63cb065..0fe420c 100644
--- a/hw/xfree86/drivers/modesetting/dri2.c
+++ b/hw/xfree86/drivers/modesetting/dri2.c
@@ -138,8 +138,8 @@ ms_dri2_create_buffer(DrawablePtr drawable, unsigned int attachment,
     ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
     DRI2Buffer2Ptr buffer;
     PixmapPtr pixmap;
-    uint32_t size;
-    uint16_t pitch;
+    CARD32 size;
+    CARD16 pitch;
     ms_dri2_buffer_private_ptr private;
 
     buffer = calloc(1, sizeof *buffer);
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index ef5b087..6a13660 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -148,8 +148,8 @@ drmmode_bo_for_pixmap(drmmode_ptr drmmode, drmmode_bo *bo, PixmapPtr pixmap)
 {
 #ifdef GLAMOR
     ScreenPtr screen = xf86ScrnToScreen(drmmode->scrn);
-    uint16_t pitch;
-    uint32_t size;
+    CARD16 pitch;
+    CARD32 size;
     int fd;
 
 #ifdef GLAMOR_HAS_GBM
commit db5337afb248edf81087cf8d74006fc496d70589
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Jul 15 17:56:11 2015 +1000

    glamor: make current in prepare paths
    
    Lots of the accel paths only make current once they start
    doing someting, so a lot of them call the bail paths without
    make current, which means on PRIME systems for example
    we end up in the wrong context.
    
    Add a prepare pixmap in the prepare fallback path.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=90667
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-and-Tested-by: Michel Dänzer <michel.daenzer at amd.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>

diff --git a/glamor/glamor_prepare.c b/glamor/glamor_prepare.c
index 833291c..5a73e6c 100644
--- a/glamor/glamor_prepare.c
+++ b/glamor/glamor_prepare.c
@@ -45,6 +45,8 @@ glamor_prep_pixmap_box(PixmapPtr pixmap, glamor_access_t access, BoxPtr box)
     if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(priv))
         return TRUE;
 
+    glamor_make_current(glamor_priv);
+
     RegionInit(&region, box, 1);
 
     /* See if it's already mapped */
commit 1a18513a4eb3fa22459dd9f7d8f0e275aff679ec
Author: Michel Dänzer <michel.daenzer at amd.com>
Date:   Fri Jul 10 15:28:52 2015 +0900

    glamor: Use glamor_prepare_access_box() for PutImage/GetImage fallback
    
    Fixes slow text display in xdvi.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=91260
    Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>

diff --git a/glamor/glamor_image.c b/glamor/glamor_image.c
index a272d5e..3158749 100644
--- a/glamor/glamor_image.c
+++ b/glamor/glamor_image.c
@@ -88,7 +88,7 @@ static void
 glamor_put_image_bail(DrawablePtr drawable, GCPtr gc, int depth, int x, int y,
                       int w, int h, int leftPad, int format, char *bits)
 {
-    if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW))
+    if (glamor_prepare_access_box(drawable, GLAMOR_ACCESS_RW, x, y, w, h))
         fbPutImage(drawable, gc, depth, x, y, w, h, leftPad, format, bits);
     glamor_finish_access(drawable);
 }
@@ -137,7 +137,7 @@ static void
 glamor_get_image_bail(DrawablePtr drawable, int x, int y, int w, int h,
                       unsigned int format, unsigned long plane_mask, char *d)
 {
-    if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RO))
+    if (glamor_prepare_access_box(drawable, GLAMOR_ACCESS_RO, x, y, w, h))
         fbGetImage(drawable, x, y, w, h, format, plane_mask, d);
     glamor_finish_access(drawable);
 }
commit fde13565c1b2462ee38f2a446ad3c9157261afa2
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jul 2 13:57:05 2015 -0700

    glamor: Drop unused box translation/bounds code.
    
    These are dead since the glamor_copy.c replacement.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/glamor/glamor_utils.h b/glamor/glamor_utils.h
index 8a96c61..e648af2 100644
--- a/glamor/glamor_utils.h
+++ b/glamor/glamor_utils.h
@@ -697,45 +697,6 @@
         (c)[1] = (float)y;				\
     } while(0)
 
-inline static void
-glamor_calculate_boxes_bound(BoxPtr bound, BoxPtr boxes, int nbox)
-{
-    int x_min, y_min;
-    int x_max, y_max;
-    int i;
-
-    x_min = y_min = MAXSHORT;
-    x_max = y_max = MINSHORT;
-    for (i = 0; i < nbox; i++) {
-        if (x_min > boxes[i].x1)
-            x_min = boxes[i].x1;
-        if (y_min > boxes[i].y1)
-            y_min = boxes[i].y1;
-
-        if (x_max < boxes[i].x2)
-            x_max = boxes[i].x2;
-        if (y_max < boxes[i].y2)
-            y_max = boxes[i].y2;
-    }
-    bound->x1 = x_min;
-    bound->y1 = y_min;
-    bound->x2 = x_max;
-    bound->y2 = y_max;
-}
-
-inline static void
-glamor_translate_boxes(BoxPtr boxes, int nbox, int dx, int dy)
-{
-    int i;
-
-    for (i = 0; i < nbox; i++) {
-        boxes[i].x1 += dx;
-        boxes[i].y1 += dy;
-        boxes[i].x2 += dx;
-        boxes[i].y2 += dy;
-    }
-}
-
 #ifndef ARRAY_SIZE
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
 #endif
commit ab5aa270c79d70f095bc7abadeef227b4062027c
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jul 2 13:52:05 2015 -0700

    glamor: Move cache_format to glamor_fbo.c, where it's used.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/glamor/glamor_fbo.c b/glamor/glamor_fbo.c
index 1eee304..262033f 100644
--- a/glamor/glamor_fbo.c
+++ b/glamor/glamor_fbo.c
@@ -70,6 +70,21 @@ cache_hbucket(int size)
     return order;
 }
 
+static int
+cache_format(GLenum format)
+{
+    switch (format) {
+    case GL_ALPHA:
+        return 2;
+    case GL_RGB:
+        return 1;
+    case GL_RGBA:
+        return 0;
+    default:
+        return -1;
+    }
+}
+
 static glamor_pixmap_fbo *
 glamor_pixmap_fbo_cache_get(glamor_screen_private *glamor_priv,
                             int w, int h, GLenum format)
diff --git a/glamor/glamor_utils.h b/glamor/glamor_utils.h
index e22bbc1..8a96c61 100644
--- a/glamor/glamor_utils.h
+++ b/glamor/glamor_utils.h
@@ -824,21 +824,6 @@ format_for_pixmap(PixmapPtr pixmap)
 #define SWAP_UPLOADING	  	2
 #define SWAP_NONE_UPLOADING	3
 
-inline static int
-cache_format(GLenum format)
-{
-    switch (format) {
-    case GL_ALPHA:
-        return 2;
-    case GL_RGB:
-        return 1;
-    case GL_RGBA:
-        return 0;
-    default:
-        return -1;
-    }
-}
-
 /* borrowed from uxa */
 static inline Bool
 glamor_get_rgba_from_pixel(CARD32 pixel,
commit 0ca783e8ee5dfb086fbfa64d26173bcca78b4010
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jul 2 13:50:42 2015 -0700

    glamor: Drop another dead function.
    
    This hasn't been used since the format swap/revert stuff for pictures
    was added back in 2012.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/glamor/glamor_utils.h b/glamor/glamor_utils.h
index 59e6b64..e22bbc1 100644
--- a/glamor/glamor_utils.h
+++ b/glamor/glamor_utils.h
@@ -936,13 +936,6 @@ glamor_is_large_pixmap(PixmapPtr pixmap)
     return (glamor_pixmap_priv_is_large(priv));
 }
 
-inline static Bool
-glamor_tex_format_is_readable(GLenum format)
-{
-    return ((format == GL_RGBA || format == GL_RGB || format == GL_ALPHA));
-
-}
-
 static inline void
 _glamor_dump_pixmap_bits(PixmapPtr pixmap, int x, int y, int w, int h)
 {
commit c1111710628cc2a9dfaee0d74ea9fceee990095b
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jul 2 13:33:01 2015 -0700

    glamor: Take transforms into account when preparing for a fallback.
    
    This function takes the start x/y and the destination's width/height,
    so it only works if there's no transform.  We could potentially
    transform this box and take its bounds with some rounding, but this at
    least gets us to read out enough data.
    
    Note that this does the same overshoot on destination pictures with a
    transform attached, but that seems unlikely to be used anyway.
    
    v2: Add XXX comment for the commit message note (Suggested by Michel).
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com> (v1)
    Reviewed-by: Dave Airlie <airlied at redhat.com> (v1)

diff --git a/glamor/glamor_prepare.c b/glamor/glamor_prepare.c
index 9bfc557..833291c 100644
--- a/glamor/glamor_prepare.c
+++ b/glamor/glamor_prepare.c
@@ -220,8 +220,22 @@ glamor_prepare_access_picture_box(PicturePtr picture, glamor_access_t access,
 {
     if (!picture || !picture->pDrawable)
         return TRUE;
-    return glamor_prepare_access_box(picture->pDrawable, access,
-                                    x, y, w, h);
+
+    /* If a transform is set, we don't know what the bounds is on the
+     * source, so just prepare the whole pixmap.  XXX: We could
+     * potentially work out where in the source would be sampled based
+     * on the transform, and we don't need do do this for destination
+     * pixmaps at all.
+     */
+    if (picture->transform) {
+        return glamor_prepare_access_box(picture->pDrawable, access,
+                                         0, 0,
+                                         picture->pDrawable->width,
+                                         picture->pDrawable->height);
+    } else {
+        return glamor_prepare_access_box(picture->pDrawable, access,
+                                         x, y, w, h);
+    }
 }
 
 void
commit c16e086dace81151f399485e5c686617a43d5b94
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jul 2 13:25:40 2015 -0700

    glamor: Drop dead drm_stride field.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index 5989dc4..f3950f1 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -350,7 +350,6 @@ typedef struct glamor_pixmap_private {
     glamor_pixmap_fbo *fbo;
     /** current fbo's coords in the whole pixmap. */
     BoxRec box;
-    int drm_stride;
     GLuint pbo;
     RegionRec prepare_region;
     Bool prepared;
commit 8097c887023b72744cb2cb943c2deca7ca0c404a
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jul 2 13:11:20 2015 -0700

    glamor: Drop tracking of the last picture attached to pixmaps.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Acked-by: Michel Dänzer <michel.daenzer at amd.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/glamor/glamor.c b/glamor/glamor.c
index 04c548d..6dcc259 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -649,15 +649,6 @@ glamor_init(ScreenPtr screen, unsigned int flags)
     glamor_priv->saved_procs.glyphs = ps->Glyphs;
     ps->Glyphs = glamor_composite_glyphs;
 
-    glamor_priv->saved_procs.create_picture = ps->CreatePicture;
-    ps->CreatePicture = glamor_create_picture;
-
-    glamor_priv->saved_procs.destroy_picture = ps->DestroyPicture;
-    ps->DestroyPicture = glamor_destroy_picture;
-
-    glamor_priv->saved_procs.set_window_pixmap = screen->SetWindowPixmap;
-    screen->SetWindowPixmap = glamor_set_window_pixmap;
-
     glamor_init_vbo(screen);
     glamor_init_pixmap_fbo(screen);
     glamor_init_finish_access_shaders(screen);
@@ -719,10 +710,8 @@ glamor_close_screen(ScreenPtr screen)
     ps->Composite = glamor_priv->saved_procs.composite;
     ps->Trapezoids = glamor_priv->saved_procs.trapezoids;
     ps->Triangles = glamor_priv->saved_procs.triangles;
-    ps->CreatePicture = glamor_priv->saved_procs.create_picture;
     ps->CompositeRects = glamor_priv->saved_procs.composite_rects;
     ps->Glyphs = glamor_priv->saved_procs.glyphs;
-    screen->SetWindowPixmap = glamor_priv->saved_procs.set_window_pixmap;
 
     screen_pixmap = screen->GetScreenPixmap(screen);
     glamor_pixmap_destroy_fbo(screen_pixmap);
diff --git a/glamor/glamor_picture.c b/glamor/glamor_picture.c
index c36d9d6..691f179 100644
--- a/glamor/glamor_picture.c
+++ b/glamor/glamor_picture.c
@@ -900,51 +900,3 @@ glamor_upload_picture_to_texture(PicturePtr picture)
     else
         return GLAMOR_UPLOAD_FAILED;
 }
-
-/*
- * We should already have drawable attached to it, if it has one.
- * Then set the attached pixmap to is_picture format, and set
- * the pict format.
- * */
-int
-glamor_create_picture(PicturePtr picture)
-{
-    PixmapPtr pixmap;
-    glamor_pixmap_private *pixmap_priv;
-
-    if (!picture || !picture->pDrawable)
-        return 0;
-
-    pixmap = glamor_get_drawable_pixmap(picture->pDrawable);
-    pixmap_priv = glamor_get_pixmap_private(pixmap);
-    pixmap_priv->is_picture = 1;
-    pixmap_priv->picture = picture;
-
-    return miCreatePicture(picture);
-}
-
-void
-glamor_destroy_picture(PicturePtr picture)
-{
-    PixmapPtr pixmap;
-    glamor_pixmap_private *pixmap_priv;
-
-    if (!picture || !picture->pDrawable)
-        return;
-
-    pixmap = glamor_get_drawable_pixmap(picture->pDrawable);
-    pixmap_priv = glamor_get_pixmap_private(pixmap);
-
-    if (pixmap_priv) {
-        pixmap_priv->is_picture = 0;
-        pixmap_priv->picture = NULL;
-    }
-    miDestroyPicture(picture);
-}
-
-void
-glamor_picture_format_fixup(PicturePtr picture,
-                            glamor_pixmap_private *pixmap_priv)
-{
-    pixmap_priv->picture = picture;
-}
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index 2792afa..5989dc4 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -173,9 +173,6 @@ struct glamor_saved_procs {
     BitmapToRegionProcPtr bitmap_to_region;
     TrianglesProcPtr triangles;
     AddTrapsProcPtr addtraps;
-    CreatePictureProcPtr create_picture;
-    DestroyPictureProcPtr destroy_picture;
-    SetWindowPixmapProcPtr set_window_pixmap;
 #if XSYNC
     SyncScreenFuncsRec sync_screen_funcs;
 #endif
@@ -350,13 +347,10 @@ typedef struct glamor_pixmap_private {
      * that data on glamor_finish_access().
      */
     glamor_access_t map_access;
-    /** Set if the pixmap is currenty attached to a Picture. */
-    unsigned char is_picture:1;
     glamor_pixmap_fbo *fbo;
     /** current fbo's coords in the whole pixmap. */
     BoxRec box;
     int drm_stride;
-    PicturePtr picture;
     GLuint pbo;
     RegionRec prepare_region;
     Bool prepared;
@@ -734,15 +728,6 @@ Bool glamor_composite_largepixmap_region(CARD8 op,
  **/
 enum glamor_pixmap_status glamor_upload_picture_to_texture(PicturePtr picture);
 
-int glamor_create_picture(PicturePtr picture);
-
-void glamor_set_window_pixmap(WindowPtr pWindow, PixmapPtr pPixmap);
-
-void glamor_destroy_picture(PicturePtr picture);
-
-void glamor_picture_format_fixup(PicturePtr picture,
-                                 glamor_pixmap_private *pixmap_priv);
-
 void glamor_add_traps(PicturePtr pPicture,
                       INT16 x_off, INT16 y_off, int ntrap, xTrap *traps);
 
diff --git a/glamor/glamor_render.c b/glamor/glamor_render.c
index 3048cd8..c3a8f17 100644
--- a/glamor/glamor_render.c
+++ b/glamor/glamor_render.c
@@ -936,9 +936,6 @@ glamor_composite_choose_shader(CARD8 op,
                 goto fail;
             }
 
-            if (source->format != saved_source_format) {
-                glamor_picture_format_fixup(source, source_pixmap_priv);
-            }
             /* XXX
              * By default, glamor_upload_picture_to_texture will wire alpha to 1
              * if one picture doesn't have alpha. So we don't do that again in
diff --git a/glamor/glamor_utils.h b/glamor/glamor_utils.h
index 8182006..59e6b64 100644
--- a/glamor/glamor_utils.h
+++ b/glamor/glamor_utils.h
@@ -33,6 +33,7 @@
 #define __GLAMOR_UTILS_H__
 
 #include "glamor_prepare.h"
+#include "mipict.h"
 
 #define v_from_x_coord_x(_xscale_, _x_)          ( 2 * (_x_) * (_xscale_) - 1.0)
 #define v_from_x_coord_y(_yscale_, _y_)          (-2 * (_y_) * (_yscale_) + 1.0)
@@ -756,7 +757,6 @@ glamor_translate_boxes(BoxPtr boxes, int nbox, int dx, int dy)
 						|| _depth_ == 30	\
 						|| _depth_ == 32)
 
-#define GLAMOR_PIXMAP_PRIV_IS_PICTURE(pixmap_priv) (pixmap_priv->is_picture == 1)
 #define GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv)    (pixmap_priv->gl_fbo == GLAMOR_FBO_NORMAL)
 
 /**
@@ -1287,9 +1287,9 @@ glamor_compare_pictures(ScreenPtr screen,
 
     if (fst_pixmap->drawable.depth != snd_pixmap->drawable.depth) {
         if (fst_generated)
-            glamor_destroy_picture(fst_picture);
+            miDestroyPicture(fst_picture);
         if (snd_generated)
-            glamor_destroy_picture(snd_picture);
+            miDestroyPicture(snd_picture);
 
         ErrorF("Different pixmap depth can not compare!\n");
         return;
@@ -1315,9 +1315,9 @@ glamor_compare_pictures(ScreenPtr screen,
     glamor_finish_access(&snd_pixmap->drawable);
 
     if (fst_generated)
-        glamor_destroy_picture(fst_picture);
+        miDestroyPicture(fst_picture);
     if (snd_generated)
-        glamor_destroy_picture(snd_picture);
+        miDestroyPicture(snd_picture);
 
     return;
 }
diff --git a/glamor/glamor_window.c b/glamor/glamor_window.c
index a39e723..5fd463b 100644
--- a/glamor/glamor_window.c
+++ b/glamor/glamor_window.c
@@ -65,35 +65,3 @@ glamor_change_window_attributes(WindowPtr pWin, unsigned long mask)
     }
     return TRUE;
 }
-
-void
-glamor_set_window_pixmap(WindowPtr win, PixmapPtr pPixmap)
-{
-    ScreenPtr screen = win->drawable.pScreen;
-    glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
-    PixmapPtr old = screen->GetWindowPixmap(win);
-
-    if (pPixmap != old) {
-        glamor_pixmap_private *pixmap_priv;
-        PicturePtr pic = NULL;
-
-        pixmap_priv = glamor_get_pixmap_private(old);
-        if (GLAMOR_PIXMAP_PRIV_IS_PICTURE(pixmap_priv) &&
-            pixmap_priv->picture->pDrawable == (DrawablePtr) win) {
-            pic = pixmap_priv->picture;
-            pixmap_priv->is_picture = 0;
-            pixmap_priv->picture = NULL;
-        }
-
-        pixmap_priv = glamor_get_pixmap_private(pPixmap);
-        if (pixmap_priv) {
-            pixmap_priv->is_picture = ! !pic;
-            pixmap_priv->picture = pic;
-        }
-    }
-
-    screen->SetWindowPixmap = glamor_priv->saved_procs.set_window_pixmap;
-    (screen->SetWindowPixmap) (win, pPixmap);
-    glamor_priv->saved_procs.set_window_pixmap = screen->SetWindowPixmap;
-    screen->SetWindowPixmap = glamor_set_window_pixmap;
-}
commit 0dbdb83b0d0254ac67fb33da8bf9ebc0ef4e8081
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jul 2 12:55:27 2015 -0700

    glamor: Use the actual picture's format when uploading memory pixmaps.
    
    The pixmap->picture is just the *last* picture attached to the pixmap,
    so you'd potentially be looking at the wrong one when trying to
    temporarily upload to avoid a composite fallback.
    
    There's some trickiness in glamor_render.c when we're dealing with the
    upload of a GLAMOR_MEMORY pixmap as both the source and mask using
    different formats, where we smash the source's format to a new value
    so that the mask can use the same uploaded bits.  Dropping most of
    that should be safe, since it will be uploaded as the source first, so
    the smashed format will still be used.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Acked-by: Michel Dänzer <michel.daenzer at amd.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/glamor/glamor_picture.c b/glamor/glamor_picture.c
index 3b0b7c9..c36d9d6 100644
--- a/glamor/glamor_picture.c
+++ b/glamor/glamor_picture.c
@@ -307,22 +307,15 @@ glamor_get_tex_format_type_from_pictformat_gles2(PictFormatShort format,
 
 static int
 glamor_get_tex_format_type_from_pixmap(PixmapPtr pixmap,
+                                       PictFormatShort pict_format,
                                        GLenum *format,
                                        GLenum *type,
                                        int *no_alpha,
                                        int *revert, int *swap_rb, int is_upload)
 {
-    glamor_pixmap_private *pixmap_priv;
-    PictFormatShort pict_format;
     glamor_screen_private *glamor_priv =
         glamor_get_screen_private(pixmap->drawable.pScreen);
 
-    pixmap_priv = glamor_get_pixmap_private(pixmap);
-    if (GLAMOR_PIXMAP_PRIV_IS_PICTURE(pixmap_priv))
-        pict_format = pixmap_priv->picture->format;
-    else
-        pict_format = format_for_depth(pixmap->drawable.depth);
-
     if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
         return glamor_get_tex_format_type_from_pictformat_gl(pict_format,
                                                              format, type,
@@ -774,7 +767,8 @@ glamor_put_bits(char *dst_bits, int dst_stride, char *src_bits,
 
 static Bool
 glamor_upload_sub_pixmap_to_texture(PixmapPtr pixmap, int x, int y, int w,
-                                    int h, int stride, void *bits, int pbo)
+                                    int h, int stride, void *bits, int pbo,
+                                    PictFormatShort pict_format)
 {
     ScreenPtr screen = pixmap->drawable.pScreen;
     glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
@@ -784,6 +778,7 @@ glamor_upload_sub_pixmap_to_texture(PixmapPtr pixmap, int x, int y, int w,
     Bool force_clip;
 
     if (glamor_get_tex_format_type_from_pixmap(pixmap,
+                                               pict_format,
                                                &format,
                                                &type,
                                                &no_alpha,
@@ -884,23 +879,6 @@ glamor_upload_sub_pixmap_to_texture(PixmapPtr pixmap, int x, int y, int w,
                                                      pbo);
 }
 
-static enum glamor_pixmap_status
-glamor_upload_pixmap_to_texture(PixmapPtr pixmap)
-{
-    int ret;
-
-    if (glamor_upload_sub_pixmap_to_texture(pixmap, 0, 0,
-                                            pixmap->drawable.width,
-                                            pixmap->drawable.height,
-                                            pixmap->devKind,
-                                            pixmap->devPrivate.ptr, 0))
-        ret = GLAMOR_UPLOAD_DONE;
-    else
-        ret = GLAMOR_UPLOAD_FAILED;
-
-    return ret;
-}
-
 /* Upload picture to texture.  We may need to flip the y axis or
  * wire alpha to 1. So we may conditional create fbo for the picture.
  * */
@@ -912,7 +890,15 @@ glamor_upload_picture_to_texture(PicturePtr picture)
     assert(picture->pDrawable);
     pixmap = glamor_get_drawable_pixmap(picture->pDrawable);
 
-    return glamor_upload_pixmap_to_texture(pixmap);
+    if (glamor_upload_sub_pixmap_to_texture(pixmap, 0, 0,
+                                            pixmap->drawable.width,
+                                            pixmap->drawable.height,
+                                            pixmap->devKind,
+                                            pixmap->devPrivate.ptr, 0,
+                                            picture->format))
+        return GLAMOR_UPLOAD_DONE;
+    else
+        return GLAMOR_UPLOAD_FAILED;
 }
 
 /*
commit 1fd11c46aa086e4b80cb1bafa87c6b19a8014fd1
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jul 2 12:49:36 2015 -0700

    glamor: Move glamor_render.c pict handling to glamor_picture.c
    
    These functions aren't used by anything else, and are specific to the
    temporary-upload-as-a-weird-format path of glamor_render.c, called
    through glamor_upload_picture_to_texture().
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/glamor/glamor_picture.c b/glamor/glamor_picture.c
index 20b9de2..3b0b7c9 100644
--- a/glamor/glamor_picture.c
+++ b/glamor/glamor_picture.c
@@ -31,6 +31,876 @@
 #include "glamor_priv.h"
 #include "mipict.h"
 
+/*
+ * Map picture's format to the correct gl texture format and type.
+ * no_alpha is used to indicate whehter we need to wire alpha to 1.
+ *
+ * Although opengl support A1/GL_BITMAP, we still don't use it
+ * here, it seems that mesa has bugs when uploading a A1 bitmap.
+ *
+ * Return 0 if find a matched texture type. Otherwise return -1.
+ **/
+static int
+glamor_get_tex_format_type_from_pictformat_gl(PictFormatShort format,
+                                              GLenum *tex_format,
+                                              GLenum *tex_type,
+                                              int *no_alpha,
+                                              int *revert,
+                                              int *swap_rb, int is_upload)
+{
+    *no_alpha = 0;
+    *revert = REVERT_NONE;
+    *swap_rb = is_upload ? SWAP_NONE_UPLOADING : SWAP_NONE_DOWNLOADING;
+    switch (format) {
+    case PICT_a1:
+        *tex_format = GL_ALPHA;
+        *tex_type = GL_UNSIGNED_BYTE;
+        *revert = is_upload ? REVERT_UPLOADING_A1 : REVERT_DOWNLOADING_A1;
+        break;
+    case PICT_b8g8r8x8:
+        *no_alpha = 1;
+    case PICT_b8g8r8a8:
+        *tex_format = GL_BGRA;
+        *tex_type = GL_UNSIGNED_INT_8_8_8_8;
+        break;
+
+    case PICT_x8r8g8b8:
+        *no_alpha = 1;
+    case PICT_a8r8g8b8:
+        *tex_format = GL_BGRA;
+        *tex_type = GL_UNSIGNED_INT_8_8_8_8_REV;
+        break;
+    case PICT_x8b8g8r8:
+        *no_alpha = 1;
+    case PICT_a8b8g8r8:
+        *tex_format = GL_RGBA;
+        *tex_type = GL_UNSIGNED_INT_8_8_8_8_REV;
+        break;
+    case PICT_x2r10g10b10:
+        *no_alpha = 1;
+    case PICT_a2r10g10b10:
+        *tex_format = GL_BGRA;
+        *tex_type = GL_UNSIGNED_INT_2_10_10_10_REV;
+        break;
+    case PICT_x2b10g10r10:
+        *no_alpha = 1;
+    case PICT_a2b10g10r10:
+        *tex_format = GL_RGBA;
+        *tex_type = GL_UNSIGNED_INT_2_10_10_10_REV;
+        break;
+
+    case PICT_r5g6b5:
+        *tex_format = GL_RGB;
+        *tex_type = GL_UNSIGNED_SHORT_5_6_5;
+        break;
+    case PICT_b5g6r5:
+        *tex_format = GL_RGB;
+        *tex_type = GL_UNSIGNED_SHORT_5_6_5_REV;
+        break;
+    case PICT_x1b5g5r5:
+        *no_alpha = 1;
+    case PICT_a1b5g5r5:
+        *tex_format = GL_RGBA;
+        *tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
+        break;
+
+    case PICT_x1r5g5b5:
+        *no_alpha = 1;
+    case PICT_a1r5g5b5:
+        *tex_format = GL_BGRA;
+        *tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
+        break;
+    case PICT_a8:
+        *tex_format = GL_ALPHA;
+        *tex_type = GL_UNSIGNED_BYTE;
+        break;
+    case PICT_x4r4g4b4:
+        *no_alpha = 1;
+    case PICT_a4r4g4b4:
+        *tex_format = GL_BGRA;
+        *tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
+        break;
+
+    case PICT_x4b4g4r4:
+        *no_alpha = 1;
+    case PICT_a4b4g4r4:
+        *tex_format = GL_RGBA;
+        *tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
+        break;
+
+    default:
+        return -1;
+    }
+    return 0;
+}
+
+#define IS_LITTLE_ENDIAN  (IMAGE_BYTE_ORDER == LSBFirst)
+
+static int
+glamor_get_tex_format_type_from_pictformat_gles2(PictFormatShort format,
+                                                 GLenum *tex_format,
+                                                 GLenum *tex_type,
+                                                 int *no_alpha,
+                                                 int *revert,
+                                                 int *swap_rb, int is_upload)
+{
+    int need_swap_rb = 0;
+
+    *no_alpha = 0;
+    *revert = IS_LITTLE_ENDIAN ? REVERT_NONE : REVERT_NORMAL;
+
+    switch (format) {
+    case PICT_b8g8r8x8:
+        *no_alpha = 1;
+    case PICT_b8g8r8a8:
+        *tex_format = GL_RGBA;
+        *tex_type = GL_UNSIGNED_BYTE;
+        need_swap_rb = 1;
+        *revert = IS_LITTLE_ENDIAN ? REVERT_NORMAL : REVERT_NONE;
+        break;
+
+    case PICT_x8r8g8b8:
+        *no_alpha = 1;
+    case PICT_a8r8g8b8:
+        *tex_format = GL_RGBA;
+        *tex_type = GL_UNSIGNED_BYTE;
+        need_swap_rb = 1;
+        break;
+
+    case PICT_x8b8g8r8:
+        *no_alpha = 1;
+    case PICT_a8b8g8r8:
+        *tex_format = GL_RGBA;
+        *tex_type = GL_UNSIGNED_BYTE;
+        break;
+
+    case PICT_x2r10g10b10:
+        *no_alpha = 1;
+    case PICT_a2r10g10b10:
+        *tex_format = GL_RGBA;
+        /* glReadPixmap doesn't support GL_UNSIGNED_INT_10_10_10_2.
+         * we have to use GL_UNSIGNED_BYTE and do the conversion in
+         * shader latter.*/
+        *tex_type = GL_UNSIGNED_BYTE;
+        if (is_upload == 1) {
+            if (!IS_LITTLE_ENDIAN)
+                *revert = REVERT_UPLOADING_10_10_10_2;
+            else
+                *revert = REVERT_UPLOADING_2_10_10_10;
+        }
+        else {
+            if (!IS_LITTLE_ENDIAN) {
+                *revert = REVERT_DOWNLOADING_10_10_10_2;
+            }
+            else {
+                *revert = REVERT_DOWNLOADING_2_10_10_10;
+            }
+        }
+        need_swap_rb = 1;
+
+        break;
+
+    case PICT_x2b10g10r10:
+        *no_alpha = 1;
+    case PICT_a2b10g10r10:
+        *tex_format = GL_RGBA;
+        *tex_type = GL_UNSIGNED_BYTE;
+        if (is_upload == 1) {
+            if (!IS_LITTLE_ENDIAN)
+                *revert = REVERT_UPLOADING_10_10_10_2;
+            else
+                *revert = REVERT_UPLOADING_2_10_10_10;
+        }
+        else {
+            if (!IS_LITTLE_ENDIAN) {
+                *revert = REVERT_DOWNLOADING_10_10_10_2;
+            }
+            else {
+                *revert = REVERT_DOWNLOADING_2_10_10_10;
+            }
+        }
+        break;
+
+    case PICT_r5g6b5:
+        *tex_format = GL_RGB;
+        *tex_type = GL_UNSIGNED_SHORT_5_6_5;
+        *revert = IS_LITTLE_ENDIAN ? REVERT_NONE : REVERT_NORMAL;
+
+        break;
+
+    case PICT_b5g6r5:
+        *tex_format = GL_RGB;
+        *tex_type = GL_UNSIGNED_SHORT_5_6_5;
+        need_swap_rb = IS_LITTLE_ENDIAN ? 1 : 0;;
+        break;
+
+    case PICT_x1b5g5r5:
+        *no_alpha = 1;
+    case PICT_a1b5g5r5:
+        *tex_format = GL_RGBA;
+        *tex_type = GL_UNSIGNED_SHORT_5_5_5_1;
+        if (IS_LITTLE_ENDIAN) {
+            *revert =
+                is_upload ? REVERT_UPLOADING_1_5_5_5 :
+                REVERT_DOWNLOADING_1_5_5_5;
+        }
+        else
+            *revert = REVERT_NONE;
+        break;
+
+    case PICT_x1r5g5b5:
+        *no_alpha = 1;
+    case PICT_a1r5g5b5:
+        *tex_format = GL_RGBA;
+        *tex_type = GL_UNSIGNED_SHORT_5_5_5_1;
+        if (IS_LITTLE_ENDIAN) {
+            *revert =
+                is_upload ? REVERT_UPLOADING_1_5_5_5 :
+                REVERT_DOWNLOADING_1_5_5_5;
+        }
+        else
+            *revert = REVERT_NONE;
+        need_swap_rb = 1;
+        break;
+
+    case PICT_a1:
+        *tex_format = GL_ALPHA;
+        *tex_type = GL_UNSIGNED_BYTE;
+        *revert = is_upload ? REVERT_UPLOADING_A1 : REVERT_DOWNLOADING_A1;
+        break;
+
+    case PICT_a8:
+        *tex_format = GL_ALPHA;
+        *tex_type = GL_UNSIGNED_BYTE;
+        *revert = REVERT_NONE;
+        break;
+
+    case PICT_x4r4g4b4:
+        *no_alpha = 1;
+    case PICT_a4r4g4b4:
+        *tex_format = GL_RGBA;
+        *tex_type = GL_UNSIGNED_SHORT_4_4_4_4;
+        *revert = IS_LITTLE_ENDIAN ? REVERT_NORMAL : REVERT_NONE;
+        need_swap_rb = 1;
+        break;
+
+    case PICT_x4b4g4r4:
+        *no_alpha = 1;
+    case PICT_a4b4g4r4:
+        *tex_format = GL_RGBA;
+        *tex_type = GL_UNSIGNED_SHORT_4_4_4_4;
+        *revert = IS_LITTLE_ENDIAN ? REVERT_NORMAL : REVERT_NONE;
+        break;
+
+    default:
+        LogMessageVerb(X_INFO, 0,
+                       "fail to get matched format for %x \n", format);
+        return -1;
+    }
+
+    if (need_swap_rb)
+        *swap_rb = is_upload ? SWAP_UPLOADING : SWAP_DOWNLOADING;
+    else
+        *swap_rb = is_upload ? SWAP_NONE_UPLOADING : SWAP_NONE_DOWNLOADING;
+    return 0;
+}
+
+static int
+glamor_get_tex_format_type_from_pixmap(PixmapPtr pixmap,
+                                       GLenum *format,
+                                       GLenum *type,
+                                       int *no_alpha,
+                                       int *revert, int *swap_rb, int is_upload)
+{
+    glamor_pixmap_private *pixmap_priv;
+    PictFormatShort pict_format;
+    glamor_screen_private *glamor_priv =
+        glamor_get_screen_private(pixmap->drawable.pScreen);
+
+    pixmap_priv = glamor_get_pixmap_private(pixmap);
+    if (GLAMOR_PIXMAP_PRIV_IS_PICTURE(pixmap_priv))
+        pict_format = pixmap_priv->picture->format;
+    else
+        pict_format = format_for_depth(pixmap->drawable.depth);
+
+    if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
+        return glamor_get_tex_format_type_from_pictformat_gl(pict_format,
+                                                             format, type,
+                                                             no_alpha,
+                                                             revert,
+                                                             swap_rb,
+                                                             is_upload);
+    } else {
+        return glamor_get_tex_format_type_from_pictformat_gles2(pict_format,
+                                                                format, type,
+                                                                no_alpha,
+                                                                revert,
+                                                                swap_rb,
+                                                                is_upload);
+    }
+}
+
+static void *
+_glamor_color_convert_a1_a8(void *src_bits, void *dst_bits, int w, int h,
+                            int stride, int revert)
+{
+    PictFormatShort dst_format, src_format;
+    pixman_image_t *dst_image;
+    pixman_image_t *src_image;
+    int src_stride;
+
+    if (revert == REVERT_UPLOADING_A1) {
+        src_format = PICT_a1;
+        dst_format = PICT_a8;
+        src_stride = PixmapBytePad(w, 1);
+    }
+    else {
+        dst_format = PICT_a1;
+        src_format = PICT_a8;
+        src_stride = (((w * 8 + 7) / 8) + 3) & ~3;
+    }
+
+    dst_image = pixman_image_create_bits(dst_format, w, h, dst_bits, stride);
+    if (dst_image == NULL) {
+        return NULL;
+    }
+
+    src_image = pixman_image_create_bits(src_format,
+                                         w, h, src_bits, src_stride);
+
+    if (src_image == NULL) {
+        pixman_image_unref(dst_image);
+        return NULL;
+    }
+
+    pixman_image_composite(PictOpSrc, src_image, NULL, dst_image,
+                           0, 0, 0, 0, 0, 0, w, h);
+
+    pixman_image_unref(src_image);
+    pixman_image_unref(dst_image);
+    return dst_bits;
+}
+
+#define ADJUST_BITS(d, src_bits, dst_bits)	(((dst_bits) == (src_bits)) ? (d) : 				\
+							(((dst_bits) > (src_bits)) ? 				\
+							  (((d) << ((dst_bits) - (src_bits))) 			\
+								   + (( 1 << ((dst_bits) - (src_bits))) >> 1))	\
+								:  ((d) >> ((src_bits) - (dst_bits)))))
+
+#define GLAMOR_DO_CONVERT(src, dst, no_alpha, swap,		\
+			  a_shift_src, a_bits_src,		\
+			  b_shift_src, b_bits_src,		\
+			  g_shift_src, g_bits_src,		\
+			  r_shift_src, r_bits_src,		\
+			  a_shift, a_bits,			\
+			  b_shift, b_bits,			\
+			  g_shift, g_bits,			\
+			  r_shift, r_bits)			\
+	do {								\
+		typeof(src) a,b,g,r;					\
+		typeof(src) a_mask_src, b_mask_src, g_mask_src, r_mask_src;\
+		a_mask_src = (((1 << (a_bits_src)) - 1) << a_shift_src);\
+		b_mask_src = (((1 << (b_bits_src)) - 1) << b_shift_src);\
+		g_mask_src = (((1 << (g_bits_src)) - 1) << g_shift_src);\
+		r_mask_src = (((1 << (r_bits_src)) - 1) << r_shift_src);\
+		if (no_alpha)						\
+			a = (a_mask_src) >> (a_shift_src);			\
+		else							\
+			a = ((src) & (a_mask_src)) >> (a_shift_src);	\
+		b = ((src) & (b_mask_src)) >> (b_shift_src);		\
+		g = ((src) & (g_mask_src)) >> (g_shift_src);		\
+		r = ((src) & (r_mask_src)) >> (r_shift_src);		\
+		a = ADJUST_BITS(a, a_bits_src, a_bits);			\
+		b = ADJUST_BITS(b, b_bits_src, b_bits);			\
+		g = ADJUST_BITS(g, g_bits_src, g_bits);			\
+		r = ADJUST_BITS(r, r_bits_src, r_bits);			\
+		if (swap == 0)						\
+			(*dst) = ((a) << (a_shift)) | ((b) << (b_shift)) | ((g) << (g_shift)) | ((r) << (r_shift)); \
+		else 												    \
+			(*dst) = ((a) << (a_shift)) | ((r) << (b_shift)) | ((g) << (g_shift)) | ((b) << (r_shift)); \
+	} while (0)
+
+static void *
+_glamor_color_revert_x2b10g10r10(void *src_bits, void *dst_bits, int w, int h,
+                                 int stride, int no_alpha, int revert,
+                                 int swap_rb)
+{
+    int x, y;
+    unsigned int *words, *saved_words, *source_words;
+    int swap = !(swap_rb == SWAP_NONE_DOWNLOADING ||
+                 swap_rb == SWAP_NONE_UPLOADING);
+
+    source_words = src_bits;
+    words = dst_bits;
+    saved_words = words;
+
+    for (y = 0; y < h; y++) {
+        DEBUGF("Line %d :  ", y);
+        for (x = 0; x < w; x++) {
+            unsigned int pixel = source_words[x];
+
+            if (revert == REVERT_DOWNLOADING_2_10_10_10)
+                GLAMOR_DO_CONVERT(pixel, &words[x], no_alpha, swap,
+                                  24, 8, 16, 8, 8, 8, 0, 8,
+                                  30, 2, 20, 10, 10, 10, 0, 10);
+            else
+                GLAMOR_DO_CONVERT(pixel, &words[x], no_alpha, swap,
+                                  30, 2, 20, 10, 10, 10, 0, 10,
+                                  24, 8, 16, 8, 8, 8, 0, 8);
+            DEBUGF("%x:%x ", pixel, words[x]);
+        }
+        DEBUGF("\n");
+        words += stride / sizeof(*words);
+        source_words += stride / sizeof(*words);
+    }
+    DEBUGF("\n");
+    return saved_words;
+
+}
+
+static void *
+_glamor_color_revert_x1b5g5r5(void *src_bits, void *dst_bits, int w, int h,
+                              int stride, int no_alpha, int revert, int swap_rb)
+{
+    int x, y;
+    unsigned short *words, *saved_words, *source_words;
+    int swap = !(swap_rb == SWAP_NONE_DOWNLOADING ||
+                 swap_rb == SWAP_NONE_UPLOADING);
+
+    words = dst_bits;
+    source_words = src_bits;
+    saved_words = words;
+
+    for (y = 0; y < h; y++) {
+        DEBUGF("Line %d :  ", y);
+        for (x = 0; x < w; x++) {
+            unsigned short pixel = source_words[x];
+
+            if (revert == REVERT_DOWNLOADING_1_5_5_5)
+                GLAMOR_DO_CONVERT(pixel, &words[x], no_alpha, swap,
+                                  0, 1, 1, 5, 6, 5, 11, 5,
+                                  15, 1, 10, 5, 5, 5, 0, 5);
+            else
+                GLAMOR_DO_CONVERT(pixel, &words[x], no_alpha, swap,
+                                  15, 1, 10, 5, 5, 5, 0, 5,
+                                  0, 1, 1, 5, 6, 5, 11, 5);
+            DEBUGF("%04x:%04x ", pixel, words[x]);
+        }
+        DEBUGF("\n");
+        words += stride / sizeof(*words);
+        source_words += stride / sizeof(*words);
+    }
+    DEBUGF("\n");
+    return saved_words;
+}
+
+/*
+ * This function is to convert an unsupported color format to/from a
+ * supported GL format.
+ * Here are the current scenarios:
+ *
+ * @no_alpha:
+ * 	If it is set, then we need to wire the alpha value to 1.
+ * @revert:
+	REVERT_DOWNLOADING_A1		: convert an Alpha8 buffer to a A1 buffer.
+	REVERT_UPLOADING_A1		: convert an A1 buffer to an Alpha8 buffer
+	REVERT_DOWNLOADING_2_10_10_10 	: convert r10G10b10X2 to X2B10G10R10
+	REVERT_UPLOADING_2_10_10_10 	: convert X2B10G10R10 to R10G10B10X2
+	REVERT_DOWNLOADING_1_5_5_5  	: convert B5G5R5X1 to X1R5G5B5
+	REVERT_UPLOADING_1_5_5_5    	: convert X1R5G5B5 to B5G5R5X1
+   @swap_rb: if we have the swap_rb set, then we need to swap the R and B's position.
+ *
+ */
+
+static void *
+glamor_color_convert_to_bits(void *src_bits, void *dst_bits, int w, int h,
+                             int stride, int no_alpha, int revert, int swap_rb)
+{
+    if (revert == REVERT_DOWNLOADING_A1 || revert == REVERT_UPLOADING_A1) {
+        return _glamor_color_convert_a1_a8(src_bits, dst_bits, w, h, stride,
+                                           revert);
+    }
+    else if (revert == REVERT_DOWNLOADING_2_10_10_10 ||
+             revert == REVERT_UPLOADING_2_10_10_10) {
+        return _glamor_color_revert_x2b10g10r10(src_bits, dst_bits, w, h,
+                                                stride, no_alpha, revert,
+                                                swap_rb);
+    }
+    else if (revert == REVERT_DOWNLOADING_1_5_5_5 ||
+             revert == REVERT_UPLOADING_1_5_5_5) {
+        return _glamor_color_revert_x1b5g5r5(src_bits, dst_bits, w, h, stride,
+                                             no_alpha, revert, swap_rb);
+    }
+    else
+        ErrorF("convert a non-supported mode %x.\n", revert);
+
+    return NULL;
+}
+
+/**
+ * Upload pixmap to a specified texture.
+ * This texture may not be the one attached to it.
+ **/
+static void
+__glamor_upload_pixmap_to_texture(PixmapPtr pixmap, unsigned int *tex,
+                                  GLenum format,
+                                  GLenum type,
+                                  int x, int y, int w, int h,
+                                  void *bits, int pbo)
+{
+    glamor_screen_private *glamor_priv =
+        glamor_get_screen_private(pixmap->drawable.pScreen);
+    int non_sub = 0;
+    unsigned int iformat = 0;
+
+    glamor_make_current(glamor_priv);
+    if (*tex == 0) {
+        glGenTextures(1, tex);
+        if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP)
+            iformat = gl_iformat_for_pixmap(pixmap);
+        else
+            iformat = format;
+        non_sub = 1;
+        assert(x == 0 && y == 0);
+    }
+
+    glBindTexture(GL_TEXTURE_2D, *tex);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+    glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
+
+    assert(pbo || bits != 0);
+    if (bits == NULL) {
+        glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
+        glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
+    }
+    if (non_sub)
+        glTexImage2D(GL_TEXTURE_2D, 0, iformat, w, h, 0, format, type, bits);
+    else
+        glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, format, type, bits);
+
+    if (bits == NULL)
+        glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
+}
+
+static Bool
+_glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format,
+                                      GLenum type, int no_alpha, int revert,
+                                      int swap_rb, int x, int y, int w, int h,
+                                      int stride, void *bits, int pbo)
+{
+    ScreenPtr screen = pixmap->drawable.pScreen;
+    glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
+    glamor_screen_private *glamor_priv =
+        glamor_get_screen_private(pixmap->drawable.pScreen);
+    static float vertices[8];
+
+    static float texcoords_inv[8] = { 0, 0,
+        1, 0,
+        1, 1,
+        0, 1
+    };
+    float *ptexcoords;
+    float dst_xscale, dst_yscale;
+    GLuint tex = 0;
+    int need_free_bits = 0;
+
+    if (bits == NULL)
+        goto ready_to_upload;
+
+    if (revert > REVERT_NORMAL) {
+        /* XXX if we are restoring the pixmap, then we may not need to allocate
+         * new buffer */
+        void *converted_bits;
+
+        if (pixmap->drawable.depth == 1)
+            stride = (((w * 8 + 7) / 8) + 3) & ~3;
+
+        converted_bits = xallocarray(h, stride);
+
+        if (converted_bits == NULL)
+            return FALSE;
+        bits = glamor_color_convert_to_bits(bits, converted_bits, w, h,
+                                            stride, no_alpha, revert, swap_rb);
+        if (bits == NULL) {
+            free(converted_bits);
+            ErrorF("Failed to convert pixmap no_alpha %d,"
+                   "revert mode %d, swap mode %d\n", no_alpha, revert, swap_rb);
+            return FALSE;
+        }
+        no_alpha = 0;
+        revert = REVERT_NONE;
+        swap_rb = SWAP_NONE_UPLOADING;
+        need_free_bits = TRUE;
+    }
+
+ ready_to_upload:
+
+    /* Try fast path firstly, upload the pixmap to the texture attached
+     * to the fbo directly. */
+    if (no_alpha == 0
+        && revert == REVERT_NONE && swap_rb == SWAP_NONE_UPLOADING
+#ifdef WALKAROUND_LARGE_TEXTURE_MAP
+        && glamor_pixmap_priv_is_small(pixmap_priv)
+#endif
+        ) {
+        int fbo_x_off, fbo_y_off;
+
+        assert(pixmap_priv->fbo->tex);
+        pixmap_priv_get_fbo_off(pixmap_priv, &fbo_x_off, &fbo_y_off);
+
+        assert(x + fbo_x_off >= 0 && y + fbo_y_off >= 0);
+        assert(x + fbo_x_off + w <= pixmap_priv->fbo->width);
+        assert(y + fbo_y_off + h <= pixmap_priv->fbo->height);
+        __glamor_upload_pixmap_to_texture(pixmap, &pixmap_priv->fbo->tex,
+                                          format, type,
+                                          x + fbo_x_off, y + fbo_y_off, w, h,
+                                          bits, pbo);
+    } else {
+        ptexcoords = texcoords_inv;
+
+        pixmap_priv_get_dest_scale(pixmap, pixmap_priv, &dst_xscale, &dst_yscale);
+        glamor_set_normalize_vcoords(pixmap_priv, dst_xscale,
+                                     dst_yscale,
+                                     x, y,
+                                     x + w, y + h,
+                                     vertices);
+        /* Slow path, we need to flip y or wire alpha to 1. */
+        glamor_make_current(glamor_priv);
+        glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT,
+                              GL_FALSE, 2 * sizeof(float), vertices);
+        glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
+        glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, GL_FLOAT,
+                              GL_FALSE, 2 * sizeof(float), ptexcoords);
+        glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
+
+        glamor_set_destination_pixmap_priv_nc(glamor_priv, pixmap, pixmap_priv);
+        glamor_set_alu(screen, GXcopy);
+        __glamor_upload_pixmap_to_texture(pixmap, &tex,
+                                          format, type, 0, 0, w, h, bits, pbo);
+        glActiveTexture(GL_TEXTURE0);
+        glBindTexture(GL_TEXTURE_2D, tex);
+
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+        glUseProgram(glamor_priv->finish_access_prog[no_alpha]);
+        glUniform1i(glamor_priv->finish_access_revert[no_alpha], revert);
+        glUniform1i(glamor_priv->finish_access_swap_rb[no_alpha], swap_rb);
+
+        glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+        glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
+        glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
+        glDeleteTextures(1, &tex);
+        glBindFramebuffer(GL_FRAMEBUFFER, 0);
+    }
+
+    if (need_free_bits)
+        free(bits);
+    return TRUE;
+}
+
+/*
+ * Prepare to upload a pixmap to texture memory.
+ * no_alpha equals 1 means the format needs to wire alpha to 1.
+ */
+static int
+glamor_pixmap_upload_prepare(PixmapPtr pixmap, GLenum format, int no_alpha,
+                             int revert, int swap_rb)
+{
+    int flag = 0;
+    glamor_pixmap_private *pixmap_priv;
+    glamor_screen_private *glamor_priv;
+    glamor_pixmap_fbo *fbo;
+    GLenum iformat;
+
+    pixmap_priv = glamor_get_pixmap_private(pixmap);
+    glamor_priv = glamor_get_screen_private(pixmap->drawable.pScreen);
+
+    if (pixmap_priv->gl_fbo != GLAMOR_FBO_UNATTACHED)
+        return 0;
+
+    if (pixmap_priv->fbo
+        && (pixmap_priv->fbo->width < pixmap->drawable.width
+            || pixmap_priv->fbo->height < pixmap->drawable.height)) {
+        fbo = glamor_pixmap_detach_fbo(pixmap_priv);
+        glamor_destroy_fbo(glamor_priv, fbo);
+    }
+
+    if (pixmap_priv->fbo && pixmap_priv->fbo->fb)
+        return 0;
+
+    if (!(no_alpha || (revert == REVERT_NORMAL)
+          || (swap_rb != SWAP_NONE_UPLOADING))) {
+        /* We don't need a fbo, a simple texture uploading should work. */
+
+        flag = GLAMOR_CREATE_FBO_NO_FBO;
+    }
+
+    if ((flag == GLAMOR_CREATE_FBO_NO_FBO
+         && pixmap_priv->fbo && pixmap_priv->fbo->tex))
+        return 0;
+
+    if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP)
+        iformat = gl_iformat_for_pixmap(pixmap);
+    else
+        iformat = format;
+
+    if (!glamor_pixmap_ensure_fbo(pixmap, iformat, flag))
+        return -1;
+
+    return 0;
+}
+
+/*
+ * upload sub region to a large region.
+ * */
+static void
+glamor_put_bits(char *dst_bits, int dst_stride, char *src_bits,
+                int src_stride, int bpp, int x, int y, int w, int h)
+{
+    int j;
+    int byte_per_pixel;
+
+    byte_per_pixel = bpp / 8;
+    src_bits += y * src_stride + (x * byte_per_pixel);
+
+    for (j = y; j < y + h; j++) {
+        memcpy(dst_bits, src_bits, w * byte_per_pixel);
+        src_bits += src_stride;
+        dst_bits += dst_stride;
+    }
+}
+
+static Bool
+glamor_upload_sub_pixmap_to_texture(PixmapPtr pixmap, int x, int y, int w,
+                                    int h, int stride, void *bits, int pbo)
+{
+    ScreenPtr screen = pixmap->drawable.pScreen;
+    glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
+    GLenum format, type;
+    int no_alpha, revert, swap_rb;
+    glamor_pixmap_private *pixmap_priv;
+    Bool force_clip;
+
+    if (glamor_get_tex_format_type_from_pixmap(pixmap,
+                                               &format,
+                                               &type,
+                                               &no_alpha,
+                                               &revert, &swap_rb, 1)) {
+        glamor_fallback("Unknown pixmap depth %d.\n", pixmap->drawable.depth);
+        return FALSE;
+    }
+    if (glamor_pixmap_upload_prepare(pixmap, format, no_alpha, revert, swap_rb))
+        return FALSE;
+
+    pixmap_priv = glamor_get_pixmap_private(pixmap);
+    force_clip = glamor_priv->gl_flavor != GLAMOR_GL_DESKTOP
+        && !glamor_check_fbo_size(glamor_priv, w, h);
+
+    if (glamor_pixmap_priv_is_large(pixmap_priv) || force_clip) {
+        RegionRec region;
+        BoxRec box;
+        int n_region;
+        glamor_pixmap_clipped_regions *clipped_regions;
+        void *sub_bits;
+        int i, j;
+
+        sub_bits = xallocarray(h, stride);
+        if (sub_bits == NULL)
+            return FALSE;
+        box.x1 = x;
+        box.y1 = y;
+        box.x2 = x + w;
+        box.y2 = y + h;
+        RegionInitBoxes(&region, &box, 1);
+        if (!force_clip)
+            clipped_regions =
+                glamor_compute_clipped_regions(pixmap, &region, &n_region,
+                                               0, 0, 0);
+        else
+            clipped_regions =
+                glamor_compute_clipped_regions_ext(pixmap, &region,
+                                                   &n_region,
+                                                   pixmap_priv->block_w,
+                                                   pixmap_priv->block_h,
+                                                   0,
+                                                   0);
+        DEBUGF("prepare upload %dx%d to a large pixmap %p\n", w, h, pixmap);
+        for (i = 0; i < n_region; i++) {
+            BoxPtr boxes;
+            int nbox;
+            int temp_stride;
+            void *temp_bits;
+
+            assert(pbo == 0);
+
+            glamor_set_pixmap_fbo_current(pixmap_priv, clipped_regions[i].block_idx);
+
+            boxes = RegionRects(clipped_regions[i].region);
+            nbox = RegionNumRects(clipped_regions[i].region);
+            DEBUGF("split to %d boxes\n", nbox);
+            for (j = 0; j < nbox; j++) {
+                temp_stride = PixmapBytePad(boxes[j].x2 - boxes[j].x1,
+                                            pixmap->drawable.depth);
+
+                if (boxes[j].x1 == x && temp_stride == stride) {
+                    temp_bits = (char *) bits + (boxes[j].y1 - y) * stride;
+                }
+                else {
+                    temp_bits = sub_bits;
+                    glamor_put_bits(temp_bits, temp_stride, bits, stride,
+                                    pixmap->drawable.bitsPerPixel,
+                                    boxes[j].x1 - x, boxes[j].y1 - y,
+                                    boxes[j].x2 - boxes[j].x1,
+                                    boxes[j].y2 - boxes[j].y1);
+                }
+                DEBUGF("upload x %d y %d w %d h %d temp stride %d \n",
+                       boxes[j].x1 - x, boxes[j].y1 - y,
+                       boxes[j].x2 - boxes[j].x1,
+                       boxes[j].y2 - boxes[j].y1, temp_stride);
+                if (_glamor_upload_bits_to_pixmap_texture
+                    (pixmap, format, type, no_alpha, revert, swap_rb,
+                     boxes[j].x1, boxes[j].y1, boxes[j].x2 - boxes[j].x1,
+                     boxes[j].y2 - boxes[j].y1, temp_stride, temp_bits,
+                     pbo) == FALSE) {
+                    RegionUninit(&region);
+                    free(sub_bits);
+                    assert(0);
+                    return FALSE;
+                }
+            }
+            RegionDestroy(clipped_regions[i].region);
+        }
+        free(sub_bits);
+        free(clipped_regions);
+        RegionUninit(&region);
+        return TRUE;
+    }
+    else
+        return _glamor_upload_bits_to_pixmap_texture(pixmap, format, type,
+                                                     no_alpha, revert, swap_rb,
+                                                     x, y, w, h, stride, bits,
+                                                     pbo);
+}
+
+static enum glamor_pixmap_status
+glamor_upload_pixmap_to_texture(PixmapPtr pixmap)
+{
+    int ret;
+
+    if (glamor_upload_sub_pixmap_to_texture(pixmap, 0, 0,
+                                            pixmap->drawable.width,
+                                            pixmap->drawable.height,
+                                            pixmap->devKind,
+                                            pixmap->devPrivate.ptr, 0))
+        ret = GLAMOR_UPLOAD_DONE;
+    else
+        ret = GLAMOR_UPLOAD_FAILED;
+
+    return ret;
+}
+
 /* Upload picture to texture.  We may need to flip the y axis or
  * wire alpha to 1. So we may conditional create fbo for the picture.
  * */
diff --git a/glamor/glamor_pixmap.c b/glamor/glamor_pixmap.c
index 5a09d32..166bde5 100644
--- a/glamor/glamor_pixmap.c
+++ b/glamor/glamor_pixmap.c
@@ -189,873 +189,3 @@ glamor_set_alu(ScreenPtr screen, unsigned char alu)
 
     return TRUE;
 }
-
-/*
- * Map picture's format to the correct gl texture format and type.
- * no_alpha is used to indicate whehter we need to wire alpha to 1.
- *
- * Although opengl support A1/GL_BITMAP, we still don't use it
- * here, it seems that mesa has bugs when uploading a A1 bitmap.
- *
- * Return 0 if find a matched texture type. Otherwise return -1.
- **/
-static int
-glamor_get_tex_format_type_from_pictformat_gl(PictFormatShort format,
-                                              GLenum *tex_format,
-                                              GLenum *tex_type,
-                                              int *no_alpha,
-                                              int *revert,
-                                              int *swap_rb, int is_upload)
-{
-    *no_alpha = 0;
-    *revert = REVERT_NONE;
-    *swap_rb = is_upload ? SWAP_NONE_UPLOADING : SWAP_NONE_DOWNLOADING;
-    switch (format) {
-    case PICT_a1:
-        *tex_format = GL_ALPHA;
-        *tex_type = GL_UNSIGNED_BYTE;
-        *revert = is_upload ? REVERT_UPLOADING_A1 : REVERT_DOWNLOADING_A1;
-        break;
-    case PICT_b8g8r8x8:
-        *no_alpha = 1;
-    case PICT_b8g8r8a8:
-        *tex_format = GL_BGRA;
-        *tex_type = GL_UNSIGNED_INT_8_8_8_8;
-        break;
-
-    case PICT_x8r8g8b8:
-        *no_alpha = 1;
-    case PICT_a8r8g8b8:
-        *tex_format = GL_BGRA;
-        *tex_type = GL_UNSIGNED_INT_8_8_8_8_REV;
-        break;
-    case PICT_x8b8g8r8:
-        *no_alpha = 1;
-    case PICT_a8b8g8r8:
-        *tex_format = GL_RGBA;
-        *tex_type = GL_UNSIGNED_INT_8_8_8_8_REV;
-        break;
-    case PICT_x2r10g10b10:
-        *no_alpha = 1;
-    case PICT_a2r10g10b10:
-        *tex_format = GL_BGRA;
-        *tex_type = GL_UNSIGNED_INT_2_10_10_10_REV;
-        break;
-    case PICT_x2b10g10r10:
-        *no_alpha = 1;
-    case PICT_a2b10g10r10:
-        *tex_format = GL_RGBA;
-        *tex_type = GL_UNSIGNED_INT_2_10_10_10_REV;
-        break;
-
-    case PICT_r5g6b5:
-        *tex_format = GL_RGB;
-        *tex_type = GL_UNSIGNED_SHORT_5_6_5;
-        break;
-    case PICT_b5g6r5:
-        *tex_format = GL_RGB;
-        *tex_type = GL_UNSIGNED_SHORT_5_6_5_REV;
-        break;
-    case PICT_x1b5g5r5:
-        *no_alpha = 1;
-    case PICT_a1b5g5r5:
-        *tex_format = GL_RGBA;
-        *tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
-        break;
-
-    case PICT_x1r5g5b5:
-        *no_alpha = 1;
-    case PICT_a1r5g5b5:
-        *tex_format = GL_BGRA;
-        *tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
-        break;
-    case PICT_a8:
-        *tex_format = GL_ALPHA;
-        *tex_type = GL_UNSIGNED_BYTE;
-        break;
-    case PICT_x4r4g4b4:
-        *no_alpha = 1;
-    case PICT_a4r4g4b4:
-        *tex_format = GL_BGRA;
-        *tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
-        break;
-
-    case PICT_x4b4g4r4:
-        *no_alpha = 1;
-    case PICT_a4b4g4r4:
-        *tex_format = GL_RGBA;
-        *tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
-        break;
-
-    default:
-        return -1;
-    }
-    return 0;
-}
-
-#define IS_LITTLE_ENDIAN  (IMAGE_BYTE_ORDER == LSBFirst)
-
-static int
-glamor_get_tex_format_type_from_pictformat_gles2(PictFormatShort format,
-                                                 GLenum *tex_format,
-                                                 GLenum *tex_type,
-                                                 int *no_alpha,
-                                                 int *revert,
-                                                 int *swap_rb, int is_upload)
-{
-    int need_swap_rb = 0;
-
-    *no_alpha = 0;
-    *revert = IS_LITTLE_ENDIAN ? REVERT_NONE : REVERT_NORMAL;
-
-    switch (format) {
-    case PICT_b8g8r8x8:
-        *no_alpha = 1;
-    case PICT_b8g8r8a8:
-        *tex_format = GL_RGBA;
-        *tex_type = GL_UNSIGNED_BYTE;
-        need_swap_rb = 1;
-        *revert = IS_LITTLE_ENDIAN ? REVERT_NORMAL : REVERT_NONE;
-        break;
-
-    case PICT_x8r8g8b8:
-        *no_alpha = 1;
-    case PICT_a8r8g8b8:
-        *tex_format = GL_RGBA;
-        *tex_type = GL_UNSIGNED_BYTE;
-        need_swap_rb = 1;
-        break;
-
-    case PICT_x8b8g8r8:
-        *no_alpha = 1;
-    case PICT_a8b8g8r8:
-        *tex_format = GL_RGBA;
-        *tex_type = GL_UNSIGNED_BYTE;
-        break;
-
-    case PICT_x2r10g10b10:
-        *no_alpha = 1;
-    case PICT_a2r10g10b10:
-        *tex_format = GL_RGBA;
-        /* glReadPixmap doesn't support GL_UNSIGNED_INT_10_10_10_2.
-         * we have to use GL_UNSIGNED_BYTE and do the conversion in
-         * shader latter.*/
-        *tex_type = GL_UNSIGNED_BYTE;
-        if (is_upload == 1) {
-            if (!IS_LITTLE_ENDIAN)
-                *revert = REVERT_UPLOADING_10_10_10_2;
-            else
-                *revert = REVERT_UPLOADING_2_10_10_10;
-        }
-        else {
-            if (!IS_LITTLE_ENDIAN) {
-                *revert = REVERT_DOWNLOADING_10_10_10_2;
-            }
-            else {
-                *revert = REVERT_DOWNLOADING_2_10_10_10;
-            }
-        }
-        need_swap_rb = 1;
-
-        break;
-
-    case PICT_x2b10g10r10:
-        *no_alpha = 1;
-    case PICT_a2b10g10r10:
-        *tex_format = GL_RGBA;
-        *tex_type = GL_UNSIGNED_BYTE;
-        if (is_upload == 1) {
-            if (!IS_LITTLE_ENDIAN)
-                *revert = REVERT_UPLOADING_10_10_10_2;
-            else
-                *revert = REVERT_UPLOADING_2_10_10_10;
-        }
-        else {
-            if (!IS_LITTLE_ENDIAN) {
-                *revert = REVERT_DOWNLOADING_10_10_10_2;
-            }
-            else {
-                *revert = REVERT_DOWNLOADING_2_10_10_10;
-            }
-        }
-        break;
-
-    case PICT_r5g6b5:
-        *tex_format = GL_RGB;
-        *tex_type = GL_UNSIGNED_SHORT_5_6_5;
-        *revert = IS_LITTLE_ENDIAN ? REVERT_NONE : REVERT_NORMAL;
-
-        break;
-
-    case PICT_b5g6r5:
-        *tex_format = GL_RGB;
-        *tex_type = GL_UNSIGNED_SHORT_5_6_5;
-        need_swap_rb = IS_LITTLE_ENDIAN ? 1 : 0;;
-        break;
-
-    case PICT_x1b5g5r5:
-        *no_alpha = 1;
-    case PICT_a1b5g5r5:
-        *tex_format = GL_RGBA;
-        *tex_type = GL_UNSIGNED_SHORT_5_5_5_1;
-        if (IS_LITTLE_ENDIAN) {
-            *revert =
-                is_upload ? REVERT_UPLOADING_1_5_5_5 :
-                REVERT_DOWNLOADING_1_5_5_5;
-        }
-        else
-            *revert = REVERT_NONE;
-        break;
-
-    case PICT_x1r5g5b5:
-        *no_alpha = 1;
-    case PICT_a1r5g5b5:
-        *tex_format = GL_RGBA;
-        *tex_type = GL_UNSIGNED_SHORT_5_5_5_1;
-        if (IS_LITTLE_ENDIAN) {
-            *revert =
-                is_upload ? REVERT_UPLOADING_1_5_5_5 :
-                REVERT_DOWNLOADING_1_5_5_5;
-        }
-        else
-            *revert = REVERT_NONE;
-        need_swap_rb = 1;
-        break;
-
-    case PICT_a1:
-        *tex_format = GL_ALPHA;
-        *tex_type = GL_UNSIGNED_BYTE;
-        *revert = is_upload ? REVERT_UPLOADING_A1 : REVERT_DOWNLOADING_A1;
-        break;
-
-    case PICT_a8:
-        *tex_format = GL_ALPHA;
-        *tex_type = GL_UNSIGNED_BYTE;
-        *revert = REVERT_NONE;
-        break;
-
-    case PICT_x4r4g4b4:
-        *no_alpha = 1;
-    case PICT_a4r4g4b4:
-        *tex_format = GL_RGBA;
-        *tex_type = GL_UNSIGNED_SHORT_4_4_4_4;
-        *revert = IS_LITTLE_ENDIAN ? REVERT_NORMAL : REVERT_NONE;
-        need_swap_rb = 1;
-        break;
-
-    case PICT_x4b4g4r4:
-        *no_alpha = 1;
-    case PICT_a4b4g4r4:
-        *tex_format = GL_RGBA;
-        *tex_type = GL_UNSIGNED_SHORT_4_4_4_4;
-        *revert = IS_LITTLE_ENDIAN ? REVERT_NORMAL : REVERT_NONE;
-        break;
-
-    default:
-        LogMessageVerb(X_INFO, 0,
-                       "fail to get matched format for %x \n", format);
-        return -1;
-    }
-
-    if (need_swap_rb)
-        *swap_rb = is_upload ? SWAP_UPLOADING : SWAP_DOWNLOADING;
-    else
-        *swap_rb = is_upload ? SWAP_NONE_UPLOADING : SWAP_NONE_DOWNLOADING;
-    return 0;
-}
-
-static int
-glamor_get_tex_format_type_from_pixmap(PixmapPtr pixmap,
-                                       GLenum *format,
-                                       GLenum *type,
-                                       int *no_alpha,
-                                       int *revert, int *swap_rb, int is_upload)
-{
-    glamor_pixmap_private *pixmap_priv;
-    PictFormatShort pict_format;
-    glamor_screen_private *glamor_priv =
-        glamor_get_screen_private(pixmap->drawable.pScreen);
-
-    pixmap_priv = glamor_get_pixmap_private(pixmap);
-    if (GLAMOR_PIXMAP_PRIV_IS_PICTURE(pixmap_priv))
-        pict_format = pixmap_priv->picture->format;
-    else
-        pict_format = format_for_depth(pixmap->drawable.depth);
-
-    if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
-        return glamor_get_tex_format_type_from_pictformat_gl(pict_format,
-                                                             format, type,
-                                                             no_alpha,
-                                                             revert,
-                                                             swap_rb,
-                                                             is_upload);
-    } else {
-        return glamor_get_tex_format_type_from_pictformat_gles2(pict_format,
-                                                                format, type,
-                                                                no_alpha,
-                                                                revert,
-                                                                swap_rb,
-                                                                is_upload);
-    }
-}
-
-static void *
-_glamor_color_convert_a1_a8(void *src_bits, void *dst_bits, int w, int h,
-                            int stride, int revert)
-{
-    PictFormatShort dst_format, src_format;
-    pixman_image_t *dst_image;
-    pixman_image_t *src_image;
-    int src_stride;
-
-    if (revert == REVERT_UPLOADING_A1) {
-        src_format = PICT_a1;
-        dst_format = PICT_a8;
-        src_stride = PixmapBytePad(w, 1);
-    }
-    else {
-        dst_format = PICT_a1;
-        src_format = PICT_a8;
-        src_stride = (((w * 8 + 7) / 8) + 3) & ~3;
-    }
-
-    dst_image = pixman_image_create_bits(dst_format, w, h, dst_bits, stride);
-    if (dst_image == NULL) {
-        return NULL;
-    }
-
-    src_image = pixman_image_create_bits(src_format,
-                                         w, h, src_bits, src_stride);
-
-    if (src_image == NULL) {
-        pixman_image_unref(dst_image);
-        return NULL;
-    }
-
-    pixman_image_composite(PictOpSrc, src_image, NULL, dst_image,
-                           0, 0, 0, 0, 0, 0, w, h);
-
-    pixman_image_unref(src_image);
-    pixman_image_unref(dst_image);
-    return dst_bits;
-}
-
-#define ADJUST_BITS(d, src_bits, dst_bits)	(((dst_bits) == (src_bits)) ? (d) : 				\
-							(((dst_bits) > (src_bits)) ? 				\
-							  (((d) << ((dst_bits) - (src_bits))) 			\
-								   + (( 1 << ((dst_bits) - (src_bits))) >> 1))	\
-								:  ((d) >> ((src_bits) - (dst_bits)))))
-
-#define GLAMOR_DO_CONVERT(src, dst, no_alpha, swap,		\
-			  a_shift_src, a_bits_src,		\
-			  b_shift_src, b_bits_src,		\
-			  g_shift_src, g_bits_src,		\
-			  r_shift_src, r_bits_src,		\
-			  a_shift, a_bits,			\
-			  b_shift, b_bits,			\
-			  g_shift, g_bits,			\
-			  r_shift, r_bits)			\
-	do {								\
-		typeof(src) a,b,g,r;					\
-		typeof(src) a_mask_src, b_mask_src, g_mask_src, r_mask_src;\
-		a_mask_src = (((1 << (a_bits_src)) - 1) << a_shift_src);\
-		b_mask_src = (((1 << (b_bits_src)) - 1) << b_shift_src);\
-		g_mask_src = (((1 << (g_bits_src)) - 1) << g_shift_src);\
-		r_mask_src = (((1 << (r_bits_src)) - 1) << r_shift_src);\
-		if (no_alpha)						\
-			a = (a_mask_src) >> (a_shift_src);			\
-		else							\
-			a = ((src) & (a_mask_src)) >> (a_shift_src);	\
-		b = ((src) & (b_mask_src)) >> (b_shift_src);		\
-		g = ((src) & (g_mask_src)) >> (g_shift_src);		\
-		r = ((src) & (r_mask_src)) >> (r_shift_src);		\
-		a = ADJUST_BITS(a, a_bits_src, a_bits);			\
-		b = ADJUST_BITS(b, b_bits_src, b_bits);			\
-		g = ADJUST_BITS(g, g_bits_src, g_bits);			\
-		r = ADJUST_BITS(r, r_bits_src, r_bits);			\
-		if (swap == 0)						\
-			(*dst) = ((a) << (a_shift)) | ((b) << (b_shift)) | ((g) << (g_shift)) | ((r) << (r_shift)); \
-		else 												    \
-			(*dst) = ((a) << (a_shift)) | ((r) << (b_shift)) | ((g) << (g_shift)) | ((b) << (r_shift)); \
-	} while (0)
-
-static void *
-_glamor_color_revert_x2b10g10r10(void *src_bits, void *dst_bits, int w, int h,
-                                 int stride, int no_alpha, int revert,
-                                 int swap_rb)
-{
-    int x, y;
-    unsigned int *words, *saved_words, *source_words;
-    int swap = !(swap_rb == SWAP_NONE_DOWNLOADING ||
-                 swap_rb == SWAP_NONE_UPLOADING);
-
-    source_words = src_bits;
-    words = dst_bits;
-    saved_words = words;
-
-    for (y = 0; y < h; y++) {
-        DEBUGF("Line %d :  ", y);
-        for (x = 0; x < w; x++) {
-            unsigned int pixel = source_words[x];
-
-            if (revert == REVERT_DOWNLOADING_2_10_10_10)
-                GLAMOR_DO_CONVERT(pixel, &words[x], no_alpha, swap,
-                                  24, 8, 16, 8, 8, 8, 0, 8,
-                                  30, 2, 20, 10, 10, 10, 0, 10);
-            else
-                GLAMOR_DO_CONVERT(pixel, &words[x], no_alpha, swap,
-                                  30, 2, 20, 10, 10, 10, 0, 10,
-                                  24, 8, 16, 8, 8, 8, 0, 8);
-            DEBUGF("%x:%x ", pixel, words[x]);
-        }
-        DEBUGF("\n");
-        words += stride / sizeof(*words);
-        source_words += stride / sizeof(*words);
-    }
-    DEBUGF("\n");
-    return saved_words;
-
-}
-
-static void *
-_glamor_color_revert_x1b5g5r5(void *src_bits, void *dst_bits, int w, int h,
-                              int stride, int no_alpha, int revert, int swap_rb)
-{
-    int x, y;
-    unsigned short *words, *saved_words, *source_words;
-    int swap = !(swap_rb == SWAP_NONE_DOWNLOADING ||
-                 swap_rb == SWAP_NONE_UPLOADING);
-
-    words = dst_bits;
-    source_words = src_bits;
-    saved_words = words;
-
-    for (y = 0; y < h; y++) {
-        DEBUGF("Line %d :  ", y);
-        for (x = 0; x < w; x++) {
-            unsigned short pixel = source_words[x];
-
-            if (revert == REVERT_DOWNLOADING_1_5_5_5)
-                GLAMOR_DO_CONVERT(pixel, &words[x], no_alpha, swap,
-                                  0, 1, 1, 5, 6, 5, 11, 5,
-                                  15, 1, 10, 5, 5, 5, 0, 5);
-            else
-                GLAMOR_DO_CONVERT(pixel, &words[x], no_alpha, swap,
-                                  15, 1, 10, 5, 5, 5, 0, 5,
-                                  0, 1, 1, 5, 6, 5, 11, 5);
-            DEBUGF("%04x:%04x ", pixel, words[x]);
-        }
-        DEBUGF("\n");
-        words += stride / sizeof(*words);
-        source_words += stride / sizeof(*words);
-    }
-    DEBUGF("\n");
-    return saved_words;
-}
-
-/*
- * This function is to convert an unsupported color format to/from a
- * supported GL format.
- * Here are the current scenarios:
- *
- * @no_alpha:
- * 	If it is set, then we need to wire the alpha value to 1.
- * @revert:
-	REVERT_DOWNLOADING_A1		: convert an Alpha8 buffer to a A1 buffer.
-	REVERT_UPLOADING_A1		: convert an A1 buffer to an Alpha8 buffer
-	REVERT_DOWNLOADING_2_10_10_10 	: convert r10G10b10X2 to X2B10G10R10
-	REVERT_UPLOADING_2_10_10_10 	: convert X2B10G10R10 to R10G10B10X2
-	REVERT_DOWNLOADING_1_5_5_5  	: convert B5G5R5X1 to X1R5G5B5
-	REVERT_UPLOADING_1_5_5_5    	: convert X1R5G5B5 to B5G5R5X1
-   @swap_rb: if we have the swap_rb set, then we need to swap the R and B's position.
- *
- */
-
-static void *
-glamor_color_convert_to_bits(void *src_bits, void *dst_bits, int w, int h,
-                             int stride, int no_alpha, int revert, int swap_rb)
-{
-    if (revert == REVERT_DOWNLOADING_A1 || revert == REVERT_UPLOADING_A1) {
-        return _glamor_color_convert_a1_a8(src_bits, dst_bits, w, h, stride,
-                                           revert);
-    }
-    else if (revert == REVERT_DOWNLOADING_2_10_10_10 ||
-             revert == REVERT_UPLOADING_2_10_10_10) {
-        return _glamor_color_revert_x2b10g10r10(src_bits, dst_bits, w, h,
-                                                stride, no_alpha, revert,
-                                                swap_rb);
-    }
-    else if (revert == REVERT_DOWNLOADING_1_5_5_5 ||
-             revert == REVERT_UPLOADING_1_5_5_5) {
-        return _glamor_color_revert_x1b5g5r5(src_bits, dst_bits, w, h, stride,
-                                             no_alpha, revert, swap_rb);
-    }
-    else
-        ErrorF("convert a non-supported mode %x.\n", revert);
-
-    return NULL;
-}
-
-/**
- * Upload pixmap to a specified texture.
- * This texture may not be the one attached to it.
- **/
-static void
-__glamor_upload_pixmap_to_texture(PixmapPtr pixmap, unsigned int *tex,
-                                  GLenum format,
-                                  GLenum type,
-                                  int x, int y, int w, int h,
-                                  void *bits, int pbo)
-{
-    glamor_screen_private *glamor_priv =
-        glamor_get_screen_private(pixmap->drawable.pScreen);
-    int non_sub = 0;
-    unsigned int iformat = 0;
-
-    glamor_make_current(glamor_priv);
-    if (*tex == 0) {
-        glGenTextures(1, tex);
-        if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP)
-            iformat = gl_iformat_for_pixmap(pixmap);
-        else
-            iformat = format;
-        non_sub = 1;
-        assert(x == 0 && y == 0);
-    }
-
-    glBindTexture(GL_TEXTURE_2D, *tex);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-    glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
-
-    assert(pbo || bits != 0);
-    if (bits == NULL) {
-        glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
-        glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
-    }
-    if (non_sub)
-        glTexImage2D(GL_TEXTURE_2D, 0, iformat, w, h, 0, format, type, bits);
-    else
-        glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, format, type, bits);
-
-    if (bits == NULL)
-        glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
-}
-
-static Bool
-_glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format,
-                                      GLenum type, int no_alpha, int revert,
-                                      int swap_rb, int x, int y, int w, int h,
-                                      int stride, void *bits, int pbo)
-{
-    ScreenPtr screen = pixmap->drawable.pScreen;
-    glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
-    glamor_screen_private *glamor_priv =
-        glamor_get_screen_private(pixmap->drawable.pScreen);
-    static float vertices[8];
-
-    static float texcoords_inv[8] = { 0, 0,
-        1, 0,
-        1, 1,
-        0, 1
-    };
-    float *ptexcoords;
-    float dst_xscale, dst_yscale;
-    GLuint tex = 0;
-    int need_free_bits = 0;
-
-    if (bits == NULL)
-        goto ready_to_upload;
-
-    if (revert > REVERT_NORMAL) {
-        /* XXX if we are restoring the pixmap, then we may not need to allocate
-         * new buffer */
-        void *converted_bits;
-
-        if (pixmap->drawable.depth == 1)
-            stride = (((w * 8 + 7) / 8) + 3) & ~3;
-
-        converted_bits = xallocarray(h, stride);
-
-        if (converted_bits == NULL)
-            return FALSE;
-        bits = glamor_color_convert_to_bits(bits, converted_bits, w, h,
-                                            stride, no_alpha, revert, swap_rb);
-        if (bits == NULL) {
-            free(converted_bits);
-            ErrorF("Failed to convert pixmap no_alpha %d,"
-                   "revert mode %d, swap mode %d\n", no_alpha, revert, swap_rb);
-            return FALSE;
-        }
-        no_alpha = 0;
-        revert = REVERT_NONE;
-        swap_rb = SWAP_NONE_UPLOADING;
-        need_free_bits = TRUE;
-    }
-
- ready_to_upload:
-
-    /* Try fast path firstly, upload the pixmap to the texture attached
-     * to the fbo directly. */
-    if (no_alpha == 0
-        && revert == REVERT_NONE && swap_rb == SWAP_NONE_UPLOADING
-#ifdef WALKAROUND_LARGE_TEXTURE_MAP
-        && glamor_pixmap_priv_is_small(pixmap_priv)
-#endif
-        ) {
-        int fbo_x_off, fbo_y_off;
-
-        assert(pixmap_priv->fbo->tex);
-        pixmap_priv_get_fbo_off(pixmap_priv, &fbo_x_off, &fbo_y_off);
-
-        assert(x + fbo_x_off >= 0 && y + fbo_y_off >= 0);
-        assert(x + fbo_x_off + w <= pixmap_priv->fbo->width);
-        assert(y + fbo_y_off + h <= pixmap_priv->fbo->height);
-        __glamor_upload_pixmap_to_texture(pixmap, &pixmap_priv->fbo->tex,
-                                          format, type,
-                                          x + fbo_x_off, y + fbo_y_off, w, h,
-                                          bits, pbo);
-    } else {
-        ptexcoords = texcoords_inv;
-
-        pixmap_priv_get_dest_scale(pixmap, pixmap_priv, &dst_xscale, &dst_yscale);
-        glamor_set_normalize_vcoords(pixmap_priv, dst_xscale,
-                                     dst_yscale,
-                                     x, y,
-                                     x + w, y + h,
-                                     vertices);
-        /* Slow path, we need to flip y or wire alpha to 1. */
-        glamor_make_current(glamor_priv);
-        glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT,
-                              GL_FALSE, 2 * sizeof(float), vertices);
-        glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
-        glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, GL_FLOAT,
-                              GL_FALSE, 2 * sizeof(float), ptexcoords);
-        glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
-
-        glamor_set_destination_pixmap_priv_nc(glamor_priv, pixmap, pixmap_priv);
-        glamor_set_alu(screen, GXcopy);
-        __glamor_upload_pixmap_to_texture(pixmap, &tex,
-                                          format, type, 0, 0, w, h, bits, pbo);
-        glActiveTexture(GL_TEXTURE0);
-        glBindTexture(GL_TEXTURE_2D, tex);
-
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-        glUseProgram(glamor_priv->finish_access_prog[no_alpha]);
-        glUniform1i(glamor_priv->finish_access_revert[no_alpha], revert);
-        glUniform1i(glamor_priv->finish_access_swap_rb[no_alpha], swap_rb);
-
-        glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
-
-        glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
-        glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
-        glDeleteTextures(1, &tex);
-        glBindFramebuffer(GL_FRAMEBUFFER, 0);
-    }
-
-    if (need_free_bits)
-        free(bits);
-    return TRUE;
-}
-
-/*
- * Prepare to upload a pixmap to texture memory.
- * no_alpha equals 1 means the format needs to wire alpha to 1.
- */
-static int
-glamor_pixmap_upload_prepare(PixmapPtr pixmap, GLenum format, int no_alpha,
-                             int revert, int swap_rb)
-{
-    int flag = 0;
-    glamor_pixmap_private *pixmap_priv;
-    glamor_screen_private *glamor_priv;
-    glamor_pixmap_fbo *fbo;
-    GLenum iformat;
-
-    pixmap_priv = glamor_get_pixmap_private(pixmap);
-    glamor_priv = glamor_get_screen_private(pixmap->drawable.pScreen);
-
-    if (pixmap_priv->gl_fbo != GLAMOR_FBO_UNATTACHED)
-        return 0;
-
-    if (pixmap_priv->fbo
-        && (pixmap_priv->fbo->width < pixmap->drawable.width
-            || pixmap_priv->fbo->height < pixmap->drawable.height)) {
-        fbo = glamor_pixmap_detach_fbo(pixmap_priv);
-        glamor_destroy_fbo(glamor_priv, fbo);
-    }
-
-    if (pixmap_priv->fbo && pixmap_priv->fbo->fb)
-        return 0;
-
-    if (!(no_alpha || (revert == REVERT_NORMAL)
-          || (swap_rb != SWAP_NONE_UPLOADING))) {
-        /* We don't need a fbo, a simple texture uploading should work. */
-
-        flag = GLAMOR_CREATE_FBO_NO_FBO;
-    }
-
-    if ((flag == GLAMOR_CREATE_FBO_NO_FBO
-         && pixmap_priv->fbo && pixmap_priv->fbo->tex))
-        return 0;
-
-    if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP)
-        iformat = gl_iformat_for_pixmap(pixmap);
-    else
-        iformat = format;
-
-    if (!glamor_pixmap_ensure_fbo(pixmap, iformat, flag))
-        return -1;
-
-    return 0;
-}
-
-/*
- * upload sub region to a large region.
- * */
-static void
-glamor_put_bits(char *dst_bits, int dst_stride, char *src_bits,
-                int src_stride, int bpp, int x, int y, int w, int h)
-{
-    int j;
-    int byte_per_pixel;
-
-    byte_per_pixel = bpp / 8;
-    src_bits += y * src_stride + (x * byte_per_pixel);
-
-    for (j = y; j < y + h; j++) {
-        memcpy(dst_bits, src_bits, w * byte_per_pixel);
-        src_bits += src_stride;
-        dst_bits += dst_stride;
-    }
-}
-
-static Bool
-glamor_upload_sub_pixmap_to_texture(PixmapPtr pixmap, int x, int y, int w,
-                                    int h, int stride, void *bits, int pbo)
-{
-    ScreenPtr screen = pixmap->drawable.pScreen;
-    glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
-    GLenum format, type;
-    int no_alpha, revert, swap_rb;
-    glamor_pixmap_private *pixmap_priv;
-    Bool force_clip;
-
-    if (glamor_get_tex_format_type_from_pixmap(pixmap,
-                                               &format,
-                                               &type,
-                                               &no_alpha,
-                                               &revert, &swap_rb, 1)) {
-        glamor_fallback("Unknown pixmap depth %d.\n", pixmap->drawable.depth);
-        return FALSE;
-    }
-    if (glamor_pixmap_upload_prepare(pixmap, format, no_alpha, revert, swap_rb))
-        return FALSE;
-
-    pixmap_priv = glamor_get_pixmap_private(pixmap);
-    force_clip = glamor_priv->gl_flavor != GLAMOR_GL_DESKTOP
-        && !glamor_check_fbo_size(glamor_priv, w, h);
-
-    if (glamor_pixmap_priv_is_large(pixmap_priv) || force_clip) {
-        RegionRec region;
-        BoxRec box;
-        int n_region;
-        glamor_pixmap_clipped_regions *clipped_regions;
-        void *sub_bits;
-        int i, j;
-
-        sub_bits = xallocarray(h, stride);
-        if (sub_bits == NULL)
-            return FALSE;
-        box.x1 = x;
-        box.y1 = y;
-        box.x2 = x + w;
-        box.y2 = y + h;
-        RegionInitBoxes(&region, &box, 1);
-        if (!force_clip)
-            clipped_regions =
-                glamor_compute_clipped_regions(pixmap, &region, &n_region,
-                                               0, 0, 0);
-        else
-            clipped_regions =
-                glamor_compute_clipped_regions_ext(pixmap, &region,
-                                                   &n_region,
-                                                   pixmap_priv->block_w,
-                                                   pixmap_priv->block_h,
-                                                   0,
-                                                   0);
-        DEBUGF("prepare upload %dx%d to a large pixmap %p\n", w, h, pixmap);
-        for (i = 0; i < n_region; i++) {
-            BoxPtr boxes;
-            int nbox;
-            int temp_stride;
-            void *temp_bits;
-
-            assert(pbo == 0);
-
-            glamor_set_pixmap_fbo_current(pixmap_priv, clipped_regions[i].block_idx);
-
-            boxes = RegionRects(clipped_regions[i].region);
-            nbox = RegionNumRects(clipped_regions[i].region);
-            DEBUGF("split to %d boxes\n", nbox);
-            for (j = 0; j < nbox; j++) {
-                temp_stride = PixmapBytePad(boxes[j].x2 - boxes[j].x1,
-                                            pixmap->drawable.depth);
-
-                if (boxes[j].x1 == x && temp_stride == stride) {
-                    temp_bits = (char *) bits + (boxes[j].y1 - y) * stride;
-                }
-                else {
-                    temp_bits = sub_bits;
-                    glamor_put_bits(temp_bits, temp_stride, bits, stride,
-                                    pixmap->drawable.bitsPerPixel,
-                                    boxes[j].x1 - x, boxes[j].y1 - y,
-                                    boxes[j].x2 - boxes[j].x1,
-                                    boxes[j].y2 - boxes[j].y1);
-                }
-                DEBUGF("upload x %d y %d w %d h %d temp stride %d \n",
-                       boxes[j].x1 - x, boxes[j].y1 - y,
-                       boxes[j].x2 - boxes[j].x1,
-                       boxes[j].y2 - boxes[j].y1, temp_stride);
-                if (_glamor_upload_bits_to_pixmap_texture
-                    (pixmap, format, type, no_alpha, revert, swap_rb,
-                     boxes[j].x1, boxes[j].y1, boxes[j].x2 - boxes[j].x1,
-                     boxes[j].y2 - boxes[j].y1, temp_stride, temp_bits,
-                     pbo) == FALSE) {
-                    RegionUninit(&region);
-                    free(sub_bits);
-                    assert(0);
-                    return FALSE;
-                }
-            }
-            RegionDestroy(clipped_regions[i].region);
-        }
-        free(sub_bits);
-        free(clipped_regions);
-        RegionUninit(&region);
-        return TRUE;
-    }
-    else
-        return _glamor_upload_bits_to_pixmap_texture(pixmap, format, type,
-                                                     no_alpha, revert, swap_rb,
-                                                     x, y, w, h, stride, bits,
-                                                     pbo);
-}
-
-enum glamor_pixmap_status
-glamor_upload_pixmap_to_texture(PixmapPtr pixmap)
-{
-    int ret;
-
-    if (glamor_upload_sub_pixmap_to_texture(pixmap, 0, 0,
-                                            pixmap->drawable.width,
-                                            pixmap->drawable.height,
-                                            pixmap->devKind,
-                                            pixmap->devPrivate.ptr, 0))
-        ret = GLAMOR_UPLOAD_DONE;
-    else
-        ret = GLAMOR_UPLOAD_FAILED;
-
-    return ret;
-}
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index 508433a..2792afa 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -701,13 +701,6 @@ glamor_put_vbo_space(ScreenPtr screen);
  */
 Bool glamor_pixmap_ensure_fbo(PixmapPtr pixmap, GLenum format, int flag);
 
-/**
- * Upload a pixmap to gl texture. Used by dynamic pixmap
- * uploading feature. The pixmap must be a software pixmap.
- * This function will change current FBO and current shaders.
- */
-enum glamor_pixmap_status glamor_upload_pixmap_to_texture(PixmapPtr pixmap);
-
 glamor_pixmap_clipped_regions *
 glamor_compute_clipped_regions(PixmapPtr pixmap,
                                RegionPtr region, int *clipped_nbox,
commit 53aed06fb45aed4145754cd622508563ad262c4a
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jul 2 12:48:01 2015 -0700

    glamor: Drop dead glamor_upload_bits_to_pixmap_texture() proto.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index 1614b6f..508433a 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -741,15 +741,6 @@ Bool glamor_composite_largepixmap_region(CARD8 op,
  **/
 enum glamor_pixmap_status glamor_upload_picture_to_texture(PicturePtr picture);
 
-/**
- * Upload bits to a pixmap's texture. This function will
- * convert the bits to the specified format/type format
- * if the conversion is unavoidable.
- **/
-Bool glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format,
-                                          GLenum type, int no_alpha, int revert,
-                                          int swap_rb, void *bits);
-
 int glamor_create_picture(PicturePtr picture);
 
 void glamor_set_window_pixmap(WindowPtr pWindow, PixmapPtr pPixmap);
commit b51e079e1877411fde72372c3953d71e42ac1d6e
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jul 2 12:40:05 2015 -0700

    glamor: Use the new upload/download interface for XV uploads.
    
    We don't need any of its weird handling of picture formats, since our
    XV pixmaps don't have any pictures attached.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/glamor/glamor_pixmap.c b/glamor/glamor_pixmap.c
index 9a14527..5a09d32 100644
--- a/glamor/glamor_pixmap.c
+++ b/glamor/glamor_pixmap.c
@@ -931,7 +931,7 @@ glamor_put_bits(char *dst_bits, int dst_stride, char *src_bits,
     }
 }
 
-Bool
+static Bool
 glamor_upload_sub_pixmap_to_texture(PixmapPtr pixmap, int x, int y, int w,
                                     int h, int stride, void *bits, int pbo)
 {
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index d085ff2..1614b6f 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -708,10 +708,6 @@ Bool glamor_pixmap_ensure_fbo(PixmapPtr pixmap, GLenum format, int flag);
  */
 enum glamor_pixmap_status glamor_upload_pixmap_to_texture(PixmapPtr pixmap);
 
-Bool glamor_upload_sub_pixmap_to_texture(PixmapPtr pixmap, int x, int y, int w,
-                                         int h, int stride, void *bits,
-                                         int pbo);
-
 glamor_pixmap_clipped_regions *
 glamor_compute_clipped_regions(PixmapPtr pixmap,
                                RegionPtr region, int *clipped_nbox,
diff --git a/glamor/glamor_xv.c b/glamor/glamor_xv.c
index 364104d..85e6528 100644
--- a/glamor/glamor_xv.c
+++ b/glamor/glamor_xv.c
@@ -37,6 +37,7 @@
 #endif
 
 #include "glamor_priv.h"
+#include "glamor_transfer.h"
 
 #include <X11/extensions/Xv.h>
 #include "../hw/xfree86/common/fourcc.h"
@@ -410,6 +411,7 @@ glamor_xv_put_image(glamor_port_private *port_priv,
     int srcPitch, srcPitch2;
     int top, nlines;
     int s2offset, s3offset, tmp;
+    BoxRec full_box, half_box;
 
     s2offset = s3offset = srcPitch2 = 0;
 
@@ -452,20 +454,28 @@ glamor_xv_put_image(glamor_port_private *port_priv,
             s2offset = s3offset;
             s3offset = tmp;
         }
-        glamor_upload_sub_pixmap_to_texture(port_priv->src_pix[0],
-                                            0, 0, width, nlines,
-                                            srcPitch,
-                                            buf + (top * srcPitch), 0);
-
-        glamor_upload_sub_pixmap_to_texture(port_priv->src_pix[1],
-                                            0, 0, width >> 1, (nlines + 1) >> 1,
-                                            srcPitch2,
-                                            buf + s2offset, 0);
-
-        glamor_upload_sub_pixmap_to_texture(port_priv->src_pix[2],
-                                            0, 0, width >> 1, (nlines + 1) >> 1,
-                                            srcPitch2,
-                                            buf + s3offset, 0);
+
+        full_box.x1 = 0;
+        full_box.y1 = 0;
+        full_box.x2 = width;
+        full_box.y2 = nlines;
+
+        half_box.x1 = 0;
+        half_box.y1 = 0;
+        half_box.x2 = width >> 1;
+        half_box.y2 = (nlines + 1) >> 1;
+
+        glamor_upload_boxes(port_priv->src_pix[0], &full_box, 1,
+                            0, 0, 0, 0,
+                            buf + (top * srcPitch), srcPitch);
+
+        glamor_upload_boxes(port_priv->src_pix[1], &half_box, 1,
+                            0, 0, 0, 0,
+                            buf + s2offset, srcPitch2);
+
+        glamor_upload_boxes(port_priv->src_pix[2], &half_box, 1,
+                            0, 0, 0, 0,
+                            buf + s3offset, srcPitch2);
         break;
     default:
         return BadMatch;
commit 1bd966d16d87ed908547144c68850f2cdee05469
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jul 2 12:21:41 2015 -0700

    glamor: Ignore picture formats when choosing color for core rendering.
    
    Attaching a picture to a pixmap doesn't change its GL format, so it
    doesn't change how core rendering should be assigning colors to it.
    
    (Imagine XCreatePixmap(), optional XCreatePicture(pixmap) with various
    formats, XFillRectangle, XGetImage().  If the XGetImage results
    changed, this would be wrong).
    
    Fixes all failures in "rendercheck -t fill" and, as a result, the
    remaining failures in "rendercheck -t blend -o src -f
    a8r8g8b8,x2r10g10b10"
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/glamor/glamor_utils.h b/glamor/glamor_utils.h
index a923b7a..8182006 100644
--- a/glamor/glamor_utils.h
+++ b/glamor/glamor_utils.h
@@ -805,16 +805,7 @@ gl_iformat_for_pixmap(PixmapPtr pixmap)
 static inline CARD32
 format_for_pixmap(PixmapPtr pixmap)
 {
-    glamor_pixmap_private *pixmap_priv;
-    PictFormatShort pict_format;
-
-    pixmap_priv = glamor_get_pixmap_private(pixmap);
-    if (GLAMOR_PIXMAP_PRIV_IS_PICTURE(pixmap_priv))
-        pict_format = pixmap_priv->picture->format;
-    else
-        pict_format = format_for_depth((pixmap)->drawable.depth);
-
-    return pict_format;
+    return format_for_depth((pixmap)->drawable.depth);
 }
 
 #define REVERT_NONE       		0
commit 5a81de8284f851751a8943aa6a905377be315c7b
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Jul 8 12:18:28 2015 -0700

    glamor: Don't try to do rendering with unsupported formats.
    
    I'm amazed we've made it as far as we have without these checks: if
    you made an unusual format picture that wasn't the normal a8r8g8b8 or
    x8r8g8b8 or a8, we'd go ahead and try to render with it, ignoring that
    the sampler would fetch totally wrong bits.
    
    Fixes 260 tests in rendercheck -t blend -o src -f a8r8g8b8,x2r10g10b10
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/glamor/glamor_render.c b/glamor/glamor_render.c
index 488d1a7..3048cd8 100644
--- a/glamor/glamor_render.c
+++ b/glamor/glamor_render.c
@@ -753,6 +753,29 @@ glamor_set_normalize_tcoords_generic(PixmapPtr pixmap,
                                                             texcoords, stride);
 }
 
+/**
+ * Returns whether the general composite path supports this picture
+ * format for a pixmap that is permanently stored in an FBO (as
+ * opposed to the GLAMOR_PIXMAP_DYNAMIC_UPLOAD path).
+ *
+ * We could support many more formats by using GL_ARB_texture_view to
+ * parse the same bits as different formats.  For now, we only support
+ * tweaking whether we sample the alpha bits of an a8r8g8b8, or just
+ * force them to 1.
+ */
+static Bool
+glamor_render_format_is_supported(PictFormatShort format)
+{
+    switch (format) {
+    case PICT_a8r8g8b8:
+    case PICT_x8r8g8b8:
+    case PICT_a8:
+        return TRUE;
+    default:
+        return FALSE;
+    }
+}
+
 static Bool
 glamor_composite_choose_shader(CARD8 op,
                                PicturePtr source,
@@ -783,6 +806,11 @@ glamor_composite_choose_shader(CARD8 op,
         goto fail;
     }
 
+    if (!glamor_render_format_is_supported(dest->format)) {
+        glamor_fallback("Unsupported dest picture format.\n");
+        goto fail;
+    }
+
     memset(&key, 0, sizeof(key));
     if (!source) {
         key.source = SHADER_SOURCE_SOLID;
@@ -951,6 +979,11 @@ glamor_composite_choose_shader(CARD8 op,
                 glamor_fallback("Failed to upload source texture.\n");
                 goto fail;
             }
+        } else {
+            if (!glamor_render_format_is_supported(source->format)) {
+                glamor_fallback("Unsupported source picture format.\n");
+                goto fail;
+            }
         }
 
         if (mask_status == GLAMOR_UPLOAD_PENDING) {
@@ -959,6 +992,11 @@ glamor_composite_choose_shader(CARD8 op,
                 glamor_fallback("Failed to upload mask texture.\n");
                 goto fail;
             }
+        } else if (mask) {
+            if (!glamor_render_format_is_supported(mask->format)) {
+                glamor_fallback("Unsupported mask picture format.\n");
+                goto fail;
+            }
         }
     }
 #endif
commit 0d7cbd6f5a2b5c9c690979da9c1483e8f6133903
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Fri Jul 3 20:42:48 2015 +0200

    glamor_egl: Properly free resources on init-error and exit
    
    glamor_egl_init() was not undoing any of the init steps on init error,
    add an glamor_egl_cleanup() function and use this both on error and on exit
    to cleanup the various resources.
    
    Even on a clean exit eglTerminate() was not being called, causing the fd
    dup()-ed by eglInitialize() to stay open, call eglTerminate() from the new
    glamor_egl_cleanup() to fix this.
    
    Signed-off-by: Hans de Goede <hdegoede at redhat.com>
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Eric Anholt <eric at anholt.net>

diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
index 753fb34..8ff1d03 100644
--- a/glamor/glamor_egl.c
+++ b/glamor/glamor_egl.c
@@ -766,6 +766,21 @@ glamor_egl_screen_init(ScreenPtr screen, struct glamor_context *glamor_ctx)
 #endif
 }
 
+static void glamor_egl_cleanup(struct glamor_egl_screen_private *glamor_egl)
+{
+    if (glamor_egl->display != EGL_NO_DISPLAY) {
+        eglMakeCurrent(glamor_egl->display,
+                       EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+        eglTerminate(glamor_egl->display);
+    }
+#ifdef GLAMOR_HAS_GBM
+    if (glamor_egl->gbm)
+        gbm_device_destroy(glamor_egl->gbm);
+#endif
+    free(glamor_egl->device_path);
+    free(glamor_egl);
+}
+
 static void
 glamor_egl_free_screen(ScrnInfoPtr scrn)
 {
@@ -773,17 +788,8 @@ glamor_egl_free_screen(ScrnInfoPtr scrn)
 
     glamor_egl = glamor_egl_get_screen_private(scrn);
     if (glamor_egl != NULL) {
-
-        eglMakeCurrent(glamor_egl->display,
-                       EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
-#ifdef GLAMOR_HAS_GBM
-        if (glamor_egl->gbm)
-            gbm_device_destroy(glamor_egl->gbm);
-#endif
-        free(glamor_egl->device_path);
-
         scrn->FreeScreen = glamor_egl->saved_free_screen;
-        free(glamor_egl);
+        glamor_egl_cleanup(glamor_egl);
         scrn->FreeScreen(scrn);
     }
 }
@@ -814,7 +820,7 @@ glamor_egl_init(ScrnInfoPtr scrn, int fd)
     glamor_egl->gbm = gbm_create_device(glamor_egl->fd);
     if (glamor_egl->gbm == NULL) {
         ErrorF("couldn't get display device\n");
-        return FALSE;
+        goto error;
     }
     glamor_egl->display = eglGetDisplay(glamor_egl->gbm);
 #else
@@ -831,7 +837,8 @@ glamor_egl_init(ScrnInfoPtr scrn, int fd)
     if (!eglInitialize
         (glamor_egl->display, &glamor_egl->major, &glamor_egl->minor)) {
         xf86DrvMsg(scrn->scrnIndex, X_ERROR, "eglInitialize() failed\n");
-        return FALSE;
+        glamor_egl->display = EGL_NO_DISPLAY;
+        goto error;
     }
 
     version = eglQueryString(glamor_egl->display, EGL_VERSION);
@@ -840,14 +847,14 @@ glamor_egl_init(ScrnInfoPtr scrn, int fd)
 #define GLAMOR_CHECK_EGL_EXTENSION(EXT)  \
 	if (!epoxy_has_egl_extension(glamor_egl->display, "EGL_" #EXT)) {  \
 		ErrorF("EGL_" #EXT " required.\n");  \
-		return FALSE;  \
+		goto error;  \
 	}
 
 #define GLAMOR_CHECK_EGL_EXTENSIONS(EXT1, EXT2)	 \
 	if (!epoxy_has_egl_extension(glamor_egl->display, "EGL_" #EXT1) &&  \
 	    !epoxy_has_egl_extension(glamor_egl->display, "EGL_" #EXT2)) {  \
 		ErrorF("EGL_" #EXT1 " or EGL_" #EXT2 " required.\n");  \
-		return FALSE;  \
+		goto error;  \
 	}
 
     GLAMOR_CHECK_EGL_EXTENSION(MESA_drm_image);
@@ -872,14 +879,14 @@ glamor_egl_init(ScrnInfoPtr scrn, int fd)
                                            config_attribs);
     if (glamor_egl->context == EGL_NO_CONTEXT) {
         xf86DrvMsg(scrn->scrnIndex, X_ERROR, "Failed to create EGL context\n");
-        return FALSE;
+        goto error;
     }
 
     if (!eglMakeCurrent(glamor_egl->display,
                         EGL_NO_SURFACE, EGL_NO_SURFACE, glamor_egl->context)) {
         xf86DrvMsg(scrn->scrnIndex, X_ERROR,
                    "Failed to make EGL context current\n");
-        return FALSE;
+        goto error;
     }
     glamor_egl->saved_free_screen = scrn->FreeScreen;
     scrn->FreeScreen = glamor_egl_free_screen;
@@ -890,6 +897,10 @@ glamor_egl_init(ScrnInfoPtr scrn, int fd)
                "Indirect GLX may not work correctly.\n");
 #endif
     return TRUE;
+
+error:
+    glamor_egl_cleanup(glamor_egl);
+    return FALSE;
 }
 
 /** Stub to retain compatibility with pre-server-1.16 ABI. */
commit 80b6652c9fb9cdff91e92fa16c07e2cc63b06f44
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Jul 7 17:21:55 2015 -0700

    glamor: Drop a bunch of glamor_priv == NULL checks.
    
    Now that it's always non-null when the pixmap is non-null, we don't
    need so much of this.  glamor_get_pixmap_private() itself still
    accepts a NULL pixmap and returns NULL, because of glamor_render.c
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/glamor/glamor.c b/glamor/glamor.c
index 2470a8d..04c548d 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -207,13 +207,10 @@ void
 glamor_destroy_textured_pixmap(PixmapPtr pixmap)
 {
     if (pixmap->refcnt == 1) {
-        glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
-        if (pixmap_priv != NULL) {
 #if GLAMOR_HAS_GBM
-            glamor_egl_destroy_pixmap_image(pixmap);
+        glamor_egl_destroy_pixmap_image(pixmap);
 #endif
-            glamor_pixmap_destroy_fbo(pixmap);
-        }
+        glamor_pixmap_destroy_fbo(pixmap);
     }
 }
 
@@ -761,12 +758,11 @@ _X_EXPORT int
 glamor_fd_from_pixmap(ScreenPtr screen,
                       PixmapPtr pixmap, CARD16 *stride, CARD32 *size)
 {
-    glamor_pixmap_private *pixmap_priv;
+    glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
     glamor_screen_private *glamor_priv =
         glamor_get_screen_private(pixmap->drawable.pScreen);
 
-    pixmap_priv = glamor_get_pixmap_private(pixmap);
-    if (pixmap_priv == NULL || !glamor_priv->dri3_enabled)
+    if (!glamor_priv->dri3_enabled)
         return -1;
     switch (pixmap_priv->type) {
     case GLAMOR_TEXTURE_DRM:
@@ -786,12 +782,11 @@ glamor_fd_from_pixmap(ScreenPtr screen,
 int
 glamor_name_from_pixmap(PixmapPtr pixmap, CARD16 *stride, CARD32 *size)
 {
-    glamor_pixmap_private *pixmap_priv;
+    glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
     glamor_screen_private *glamor_priv =
         glamor_get_screen_private(pixmap->drawable.pScreen);
 
-    pixmap_priv = glamor_get_pixmap_private(pixmap);
-    if (pixmap_priv == NULL || !glamor_priv->dri3_enabled)
+    if (!glamor_priv->dri3_enabled)
         return -1;
     switch (pixmap_priv->type) {
     case GLAMOR_TEXTURE_DRM:
diff --git a/glamor/glamor_core.c b/glamor/glamor_core.c
index 79f5981b..0104b88 100644
--- a/glamor/glamor_core.c
+++ b/glamor/glamor_core.c
@@ -42,8 +42,7 @@ glamor_get_drawable_location(const DrawablePtr drawable)
     glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
     glamor_screen_private *glamor_priv =
         glamor_get_screen_private(drawable->pScreen);
-    if (pixmap_priv == NULL ||
-        pixmap_priv->gl_fbo == GLAMOR_FBO_UNATTACHED)
+    if (pixmap_priv->gl_fbo == GLAMOR_FBO_UNATTACHED)
         return 'm';
     if (pixmap_priv->fbo->fb == glamor_priv->screen_fbo)
         return 's';
diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
index e01f723..753fb34 100644
--- a/glamor/glamor_egl.c
+++ b/glamor/glamor_egl.c
@@ -452,7 +452,7 @@ glamor_gbm_bo_from_pixmap(ScreenPtr screen, PixmapPtr pixmap)
         glamor_get_pixmap_private(pixmap);
 
     pixmap_priv = glamor_get_pixmap_private(pixmap);
-    if (pixmap_priv == NULL || !glamor_priv->dri3_enabled)
+    if (!glamor_priv->dri3_enabled)
         return NULL;
     switch (pixmap_priv->type) {
     case GLAMOR_TEXTURE_DRM:
@@ -604,7 +604,7 @@ glamor_egl_destroy_pixmap_image(PixmapPtr pixmap)
     struct glamor_pixmap_private *pixmap_priv =
         glamor_get_pixmap_private(pixmap);
 
-    if (pixmap_priv && pixmap_priv->image) {
+    if (pixmap_priv->image) {
         ScrnInfoPtr scrn = xf86ScreenToScrn(pixmap->drawable.pScreen);
         struct glamor_egl_screen_private *glamor_egl =
             glamor_egl_get_screen_private(scrn);
diff --git a/glamor/glamor_picture.c b/glamor/glamor_picture.c
index 53b032c..20b9de2 100644
--- a/glamor/glamor_picture.c
+++ b/glamor/glamor_picture.c
@@ -61,15 +61,6 @@ glamor_create_picture(PicturePtr picture)
 
     pixmap = glamor_get_drawable_pixmap(picture->pDrawable);
     pixmap_priv = glamor_get_pixmap_private(pixmap);
-    if (!pixmap_priv) {
-        /* We must create a pixmap priv to track the picture format even
-         * if the pixmap is a pure in memory pixmap. The reason is that
-         * we may need to upload this pixmap to a texture on the fly. During
-         * the uploading, we need to know the picture format. */
-        glamor_set_pixmap_type(pixmap, GLAMOR_MEMORY);
-        pixmap_priv = glamor_get_pixmap_private(pixmap);
-    }
-
     pixmap_priv->is_picture = 1;
     pixmap_priv->picture = picture;
 
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index fe65d9b..d085ff2 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -419,7 +419,7 @@ glamor_pixmap_drm_only(PixmapPtr pixmap)
 {
     glamor_pixmap_private *priv = glamor_get_pixmap_private(pixmap);
 
-    return priv && priv->type == GLAMOR_DRM_ONLY;
+    return priv->type == GLAMOR_DRM_ONLY;
 }
 
 /*
@@ -430,7 +430,7 @@ glamor_pixmap_is_memory(PixmapPtr pixmap)
 {
     glamor_pixmap_private *priv = glamor_get_pixmap_private(pixmap);
 
-    return !priv || priv->type == GLAMOR_MEMORY;
+    return priv->type == GLAMOR_MEMORY;
 }
 
 /*
@@ -439,13 +439,13 @@ glamor_pixmap_is_memory(PixmapPtr pixmap)
 static inline Bool
 glamor_pixmap_priv_is_large(glamor_pixmap_private *priv)
 {
-    return priv && (priv->block_wcnt > 1 || priv->block_hcnt > 1);
+    return priv->block_wcnt > 1 || priv->block_hcnt > 1;
 }
 
 static inline Bool
 glamor_pixmap_priv_is_small(glamor_pixmap_private *priv)
 {
-    return priv && priv->block_wcnt <= 1 && priv->block_hcnt <= 1;
+    return priv->block_wcnt <= 1 && priv->block_hcnt <= 1;
 }
 
 static inline Bool
@@ -453,7 +453,7 @@ glamor_pixmap_is_large(PixmapPtr pixmap)
 {
     glamor_pixmap_private *priv = glamor_get_pixmap_private(pixmap);
 
-    return priv && glamor_pixmap_priv_is_large(priv);
+    return glamor_pixmap_priv_is_large(priv);
 }
 /*
  * Returns TRUE if pixmap has an FBO
@@ -463,7 +463,7 @@ glamor_pixmap_has_fbo(PixmapPtr pixmap)
 {
     glamor_pixmap_private *priv = glamor_get_pixmap_private(pixmap);
 
-    return priv && priv->gl_fbo == GLAMOR_FBO_NORMAL;
+    return priv->gl_fbo == GLAMOR_FBO_NORMAL;
 }
 
 static inline void
diff --git a/glamor/glamor_utils.h b/glamor/glamor_utils.h
index 0a7de82..a923b7a 100644
--- a/glamor/glamor_utils.h
+++ b/glamor/glamor_utils.h
@@ -756,8 +756,8 @@ glamor_translate_boxes(BoxPtr boxes, int nbox, int dx, int dy)
 						|| _depth_ == 30	\
 						|| _depth_ == 32)
 
-#define GLAMOR_PIXMAP_PRIV_IS_PICTURE(pixmap_priv) (pixmap_priv && pixmap_priv->is_picture == 1)
-#define GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv)    (pixmap_priv && pixmap_priv->gl_fbo == GLAMOR_FBO_NORMAL)
+#define GLAMOR_PIXMAP_PRIV_IS_PICTURE(pixmap_priv) (pixmap_priv->is_picture == 1)
+#define GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv)    (pixmap_priv->gl_fbo == GLAMOR_FBO_NORMAL)
 
 /**
  * Borrow from uxa.
commit a2a2f6e34bd49e7ae31779274d52e800595660bc
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Jun 30 16:20:18 2015 -0700

    glamor: Ask the server to always allocate our private.
    
    This avoids a lot of screwing around to attach our privates later.  It
    means that non-glamor pixmaps now gain 120 bytes of glamor privates on
    64-bit (which has quite a bit of fixable bloat), and glamor pixmaps
    take one less pointer of storage (not counting malloc overhead).
    
    Note that privates start out zero-filled, which matches the callocs we
    were doing when making our own privates, and in the case of an fb
    pixmap that has a priv where it didn't before, the type ends up being
    GLAMOR_MEMORY as we would want.
    
    v2: Clarify that the GLAMOR_MEMORY enum must be 0 (as it was
        previosuly), so that the new pixmap private behavior is as
        expected.  Suggested by keithp.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com> (v1)
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/glamor/glamor.c b/glamor/glamor.c
index 50d85ff..2470a8d 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -80,12 +80,7 @@ glamor_set_pixmap_type(PixmapPtr pixmap, glamor_pixmap_type_t type)
 {
     glamor_pixmap_private *pixmap_priv;
 
-    pixmap_priv = dixLookupPrivate(&pixmap->devPrivates,
-                                   &glamor_pixmap_private_key);
-    if (pixmap_priv == NULL) {
-        pixmap_priv = calloc(sizeof(*pixmap_priv), 1);
-        glamor_set_pixmap_private(pixmap, pixmap_priv);
-    }
+    pixmap_priv = glamor_get_pixmap_private(pixmap);
     pixmap_priv->type = type;
     glamor_init_pixmap_private_small(pixmap, pixmap_priv);
 }
@@ -171,13 +166,7 @@ glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth,
     else
         pixmap = fbCreatePixmap(screen, 0, 0, depth, usage);
 
-    pixmap_priv = calloc(1, sizeof(*pixmap_priv));
-
-    if (!pixmap_priv) {
-        fbDestroyPixmap(pixmap);
-        return fbCreatePixmap(screen, w, h, depth, usage);
-    }
-    glamor_set_pixmap_private(pixmap, pixmap_priv);
+    pixmap_priv = glamor_get_pixmap_private(pixmap);
 
     format = gl_iformat_for_pixmap(pixmap);
 
@@ -223,7 +212,7 @@ glamor_destroy_textured_pixmap(PixmapPtr pixmap)
 #if GLAMOR_HAS_GBM
             glamor_egl_destroy_pixmap_image(pixmap);
 #endif
-            glamor_set_pixmap_private(pixmap, NULL);
+            glamor_pixmap_destroy_fbo(pixmap);
         }
     }
 }
@@ -455,7 +444,8 @@ glamor_init(ScreenPtr screen, unsigned int flags)
 
     glamor_set_screen_private(screen, glamor_priv);
 
-    if (!dixRegisterPrivateKey(&glamor_pixmap_private_key, PRIVATE_PIXMAP, 0)) {
+    if (!dixRegisterPrivateKey(&glamor_pixmap_private_key, PRIVATE_PIXMAP,
+                               sizeof(struct glamor_pixmap_private))) {
         LogMessage(X_WARNING,
                    "glamor%d: Failed to allocate pixmap private\n",
                    screen->myNum);
@@ -705,27 +695,6 @@ glamor_release_screen_priv(ScreenPtr screen)
     glamor_set_screen_private(screen, NULL);
 }
 
-_X_EXPORT void
-glamor_set_pixmap_private(PixmapPtr pixmap, glamor_pixmap_private *priv)
-{
-    glamor_pixmap_private *old_priv;
-
-    old_priv = dixGetPrivate(&pixmap->devPrivates, &glamor_pixmap_private_key);
-
-    if (priv) {
-        assert(old_priv == NULL);
-    }
-    else {
-        if (old_priv == NULL)
-            return;
-        glamor_pixmap_destroy_fbo(glamor_get_screen_private(pixmap->drawable.pScreen),
-                                  old_priv);
-        free(old_priv);
-    }
-
-    dixSetPrivate(&pixmap->devPrivates, &glamor_pixmap_private_key, priv);
-}
-
 Bool
 glamor_close_screen(ScreenPtr screen)
 {
@@ -759,7 +728,7 @@ glamor_close_screen(ScreenPtr screen)
     screen->SetWindowPixmap = glamor_priv->saved_procs.set_window_pixmap;
 
     screen_pixmap = screen->GetScreenPixmap(screen);
-    glamor_set_pixmap_private(screen_pixmap, NULL);
+    glamor_pixmap_destroy_fbo(screen_pixmap);
 
     glamor_release_screen_priv(screen);
 
diff --git a/glamor/glamor.h b/glamor/glamor.h
index 0931bbc..4be8800 100644
--- a/glamor/glamor.h
+++ b/glamor/glamor.h
@@ -52,7 +52,7 @@ struct glamor_context;
  * @TEXTURE_ONLY: pixmap is in an internal texture.
  */
 typedef enum glamor_pixmap_type {
-    GLAMOR_MEMORY,
+    GLAMOR_MEMORY = 0, /* Newly calloc()ed pixmaps are memory. */
     GLAMOR_TEXTURE_DRM,
     GLAMOR_DRM_ONLY,
     GLAMOR_TEXTURE_ONLY,
diff --git a/glamor/glamor_fbo.c b/glamor/glamor_fbo.c
index 84f3b22..1eee304 100644
--- a/glamor/glamor_fbo.c
+++ b/glamor/glamor_fbo.c
@@ -471,9 +471,11 @@ glamor_pixmap_attach_fbo(PixmapPtr pixmap, glamor_pixmap_fbo *fbo)
 }
 
 void
-glamor_pixmap_destroy_fbo(glamor_screen_private *glamor_priv,
-                          glamor_pixmap_private *priv)
+glamor_pixmap_destroy_fbo(PixmapPtr pixmap)
 {
+    ScreenPtr screen = pixmap->drawable.pScreen;
+    glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
+    glamor_pixmap_private *priv = glamor_get_pixmap_private(pixmap);
     glamor_pixmap_fbo *fbo;
 
     if (glamor_pixmap_priv_is_large(priv)) {
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index 66e5012..fe65d9b 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -405,22 +405,12 @@ extern DevPrivateKeyRec glamor_pixmap_private_key;
 static inline glamor_pixmap_private *
 glamor_get_pixmap_private(PixmapPtr pixmap)
 {
-    glamor_pixmap_private *priv;
-
     if (pixmap == NULL)
         return NULL;
 
-    priv = dixLookupPrivate(&pixmap->devPrivates, &glamor_pixmap_private_key);
-    if (!priv) {
-        glamor_set_pixmap_type(pixmap, GLAMOR_MEMORY);
-        priv = dixLookupPrivate(&pixmap->devPrivates,
-                                &glamor_pixmap_private_key);
-    }
-    return priv;
+    return dixLookupPrivate(&pixmap->devPrivates, &glamor_pixmap_private_key);
 }
 
-void glamor_set_pixmap_private(PixmapPtr pixmap, glamor_pixmap_private *priv);
-
 /*
  * Returns TRUE if pixmap has no image object
  */
@@ -590,8 +580,7 @@ glamor_pixmap_fbo *glamor_create_fbo(glamor_screen_private *glamor_priv, int w,
                                      int h, GLenum format, int flag);
 void glamor_destroy_fbo(glamor_screen_private *glamor_priv,
                         glamor_pixmap_fbo *fbo);
-void glamor_pixmap_destroy_fbo(glamor_screen_private *glamor_priv,
-                               glamor_pixmap_private *priv);
+void glamor_pixmap_destroy_fbo(PixmapPtr pixmap);
 void glamor_init_pixmap_fbo(ScreenPtr screen);
 void glamor_fini_pixmap_fbo(ScreenPtr screen);
 Bool glamor_pixmap_fbo_fixup(ScreenPtr screen, PixmapPtr pixmap);
commit d278c30e68d79e86a3e2207b629d1e461856f907
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Jun 30 20:35:59 2015 -0700

    glamor: Drop dead glamor_is_large_picture().
    
    It died as of keithp's new glyphs code.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/glamor/glamor_utils.h b/glamor/glamor_utils.h
index cef62c5..0a7de82 100644
--- a/glamor/glamor_utils.h
+++ b/glamor/glamor_utils.h
@@ -946,18 +946,6 @@ glamor_is_large_pixmap(PixmapPtr pixmap)
 }
 
 inline static Bool
-glamor_is_large_picture(PicturePtr picture)
-{
-    PixmapPtr pixmap;
-
-    if (picture->pDrawable) {
-        pixmap = glamor_get_drawable_pixmap(picture->pDrawable);
-        return glamor_is_large_pixmap(pixmap);
-    }
-    return FALSE;
-}
-
-inline static Bool
 glamor_tex_format_is_readable(GLenum format)
 {
     return ((format == GL_RGBA || format == GL_RGB || format == GL_ALPHA));
commit cd608a516d2c59ebfb95fadfecf68227888c0e4e
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Jun 30 20:25:06 2015 -0700

    glamor: Reuse the glamor_is_memory helper.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/glamor/glamor_composite_glyphs.c b/glamor/glamor_composite_glyphs.c
index cd88524..389c8f4 100644
--- a/glamor/glamor_composite_glyphs.c
+++ b/glamor/glamor_composite_glyphs.c
@@ -376,14 +376,12 @@ glamor_composite_glyphs(CARD8 op,
             if (glyph->info.width && glyph->info.height) {
                 PicturePtr glyph_pict = GlyphPicture(glyph)[screen_num];
                 DrawablePtr glyph_draw = glyph_pict->pDrawable;
-                glamor_pixmap_private *glyph_pix_priv =
-                    glamor_get_pixmap_private((PixmapPtr) glyph_draw);
 
                 /* Need to draw with slow path?
                  */
                 if (_X_UNLIKELY(glyph_draw->width > glyph_max_dim ||
                                 glyph_draw->height > glyph_max_dim ||
-                                (glyph_pix_priv != 0 && glyph_pix_priv->type != GLAMOR_MEMORY)))
+                                !glamor_pixmap_is_memory((PixmapPtr)glyph_draw)))
                 {
                     if (glyphs_queued) {
                         glamor_glyphs_flush(op, src, dst, prog, glyph_atlas, glyphs_queued);
commit 7b0f940625a0f6eee2ef91dfbfa4a206246940f5
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Dec 19 13:46:37 2014 -0500

    atom: make FreeAtom static
    
    Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/dix/atom.c b/dix/atom.c
index a1e555e..da0adfe 100644
--- a/dix/atom.c
+++ b/dix/atom.c
@@ -70,8 +70,6 @@ static NodePtr atomRoot = NULL;
 static unsigned long tableLength;
 static NodePtr *nodeTable;
 
-void FreeAtom(NodePtr patom);
-
 Atom
 MakeAtom(const char *string, unsigned len, Bool makeit)
 {
@@ -166,7 +164,7 @@ AtomError(void)
     FatalError("initializing atoms");
 }
 
-void
+static void
 FreeAtom(NodePtr patom)
 {
     if (patom->left)
commit 2d2cf9e322a5ec3ead175edc136cdaeea00ec1b1
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Dec 19 12:57:41 2014 -0500

    atom: Bump initial table size
    
    We're always creating ~230 atoms at startup, might as well tune it so we
    don't hit the realloc path before Dispatch.
    
    Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/dix/atom.c b/dix/atom.c
index 7de7fb0..a1e555e 100644
--- a/dix/atom.c
+++ b/dix/atom.c
@@ -56,7 +56,7 @@ SOFTWARE.
 #include "resource.h"
 #include "dix.h"
 
-#define InitialTableSize 100
+#define InitialTableSize 256
 
 typedef struct _Node {
     struct _Node *left, *right;
commit 995ff11422eb49160abfe276f471e412b16cab9d
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue May 19 11:31:25 2015 -0400

    glx: Implement GLX_ARB_context_flush_control
    
    This extension allows clients to opt out of the implicit glFlush on
    context release, which is quite nice for performance for clients using
    multiple contexts.  The server doesn't really need to be aware of the
    client's decision, at least for direct contexts, but it does need to not
    reject the context attribute out of hand.
    
    This patch won't do anything unless built against a Mesa that defines
    the __DRI2_FLUSH_CONTROL extension (and a new enough glxext.h, but
    that's been there since 10.3 at least).
    
    Reviewed-by: James Jones <jajones at nvidia.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/glx/createcontext.c b/glx/createcontext.c
index cbeddec..d06bc1f 100644
--- a/glx/createcontext.c
+++ b/glx/createcontext.c
@@ -87,6 +87,9 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
     int minor_version = 0;
     uint32_t flags = 0;
     uint32_t render_type = GLX_RGBA_TYPE;
+#ifdef GLX_CONTEXT_RELEASE_BEHAVIOR_ARB
+    uint32_t flush = GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB;
+#endif
     __GLXcontext *ctx = NULL;
     __GLXcontext *shareCtx = NULL;
     __GLXscreen *glxScreen;
@@ -194,6 +197,15 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
 
             break;
 
+#ifdef GLX_CONTEXT_RELEASE_BEHAVIOR_ARB
+        case GLX_CONTEXT_RELEASE_BEHAVIOR_ARB:
+            flush = attribs[2 * i + 1];
+            if (flush != GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB
+                && flush != GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB)
+                return BadValue;
+            break;
+#endif
+
         default:
             return BadValue;
         }
@@ -333,6 +345,9 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
     ctx->drawPriv = NULL;
     ctx->readPriv = NULL;
     ctx->resetNotificationStrategy = reset;
+#ifdef GLX_CONTEXT_RELEASE_BEHAVIOR_ARB
+    ctx->releaseBehavior = flush;
+#endif
 
     /* Add the new context to the various global tables of GLX contexts.
      */
diff --git a/glx/extension_string.c b/glx/extension_string.c
index 4bef96f..e881d21 100644
--- a/glx/extension_string.c
+++ b/glx/extension_string.c
@@ -72,6 +72,7 @@ struct extension_info {
 static const struct extension_info known_glx_extensions[] = {
 /*   GLX_ARB_get_proc_address is implemented on the client. */
     /* *INDENT-OFF* */
+    { GLX(ARB_context_flush_control),   VER(0,0), N, },
     { GLX(ARB_create_context),          VER(0,0), N, },
     { GLX(ARB_create_context_profile),  VER(0,0), N, },
     { GLX(ARB_create_context_robustness), VER(0,0), N, },
diff --git a/glx/extension_string.h b/glx/extension_string.h
index e7d3932..bac7b06 100644
--- a/glx/extension_string.h
+++ b/glx/extension_string.h
@@ -36,7 +36,8 @@
 
 enum {
 /*   GLX_ARB_get_proc_address is implemented on the client. */
-    ARB_create_context_bit = 0,
+    ARB_context_flush_control_bit = 0,
+    ARB_create_context_bit,
     ARB_create_context_profile_bit,
     ARB_create_context_robustness_bit,
     ARB_fbconfig_float_bit,
diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index f5f2bab..cbd4ede 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -334,6 +334,19 @@ DoCreateContext(__GLXclientState * cl, GLXContextID gcId,
      */
     glxc->resetNotificationStrategy = GLX_NO_RESET_NOTIFICATION_ARB;
 
+#ifdef GLX_CONTEXT_RELEASE_BEHAVIOR_ARB
+    /* The GLX_ARB_context_flush_control spec says:
+     *
+     *     "The default value [for GLX_CONTEXT_RELEASE_BEHAVIOR] is
+     *     CONTEXT_RELEASE_BEHAVIOR_FLUSH, and may in some cases be changed
+     *     using platform-specific context creation extensions."
+     *
+     * Without using glXCreateContextAttribsARB, there is no way to specify a
+     * non-default release behavior.
+     */
+    glxc->releaseBehavior = GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB;
+#endif
+
     /* Add the new context to the various global tables of GLX contexts.
      */
     if (!__glXAddContext(glxc)) {
@@ -626,7 +639,12 @@ DoMakeCurrent(__GLXclientState * cl,
         /*
          ** Flush the previous context if needed.
          */
-        if (prevglxc->hasUnflushedCommands) {
+        Bool need_flush = GL_TRUE;
+#ifdef GLX_CONTEXT_RELEASE_BEHAVIOR_ARB
+        if (prevglxc->releaseBehavior == GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB)
+            need_flush = GL_FALSE;
+#endif
+        if (prevglxc->hasUnflushedCommands && need_flush) {
             if (__glXForceCurrent(cl, tag, (int *) &error)) {
                 glFlush();
                 prevglxc->hasUnflushedCommands = GL_FALSE;
diff --git a/glx/glxcontext.h b/glx/glxcontext.h
index 677898a..0733281 100644
--- a/glx/glxcontext.h
+++ b/glx/glxcontext.h
@@ -108,6 +108,11 @@ struct __GLXcontext {
      */
     GLenum resetNotificationStrategy;
 
+    /**
+     * Context release behavior
+     */
+    GLenum releaseBehavior;
+
     /*
      ** Buffers for feedback and selection.
      */
diff --git a/glx/glxdri2.c b/glx/glxdri2.c
index bcd57a4..6fb3d92 100644
--- a/glx/glxdri2.c
+++ b/glx/glxdri2.c
@@ -921,6 +921,13 @@ initializeExtensions(__GLXDRIscreen * screen)
                        "AIGLX: enabled GLX_ARB_create_context_robustness\n");
         }
 
+#ifdef __DRI2_FLUSH_CONTROL
+        if (strcmp(extensions[i]->name, __DRI2_FLUSH_CONTROL) == 0) {
+            __glXEnableExtension(screen->glx_enable_bits,
+                                 "GLX_ARB_context_flush_control\n");
+        }
+#endif
+
         /* Ignore unknown extensions */
     }
 }
diff --git a/glx/glxdriswrast.c b/glx/glxdriswrast.c
index e25ca47..9add2a1 100644
--- a/glx/glxdriswrast.c
+++ b/glx/glxdriswrast.c
@@ -424,6 +424,14 @@ initializeExtensions(__GLXDRIscreen * screen)
             screen->texBuffer = (const __DRItexBufferExtension *) extensions[i];
             /* GLX_EXT_texture_from_pixmap is always enabled. */
         }
+
+#ifdef __DRI2_FLUSH_CONTROL
+        if (strcmp(extensions[i]->name, __DRI2_FLUSH_CONTROL) == 0) {
+            __glXEnableExtension(screen->glx_enable_bits,
+                                 "GLX_ARB_context_flush_control\n");
+        }
+#endif
+
     }
 }
 
commit 2d7194334a9f84e417ec90e220b2fe476f704612
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 15 11:27:31 2015 -0400

    glx/swrast: Do more GLX extension setup
    
    This gets you nice things like core contexts when using Xvfb.
    
    Also, no, MESA_copy_sub_buffer is not enabled automatically.
    
    Reviewed-by: James Jones <jajones at nvidia.com>
    Reviewed-by: Jon Turney <jon.turney at dronecode.org.uk>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/glx/glxdriswrast.c b/glx/glxdriswrast.c
index 5d9aa04..e25ca47 100644
--- a/glx/glxdriswrast.c
+++ b/glx/glxdriswrast.c
@@ -71,6 +71,8 @@ struct __GLXDRIscreen {
     const __DRIcopySubBufferExtension *copySubBuffer;
     const __DRItexBufferExtension *texBuffer;
     const __DRIconfig **driConfigs;
+
+    unsigned char glx_enable_bits[__GLX_EXT_BYTES];
 };
 
 struct __GLXDRIcontext {
@@ -394,21 +396,34 @@ initializeExtensions(__GLXDRIscreen * screen)
     const __DRIextension **extensions;
     int i;
 
+    if (screen->swrast->base.version >= 3) {
+        __glXEnableExtension(screen->glx_enable_bits,
+                             "GLX_ARB_create_context");
+        __glXEnableExtension(screen->glx_enable_bits,
+                             "GLX_ARB_create_context_profile");
+        __glXEnableExtension(screen->glx_enable_bits,
+                             "GLX_EXT_create_context_es2_profile");
+    }
+
+    /* these are harmless to enable unconditionally */
+    __glXEnableExtension(screen->glx_enable_bits, "GLX_EXT_framebuffer_sRGB");
+    __glXEnableExtension(screen->glx_enable_bits, "GLX_ARB_fbconfig_float");
+    __glXEnableExtension(screen->glx_enable_bits, "GLX_SGI_make_current_read");
+
     extensions = screen->core->getExtensions(screen->driScreen);
 
     for (i = 0; extensions[i]; i++) {
         if (strcmp(extensions[i]->name, __DRI_COPY_SUB_BUFFER) == 0) {
             screen->copySubBuffer =
                 (const __DRIcopySubBufferExtension *) extensions[i];
-            /* GLX_MESA_copy_sub_buffer is always enabled. */
+            __glXEnableExtension(screen->glx_enable_bits,
+                                 "GLX_MESA_copy_sub_buffer");
         }
 
         if (strcmp(extensions[i]->name, __DRI_TEX_BUFFER) == 0) {
             screen->texBuffer = (const __DRItexBufferExtension *) extensions[i];
             /* GLX_EXT_texture_from_pixmap is always enabled. */
         }
-
-        /* Ignore unknown extensions */
     }
 }
 
@@ -420,6 +435,7 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
 {
     const char *driverName = "swrast";
     __GLXDRIscreen *screen;
+    size_t buffer_size;
 
     screen = calloc(1, sizeof *screen);
     if (screen == NULL)
@@ -431,6 +447,8 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
     screen->base.swapInterval = NULL;
     screen->base.pScreen = pScreen;
 
+    __glXInitExtensionEnableBits(screen->glx_enable_bits);
+
     screen->driver = glxProbeDriver(driverName,
                                     (void **) &screen->core,
                                     __DRI_CORE, 1,
@@ -459,6 +477,19 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
 
     __glXScreenInit(&screen->base, pScreen);
 
+    /* The first call simply determines the length of the extension string.
+     * This allows us to allocate some memory to hold the extension string,
+     * but it requires that we call __glXGetExtensionString a second time.
+     */
+    buffer_size = __glXGetExtensionString(screen->glx_enable_bits, NULL);
+    if (buffer_size > 0) {
+        free(screen->base.GLXextensions);
+
+        screen->base.GLXextensions = xnfalloc(buffer_size);
+        (void) __glXGetExtensionString(screen->glx_enable_bits,
+                                       screen->base.GLXextensions);
+    }
+
     screen->base.GLXmajor = 1;
     screen->base.GLXminor = 4;
 
commit cbd3cfbad3f07b20e90ea9498110f255813eb441
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jun 2 13:58:30 2015 -0400

    dix: Restore PaintWindow screen hook
    
    Removes the last cpp conditional on ROOTLESS from dix code.
    
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/composite/compwindow.c b/composite/compwindow.c
index 77bdfa2..344138a 100644
--- a/composite/compwindow.c
+++ b/composite/compwindow.c
@@ -104,7 +104,7 @@ compRepaintBorder(ClientPtr pClient, void *closure)
 
         RegionNull(&exposed);
         RegionSubtract(&exposed, &pWindow->borderClip, &pWindow->winSize);
-        miPaintWindow(pWindow, &exposed, PW_BORDER);
+        pWindow->drawable.pScreen->PaintWindow(pWindow, &exposed, PW_BORDER);
         RegionUninit(&exposed);
     }
     return TRUE;
diff --git a/dix/window.c b/dix/window.c
index 1b44305..d57f320 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -1467,7 +1467,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
 
         RegionNull(&exposed);
         RegionSubtract(&exposed, &pWin->borderClip, &pWin->winSize);
-        miPaintWindow(pWin, &exposed, PW_BORDER);
+        pWin->drawable.pScreen->PaintWindow(pWin, &exposed, PW_BORDER);
         RegionUninit(&exposed);
     }
     return error;
@@ -3034,7 +3034,7 @@ dixSaveScreens(ClientPtr client, int on, int mode)
 
                 /* make it look like screen saver is off, so that
                  * NotClippedByChildren will compute a clip list
-                 * for the root window, so miPaintWindow works
+                 * for the root window, so PaintWindow works
                  */
                 screenIsSaved = SCREEN_SAVER_OFF;
                 (*pWin->drawable.pScreen->MoveWindow) (pWin,
diff --git a/hw/xquartz/quartz.c b/hw/xquartz/quartz.c
index 851ce48..d3ec133 100644
--- a/hw/xquartz/quartz.c
+++ b/hw/xquartz/quartz.c
@@ -300,8 +300,8 @@ QuartzUpdateScreens(void)
 
     quartzProcs->UpdateScreen(pScreen);
 
-    /* miPaintWindow needs to be called after RootlessUpdateScreenPixmap (from xprUpdateScreen) */
-    miPaintWindow(pRoot, &pRoot->borderClip, PW_BACKGROUND);
+    /* PaintWindow needs to be called after RootlessUpdateScreenPixmap (from xprUpdateScreen) */
+    pScreen->PaintWindow(pRoot, &pRoot->borderClip, PW_BACKGROUND);
 
     /* Tell RandR about the new size, so new connections get the correct info */
     RRScreenSizeNotify(pScreen);
diff --git a/hw/xwin/winrandr.c b/hw/xwin/winrandr.c
index 7392507..f4ba054 100644
--- a/hw/xwin/winrandr.c
+++ b/hw/xwin/winrandr.c
@@ -104,7 +104,7 @@ winDoRandRScreenSetSize(ScreenPtr pScreen,
     SetRootClip(pScreen, TRUE);
 
     // and arrange for it to be repainted
-    miPaintWindow(pRoot, &pRoot->borderClip, PW_BACKGROUND);
+    pScreen->PaintWindow(pRoot, &pRoot->borderClip, PW_BACKGROUND);
 
     /* Indicate that a screen size change took place */
     RRScreenSizeNotify(pScreen);
diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index a627fe7..2e617c4 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -158,6 +158,10 @@ typedef void (*PostValidateTreeProcPtr) (WindowPtr /*pParent */ ,
 typedef void (*WindowExposuresProcPtr) (WindowPtr /*pWindow */ ,
                                         RegionPtr /*prgn */);
 
+typedef void (*PaintWindowProcPtr) (WindowPtr /*pWindow*/,
+                                    RegionPtr /*pRegion*/,
+                                    int /*what*/);
+
 typedef void (*CopyWindowProcPtr) (WindowPtr /*pWindow */ ,
                                    DDXPointRec /*ptOldOrg */ ,
                                    RegionPtr /*prgnSrc */ );
@@ -498,6 +502,7 @@ typedef struct _Screen {
     ClearToBackgroundProcPtr ClearToBackground;
     ClipNotifyProcPtr ClipNotify;
     RestackWindowProcPtr RestackWindow;
+    PaintWindowProcPtr PaintWindow;
 
     /* Pixmap procedures */
 
diff --git a/mi/miexpose.c b/mi/miexpose.c
index f4c6e89..148d1a6 100644
--- a/mi/miexpose.c
+++ b/mi/miexpose.c
@@ -268,10 +268,11 @@ miHandleExposures(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
         RegionTranslate(&rgnExposed, pDstDrawable->x, pDstDrawable->y);
 
         if (extents) {
-            /* miPaintWindow doesn't clip, so we have to */
+            /* PaintWindow doesn't clip, so we have to */
             RegionIntersect(&rgnExposed, &rgnExposed, &pWin->clipList);
         }
-        miPaintWindow((WindowPtr) pDstDrawable, &rgnExposed, PW_BACKGROUND);
+        pDstDrawable->pScreen->PaintWindow((WindowPtr) pDstDrawable,
+                                           &rgnExposed, PW_BACKGROUND);
 
         if (extents) {
             RegionReset(&rgnExposed, &expBox);
@@ -383,16 +384,14 @@ miWindowExposures(WindowPtr pWin, RegionPtr prgn)
              * work overall, on both client and server.  This is cheating, but
              * isn't prohibited by the protocol ("spontaneous combustion" :-).
              */
-            BoxRec box;
-
-            box = *RegionExtents(prgn);
+            BoxRec box = *RegionExtents(prgn);
             exposures = &expRec;
             RegionInit(exposures, &box, 1);
             RegionReset(prgn, &box);
             /* miPaintWindow doesn't clip, so we have to */
             RegionIntersect(prgn, prgn, &pWin->clipList);
         }
-        miPaintWindow(pWin, prgn, PW_BACKGROUND);
+        pWin->drawable.pScreen->PaintWindow(pWin, prgn, PW_BACKGROUND);
         if (clientInterested)
             miSendExposures(pWin, exposures,
                             pWin->drawable.x, pWin->drawable.y);
@@ -402,14 +401,6 @@ miWindowExposures(WindowPtr pWin, RegionPtr prgn)
     }
 }
 
-#ifdef ROOTLESS
-/* Ugly, ugly, but we lost our hooks into miPaintWindow... =/ */
-void RootlessSetPixmapOfAncestors(WindowPtr pWin);
-void RootlessStartDrawing(WindowPtr pWin);
-void RootlessDamageRegion(WindowPtr pWin, RegionPtr prgn);
-Bool IsFramedWindow(WindowPtr pWin);
-#endif
-
 void
 miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
 {
@@ -437,19 +428,6 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
     Bool solid = TRUE;
     DrawablePtr drawable = &pWin->drawable;
 
-#ifdef ROOTLESS
-    if (IsFramedWindow(pWin)) {
-        RootlessStartDrawing(pWin);
-        RootlessDamageRegion(pWin, prgn);
-
-        if (pWin->backgroundState == ParentRelative) {
-            if ((what == PW_BACKGROUND) ||
-                (what == PW_BORDER && !pWin->borderIsPixel))
-                RootlessSetPixmapOfAncestors(pWin);
-        }
-    }
-#endif
-
     if (what == PW_BACKGROUND) {
         while (pWin->backgroundState == ParentRelative)
             pWin = pWin->parent;
diff --git a/mi/mioverlay.c b/mi/mioverlay.c
index 2b20fd7..9f3ef07 100644
--- a/mi/mioverlay.c
+++ b/mi/mioverlay.c
@@ -844,8 +844,8 @@ miOverlayHandleExposures(WindowPtr pWin)
             if ((mival = pTree->valdata)) {
                 if (!((*pPriv->InOverlay) (pTree->pWin))) {
                     if (RegionNotEmpty(&mival->borderExposed)) {
-                        miPaintWindow(pTree->pWin, &mival->borderExposed,
-                                      PW_BORDER);
+                        pScreen->PaintWindow(pTree->pWin, &mival->borderExposed,
+                                             PW_BORDER);
                     }
                     RegionUninit(&mival->borderExposed);
 
@@ -883,7 +883,8 @@ miOverlayHandleExposures(WindowPtr pWin)
             }
             else {
                 if (RegionNotEmpty(&val->after.borderExposed)) {
-                    miPaintWindow(pChild, &val->after.borderExposed, PW_BORDER);
+                    pScreen->PaintWindow(pChild, &val->after.borderExposed,
+                                         PW_BORDER);
                 }
                 (*WindowExposures) (pChild, &val->after.exposed);
             }
@@ -982,6 +983,7 @@ static void
 miOverlayWindowExposures(WindowPtr pWin, RegionPtr prgn)
 {
     RegionPtr exposures = prgn;
+    ScreenPtr pScreen = pWin->drawable.pScreen;
 
     if (prgn && !RegionNil(prgn)) {
         RegionRec expRec;
@@ -1007,7 +1009,7 @@ miOverlayWindowExposures(WindowPtr pWin, RegionPtr prgn)
             else
                 RegionIntersect(prgn, prgn, &pWin->clipList);
         }
-        miPaintWindow(pWin, prgn, PW_BACKGROUND);
+        pScreen->PaintWindow(pWin, prgn, PW_BACKGROUND);
         if (clientInterested)
             miSendExposures(pWin, exposures,
                             pWin->drawable.x, pWin->drawable.y);
@@ -1606,7 +1608,7 @@ miOverlayClearToBackground(WindowPtr pWin,
     if (generateExposures)
         (*pScreen->WindowExposures) (pWin, &reg);
     else if (pWin->backgroundState != None)
-        miPaintWindow(pWin, &reg, PW_BACKGROUND);
+        pScreen->PaintWindow(pWin, &reg, PW_BACKGROUND);
     RegionUninit(&reg);
 }
 
diff --git a/mi/miscrinit.c b/mi/miscrinit.c
index b53c7e4..9c6af0d 100644
--- a/mi/miscrinit.c
+++ b/mi/miscrinit.c
@@ -253,6 +253,7 @@ miScreenInit(ScreenPtr pScreen, void *pbits,  /* pointer to screen bits */
     pScreen->ClearToBackground = miClearToBackground;
     pScreen->ClipNotify = (ClipNotifyProcPtr) 0;
     pScreen->RestackWindow = (RestackWindowProcPtr) 0;
+    pScreen->PaintWindow = miPaintWindow;
     /* CreatePixmap, DestroyPixmap */
     /* RealizeFont, UnrealizeFont */
     /* CreateGC */
diff --git a/mi/miwindow.c b/mi/miwindow.c
index 2fc7cfb..39c279e 100644
--- a/mi/miwindow.c
+++ b/mi/miwindow.c
@@ -113,7 +113,7 @@ miClearToBackground(WindowPtr pWin,
     if (generateExposures)
         (*pWin->drawable.pScreen->WindowExposures) (pWin, &reg);
     else if (pWin->backgroundState != None)
-        miPaintWindow(pWin, &reg, PW_BACKGROUND);
+        pWin->drawable.pScreen->PaintWindow(pWin, &reg, PW_BACKGROUND);
     RegionUninit(&reg);
 }
 
@@ -219,7 +219,9 @@ miHandleValidateExposures(WindowPtr pWin)
     while (1) {
         if ((val = pChild->valdata)) {
             if (RegionNotEmpty(&val->after.borderExposed))
-                miPaintWindow(pChild, &val->after.borderExposed, PW_BORDER);
+                pWin->drawable.pScreen->PaintWindow(pChild,
+                                                    &val->after.borderExposed,
+                                                    PW_BORDER);
             RegionUninit(&val->after.borderExposed);
             (*WindowExposures) (pChild, &val->after.exposed);
             RegionUninit(&val->after.exposed);
diff --git a/miext/rootless/rootlessCommon.h b/miext/rootless/rootlessCommon.h
index fd9c941..aa55579 100644
--- a/miext/rootless/rootlessCommon.h
+++ b/miext/rootless/rootlessCommon.h
@@ -94,6 +94,7 @@ typedef struct _RootlessScreenRec {
     ChangeBorderWidthProcPtr ChangeBorderWidth;
     PositionWindowProcPtr PositionWindow;
     ChangeWindowAttributesProcPtr ChangeWindowAttributes;
+    PaintWindowProcPtr PaintWindow;
 
     CreateGCProcPtr CreateGC;
     CopyWindowProcPtr CopyWindow;
diff --git a/miext/rootless/rootlessScreen.c b/miext/rootless/rootlessScreen.c
index 6226ee8..4716564 100644
--- a/miext/rootless/rootlessScreen.c
+++ b/miext/rootless/rootlessScreen.c
@@ -473,7 +473,7 @@ expose_1(WindowPtr pWin)
     if (!pWin->realized)
         return;
 
-    miPaintWindow(pWin, &pWin->borderClip, PW_BACKGROUND);
+    pWin->drawable.pScreen->PaintWindow(pWin, &pWin->borderClip, PW_BACKGROUND);
 
     /* FIXME: comments in windowstr.h indicate that borderClip doesn't
        include subwindow visibility. But I'm not so sure.. so we may
@@ -669,6 +669,7 @@ RootlessWrap(ScreenPtr pScreen)
     WRAP(CloseScreen);
     WRAP(CreateGC);
     WRAP(CopyWindow);
+    WRAP(PaintWindow);
     WRAP(GetImage);
     WRAP(SourceValidate);
     WRAP(CreateWindow);
diff --git a/miext/rootless/rootlessWindow.c b/miext/rootless/rootlessWindow.c
index 3240acc..e304299 100644
--- a/miext/rootless/rootlessWindow.c
+++ b/miext/rootless/rootlessWindow.c
@@ -720,7 +720,7 @@ RootlessResizeCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg,
 /*
  * RootlessCopyWindow
  *  Update *new* location of window. Old location is redrawn with
- *  miPaintWindow. Cloned from fbCopyWindow.
+ *  PaintWindow. Cloned from fbCopyWindow.
  *  The original always draws on the root pixmap, which we don't have.
  *  Instead, draw on the parent window's pixmap.
  */
@@ -794,6 +794,27 @@ RootlessCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
     RL_DEBUG_MSG("copywindowFB end\n");
 }
 
+void
+RootlessPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
+{
+    ScreenPtr pScreen = pWin->drawable.pScreen;
+
+    if (IsFramedWindow(pWin)) {
+        RootlessStartDrawing(pWin);
+        RootlessDamageRegion(pWin, prgn);
+
+        if (pWin->backgroundState == ParentRelative) {
+            if ((what == PW_BACKGROUND) ||
+                (what == PW_BORDER && !pWin->borderIsPixel))
+                RootlessSetPixmapOfAncestors(pWin);
+        }
+    }
+
+    SCREEN_UNWRAP(pScreen, PaintWindow);
+    pScreen->PaintWindow(pWin, prgn, what);
+    SCREEN_WRAP(pScreen, PaintWindow);
+}
+
 /*
  * Window resize procedures
  */
diff --git a/miext/rootless/rootlessWindow.h b/miext/rootless/rootlessWindow.h
index d3955fc..4fd34d5 100644
--- a/miext/rootless/rootlessWindow.h
+++ b/miext/rootless/rootlessWindow.h
@@ -48,6 +48,7 @@ Bool RootlessUnrealizeWindow(WindowPtr pWin);
 void RootlessRestackWindow(WindowPtr pWin, WindowPtr pOldNextSib);
 void RootlessCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg,
                         RegionPtr prgnSrc);
+void RootlessPaintWindow(WindowPtr pWin, RegionPtr prgn, int what);
 void RootlessMoveWindow(WindowPtr pWin, int x, int y, WindowPtr pSib,
                         VTKind kind);
 void RootlessResizeWindow(WindowPtr pWin, int x, int y, unsigned int w,
commit 74d64ceea02bffad1caf3d1a727edbd38d968059
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jun 2 13:58:30 2015 -0400

    mi: Remove questionable optimization from the rootless path
    
    This is effectively a revert of 7b506fdc840aebed6b5acb91437a2cb620b5bddc
    except the coding style reindent broke that.  The code makes no sense in
    any case.  drawable can never be null since it's the first member of
    WindowRec, and we're never called with a null window.  Neither can it be
    an UNDRAWABLE_WINDOW since those are InputOnly windows; the rootless
    code does not set the root window to either UNDRAWABLE or InputOnly, so.
    
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/mi/miexpose.c b/mi/miexpose.c
index 4124d67..f4c6e89 100644
--- a/mi/miexpose.c
+++ b/mi/miexpose.c
@@ -438,9 +438,6 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
     DrawablePtr drawable = &pWin->drawable;
 
 #ifdef ROOTLESS
-    if (!drawable || drawable->type == UNDRAWABLE_WINDOW)
-        return;
-
     if (IsFramedWindow(pWin)) {
         RootlessStartDrawing(pWin);
         RootlessDamageRegion(pWin, prgn);
commit 315661a425018a546f7bcc18ad3e5f4578473ca6
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jun 2 13:58:30 2015 -0400

    fb: Make rootless-agnostic
    
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/fb/fb.h b/fb/fb.h
index ab110f3..c687aa7 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -472,13 +472,8 @@ typedef struct {
 #define fbGetWindowPixmap(pWin)	((PixmapPtr)\
 				 dixLookupPrivate(&((WindowPtr)(pWin))->devPrivates, fbGetWinPrivateKey(pWin)))
 
-#ifdef ROOTLESS
 #define __fbPixDrawableX(pPix)	((pPix)->drawable.x)
 #define __fbPixDrawableY(pPix)	((pPix)->drawable.y)
-#else
-#define __fbPixDrawableX(pPix)	0
-#define __fbPixDrawableY(pPix)	0
-#endif
 
 #ifdef COMPOSITE
 #define __fbPixOffXWin(pPix)	(__fbPixDrawableX(pPix) - (pPix)->screen_x)
commit 1594fb912996e9776d9e36383bd1d9f5dd2877eb
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jun 2 13:58:30 2015 -0400

    rootless: Build unconditionally
    
    It's not a lot of code, and if you're doing things to the core that
    affect rootless you should be alerted early.
    
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/miext/Makefile.am b/miext/Makefile.am
index b84adc1..add4d18 100644
--- a/miext/Makefile.am
+++ b/miext/Makefile.am
@@ -1,8 +1 @@
-SUBDIRS = sync damage shadow
-if XQUARTZ
-SUBDIRS += rootless
-endif
-if XWIN_MULTIWINDOWEXTWM
-SUBDIRS += rootless
-endif
-DIST_SUBDIRS = sync damage shadow rootless
+SUBDIRS = sync damage shadow rootless
commit bdc917a41691250701ccc9a0b087448b50892fa9
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jun 2 13:58:30 2015 -0400

    rootless: Genericize the config header a bit
    
    ROOTLESS_RESIZE_GRAVITY is an optimization, so let's default it to off
    unless the backing window system is known to support it.
    
    ROOTLESS_PROTECT_ALPHA looks like it has different values for xquartz
    and win32, but hilariously rootlessGC.c merely checks if it is defined,
    not what the value is.  It's effectively the more conservative path
    anyway, so let's just turn it on.
    
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/miext/rootless/rootlessConfig.h b/miext/rootless/rootlessConfig.h
index d39ae63..4c464b9 100644
--- a/miext/rootless/rootlessConfig.h
+++ b/miext/rootless/rootlessConfig.h
@@ -35,28 +35,17 @@
 #define _ROOTLESSCONFIG_H
 
 #ifdef __APPLE__
+#define ROOTLESS_RESIZE_GRAVITY TRUE
+#endif
+
+/*# define ROOTLESSDEBUG*/
 
 #define ROOTLESS_PROTECT_ALPHA TRUE
 #define ROOTLESS_REDISPLAY_DELAY 10
-#define ROOTLESS_RESIZE_GRAVITY TRUE
-/*# define ROOTLESSDEBUG*/
 
 /* Bit mask for alpha channel with a particular number of bits per
    pixel. Note that we only care for 32bpp data. Mac OS X uses planar
    alpha for 16bpp. */
 #define RootlessAlphaMask(bpp) ((bpp) == 32 ? 0xFF000000 : 0)
 
-#endif                          /* __APPLE__ */
-
-#if defined(__CYGWIN__) || defined(WIN32)
-
-#define ROOTLESS_PROTECT_ALPHA NO
-#define ROOTLESS_REDISPLAY_DELAY 10
-#undef  ROOTLESS_RESIZE_GRAVITY
-/*# define ROOTLESSDEBUG*/
-
-#define RootlessAlphaMask(bpp) ((bpp) == 32 ? 0xFF000000 : 0)
-
-#endif                          /* __CYGWIN__ */
-
 #endif                          /* _ROOTLESSCONFIG_H */
commit 6f3332b9f411fd7ac9cab0085faa56f6c2ff3323
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jun 2 13:58:30 2015 -0400

    dix: unifdef pWin->rootlessUnhittable
    
    No reason to vary the dix ABI over this.
    
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/dix/window.c b/dix/window.c
index d49276c..1b44305 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -380,10 +380,7 @@ SetWindowToDefaults(WindowPtr pWin)
     pWin->forcedBS = FALSE;
     pWin->redirectDraw = RedirectDrawNone;
     pWin->forcedBG = FALSE;
-
-#ifdef ROOTLESS
-    pWin->rootlessUnhittable = FALSE;
-#endif
+    pWin->unhittable = FALSE;
 
 #ifdef COMPOSITE
     pWin->damagedDescendants = FALSE;
diff --git a/include/windowstr.h b/include/windowstr.h
index 53eef37..4383dab 100644
--- a/include/windowstr.h
+++ b/include/windowstr.h
@@ -162,9 +162,7 @@ typedef struct _Window {
     unsigned forcedBS:1;        /* system-supplied backingStore */
     unsigned redirectDraw:2;    /* COMPOSITE rendering redirect */
     unsigned forcedBG:1;        /* must have an opaque background */
-#ifdef ROOTLESS
-    unsigned rootlessUnhittable:1;      /* doesn't hit-test */
-#endif
+    unsigned unhittable:1;      /* doesn't hit-test, for rootless */
 #ifdef COMPOSITE
     unsigned damagedDescendants:1;      /* some descendants are damaged */
     unsigned inhibitBGPaint:1;  /* paint the background? */
diff --git a/mi/miwindow.c b/mi/miwindow.c
index 7574239..2fc7cfb 100644
--- a/mi/miwindow.c
+++ b/mi/miwindow.c
@@ -767,14 +767,11 @@ miSpriteTrace(SpritePtr pSprite, int x, int y)
                 RegionContainsPoint(wInputShape(pWin),
                                     x - pWin->drawable.x,
                                     y - pWin->drawable.y, &box))
-#ifdef ROOTLESS
             /* In rootless mode windows may be offscreen, even when
              * they're in X's stack. (E.g. if the native window system
              * implements some form of virtual desktop system).
              */
-            && !pWin->rootlessUnhittable
-#endif
-            ) {
+            && !pWin->unhittable) {
             if (pSprite->spriteTraceGood >= pSprite->spriteTraceSize) {
                 pSprite->spriteTraceSize += 10;
                 pSprite->spriteTrace = reallocarray(pSprite->spriteTrace,
diff --git a/miext/rootless/rootlessWindow.c b/miext/rootless/rootlessWindow.c
index 1f78e3f..3240acc 100644
--- a/miext/rootless/rootlessWindow.c
+++ b/miext/rootless/rootlessWindow.c
@@ -92,7 +92,7 @@ RootlessNativeWindowStateChanged(WindowPtr pWin, unsigned int state)
 
     winRec->is_offscreen = ((state & XP_WINDOW_STATE_OFFSCREEN) != 0);
     winRec->is_obscured = ((state & XP_WINDOW_STATE_OBSCURED) != 0);
-    pWin->rootlessUnhittable = winRec->is_offscreen;
+    pWin->unhittable = winRec->is_offscreen;
 }
 
 void
@@ -569,7 +569,7 @@ RootlessReorderWindow(WindowPtr pWin)
         newPrevW = pWin->prevSib;
         while (newPrevW &&
                (WINREC(newPrevW) == NULL || !newPrevW->realized ||
-                newPrevW->rootlessUnhittable != pWin->rootlessUnhittable))
+                newPrevW->unhittable != pWin->unhittable))
             newPrevW = newPrevW->prevSib;
 
         newPrev = newPrevW != NULL ? WINREC(newPrevW) : NULL;
@@ -1365,7 +1365,7 @@ RootlessReparentWindow(WindowPtr pWin, WindowPtr pPriorParent)
     pTopWin = TopLevelParent(pWin);
     assert(pTopWin != pWin);
 
-    pWin->rootlessUnhittable = FALSE;
+    pWin->unhittable = FALSE;
 
     DeleteProperty(serverClient, pWin, xa_native_window_id());
 
@@ -1503,7 +1503,7 @@ RootlessOrderAllWindows(Bool include_unhitable)
                 continue;
             if (RootlessEnsureFrame(pWin) == NULL)
                 continue;
-            if (!include_unhitable && pWin->rootlessUnhittable)
+            if (!include_unhitable && pWin->unhittable)
                 continue;
             RootlessReorderWindow(pWin);
         }
commit 36fac0dd1a9a9cf41b631cf7e1ea015bcf920db7
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 23 13:23:20 2014 -0400

    xfixes: Unexport xfixes.h
    
    There's nothing a driver could want to use this for.
    
    Acked-by: Chris Wilson <chris at chris-wilson.co.uk>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/vfb/Makefile.am b/hw/vfb/Makefile.am
index f0f9fee..c9ac35e 100644
--- a/hw/vfb/Makefile.am
+++ b/hw/vfb/Makefile.am
@@ -21,7 +21,6 @@ XVFB_LIBS = \
 
 Xvfb_LDADD = $(XVFB_LIBS) $(XVFB_SYS_LIBS) $(XSERVER_SYS_LIBS)
 Xvfb_DEPENDENCIES = $(XVFB_LIBS)
-Xvfb_LDFLAGS = $(LD_EXPORT_SYMBOLS_FLAG)
 
 relink:
 	$(AM_V_at)rm -f Xvfb$(EXEEXT) && $(MAKE) Xvfb$(EXEEXT)
diff --git a/xfixes/Makefile.am b/xfixes/Makefile.am
index a8425e8..2a95c06 100644
--- a/xfixes/Makefile.am
+++ b/xfixes/Makefile.am
@@ -2,10 +2,6 @@ noinst_LTLIBRARIES = libxfixes.la
 
 AM_CFLAGS = $(DIX_CFLAGS)
 
-if XORG
-sdk_HEADERS = xfixes.h
-endif
-
 libxfixes_la_SOURCES = 	\
 	cursor.c	\
 	region.c	\
diff --git a/xfixes/xfixes.h b/xfixes/xfixes.h
index fdcf44f..23f31cd 100644
--- a/xfixes/xfixes.h
+++ b/xfixes/xfixes.h
@@ -29,8 +29,8 @@
 
 #include "resource.h"
 
-extern _X_EXPORT RESTYPE RegionResType;
-extern _X_EXPORT int XFixesErrorBase;
+extern RESTYPE RegionResType;
+extern int XFixesErrorBase;
 
 #define VERIFY_REGION(pRegion, rid, client, mode)			\
     do {								\
@@ -48,7 +48,7 @@ extern _X_EXPORT int XFixesErrorBase;
     if (rid) VERIFY_REGION(pRegion, rid, client, mode); \
 }
 
-extern _X_EXPORT RegionPtr
+extern RegionPtr
  XFixesRegionCopy(RegionPtr pRegion);
 
 #include "xibarriers.h"
commit 4da66d9e0399141feffd5f002e4195a438fe5020
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 8 14:27:02 2014 -0400

    vidmode: Hide implementation details
    
    Also remove vidmodeproc.h from the SDK since no drivers are using it.
    
    Acked-by: Chris Wilson <chris at chris-wilson.co.uk>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/common/Makefile.am b/hw/xfree86/common/Makefile.am
index 54e7f4d..3bc0046 100644
--- a/hw/xfree86/common/Makefile.am
+++ b/hw/xfree86/common/Makefile.am
@@ -16,7 +16,6 @@ endif
 
 if XF86VIDMODE
 XF86VMODESOURCES = xf86vmode.c
-XF86VMODE_SDK = vidmodeproc.h
 endif
 
 if DGA
diff --git a/hw/xfree86/common/vidmodeproc.h b/hw/xfree86/common/vidmodeproc.h
index cff340c..59d714c 100644
--- a/hw/xfree86/common/vidmodeproc.h
+++ b/hw/xfree86/common/vidmodeproc.h
@@ -41,44 +41,43 @@ typedef union {
 
 extern Bool VidModeExtensionInit(ScreenPtr pScreen);
 
-extern _X_EXPORT Bool VidModeAvailable(int scrnIndex);
-extern _X_EXPORT Bool VidModeGetCurrentModeline(int scrnIndex, void **mode,
-                                                int *dotClock);
-extern _X_EXPORT Bool VidModeGetFirstModeline(int scrnIndex, void **mode,
-                                              int *dotClock);
-extern _X_EXPORT Bool VidModeGetNextModeline(int scrnIndex, void **mode,
-                                             int *dotClock);
-extern _X_EXPORT Bool VidModeDeleteModeline(int scrnIndex, void *mode);
-extern _X_EXPORT Bool VidModeZoomViewport(int scrnIndex, int zoom);
-extern _X_EXPORT Bool VidModeGetViewPort(int scrnIndex, int *x, int *y);
-extern _X_EXPORT Bool VidModeSetViewPort(int scrnIndex, int x, int y);
-extern _X_EXPORT Bool VidModeSwitchMode(int scrnIndex, void *mode);
-extern _X_EXPORT Bool VidModeLockZoom(int scrnIndex, Bool lock);
-extern _X_EXPORT Bool VidModeGetMonitor(int scrnIndex, void **monitor);
-extern _X_EXPORT int VidModeGetNumOfClocks(int scrnIndex, Bool *progClock);
-extern _X_EXPORT Bool VidModeGetClocks(int scrnIndex, int *Clocks);
-extern _X_EXPORT ModeStatus VidModeCheckModeForMonitor(int scrnIndex,
-                                                       void *mode);
-extern _X_EXPORT ModeStatus VidModeCheckModeForDriver(int scrnIndex,
-                                                      void *mode);
-extern _X_EXPORT void VidModeSetCrtcForMode(int scrnIndex, void *mode);
-extern _X_EXPORT Bool VidModeAddModeline(int scrnIndex, void *mode);
-extern _X_EXPORT int VidModeGetDotClock(int scrnIndex, int Clock);
-extern _X_EXPORT int VidModeGetNumOfModes(int scrnIndex);
-extern _X_EXPORT Bool VidModeSetGamma(int scrnIndex, float red, float green,
-                                      float blue);
-extern _X_EXPORT Bool VidModeGetGamma(int scrnIndex, float *red, float *green,
-                                      float *blue);
-extern _X_EXPORT void *VidModeCreateMode(void);
-extern _X_EXPORT void VidModeCopyMode(void *modefrom, void *modeto);
-extern _X_EXPORT int VidModeGetModeValue(void *mode, int valtyp);
-extern _X_EXPORT void VidModeSetModeValue(void *mode, int valtyp, int val);
-extern _X_EXPORT vidMonitorValue VidModeGetMonitorValue(void *monitor,
-                                                        int valtyp, int indx);
-extern _X_EXPORT Bool VidModeSetGammaRamp(int, int, CARD16 *, CARD16 *,
-                                          CARD16 *);
-extern _X_EXPORT Bool VidModeGetGammaRamp(int, int, CARD16 *, CARD16 *,
-                                          CARD16 *);
-extern _X_EXPORT int VidModeGetGammaRampSize(int scrnIndex);
+extern Bool VidModeGetCurrentModeline(int scrnIndex, void **mode,
+                                      int *dotClock);
+extern Bool VidModeGetFirstModeline(int scrnIndex, void **mode,
+                                    int *dotClock);
+extern Bool VidModeGetNextModeline(int scrnIndex, void **mode,
+                                   int *dotClock);
+extern Bool VidModeDeleteModeline(int scrnIndex, void *mode);
+extern Bool VidModeZoomViewport(int scrnIndex, int zoom);
+extern Bool VidModeGetViewPort(int scrnIndex, int *x, int *y);
+extern Bool VidModeSetViewPort(int scrnIndex, int x, int y);
+extern Bool VidModeSwitchMode(int scrnIndex, void *mode);
+extern Bool VidModeLockZoom(int scrnIndex, Bool lock);
+extern Bool VidModeGetMonitor(int scrnIndex, void **monitor);
+extern int VidModeGetNumOfClocks(int scrnIndex, Bool *progClock);
+extern Bool VidModeGetClocks(int scrnIndex, int *Clocks);
+extern ModeStatus VidModeCheckModeForMonitor(int scrnIndex,
+                                             void *mode);
+extern ModeStatus VidModeCheckModeForDriver(int scrnIndex,
+                                            void *mode);
+extern void VidModeSetCrtcForMode(int scrnIndex, void *mode);
+extern Bool VidModeAddModeline(int scrnIndex, void *mode);
+extern int VidModeGetDotClock(int scrnIndex, int Clock);
+extern int VidModeGetNumOfModes(int scrnIndex);
+extern Bool VidModeSetGamma(int scrnIndex, float red, float green,
+                            float blue);
+extern Bool VidModeGetGamma(int scrnIndex, float *red, float *green,
+                            float *blue);
+extern void *VidModeCreateMode(void);
+extern void VidModeCopyMode(void *modefrom, void *modeto);
+extern int VidModeGetModeValue(void *mode, int valtyp);
+extern void VidModeSetModeValue(void *mode, int valtyp, int val);
+extern vidMonitorValue VidModeGetMonitorValue(void *monitor,
+                                              int valtyp, int indx);
+extern Bool VidModeSetGammaRamp(int, int, CARD16 *, CARD16 *,
+                                CARD16 *);
+extern Bool VidModeGetGammaRamp(int, int, CARD16 *, CARD16 *,
+                                CARD16 *);
+extern int VidModeGetGammaRampSize(int scrnIndex);
 
 #endif
diff --git a/hw/xfree86/common/xf86VidMode.c b/hw/xfree86/common/xf86VidMode.c
index e708b27..10c7b4b 100644
--- a/hw/xfree86/common/xf86VidMode.c
+++ b/hw/xfree86/common/xf86VidMode.c
@@ -111,7 +111,7 @@ VidModeClose(ScreenPtr pScreen)
     return pScreen->CloseScreen(pScreen);
 }
 
-Bool
+static Bool
 VidModeAvailable(int scrnIndex)
 {
     ScrnInfoPtr pScrn;
diff --git a/hw/xfree86/sdksyms.sh b/hw/xfree86/sdksyms.sh
index ed55cbb..5391b72 100755
--- a/hw/xfree86/sdksyms.sh
+++ b/hw/xfree86/sdksyms.sh
@@ -136,9 +136,6 @@ cat > sdksyms.c << EOF
 # include "xf86xvmc.h"
 # include "xf86xvpriv.h"
 #endif
-#if XF86VIDMODE
-# include "vidmodeproc.h"
-#endif
 #include "xorgVersion.h"
 #if defined(__sparc__) || defined(__sparc)
 # include "xf86sbusBus.h"
commit 49d7bae7f4c6a93f92df828440e3478513f930f4
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 8 14:18:07 2014 -0400

    xge: Hide some implementation details
    
    Acked-by: Chris Wilson <chris at chris-wilson.co.uk>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/Xext/geext.c b/Xext/geext.c
index aee68c4..6285f69 100644
--- a/Xext/geext.c
+++ b/Xext/geext.c
@@ -90,9 +90,10 @@ ProcGEQueryVersion(ClientPtr client)
     return Success;
 }
 
-int (*ProcGEVector[GENumberRequests]) (ClientPtr) = {
+static int (*ProcGEVector[GENumberRequests]) (ClientPtr) = {
     /* Version 1.0 */
-ProcGEQueryVersion};
+    ProcGEQueryVersion,
+};
 
 /************************************************************/
 /*                swapped request handlers                  */
@@ -109,9 +110,10 @@ SProcGEQueryVersion(ClientPtr client)
     return (*ProcGEVector[stuff->ReqType]) (client);
 }
 
-int (*SProcGEVector[GENumberRequests]) (ClientPtr) = {
+static int (*SProcGEVector[GENumberRequests]) (ClientPtr) = {
     /* Version 1.0 */
-SProcGEQueryVersion};
+    SProcGEQueryVersion
+};
 
 /************************************************************/
 /*                callbacks                                 */
diff --git a/Xext/geint.h b/Xext/geint.h
index f76d148..0ee28e4 100644
--- a/Xext/geint.h
+++ b/Xext/geint.h
@@ -37,7 +37,7 @@
 #include "extnsionst.h"
 #include <X11/extensions/geproto.h>
 
-extern _X_EXPORT DevPrivateKeyRec GEClientPrivateKeyRec;
+extern DevPrivateKeyRec GEClientPrivateKeyRec;
 
 #define GEClientPrivateKey (&GEClientPrivateKeyRec)
 
@@ -48,7 +48,4 @@ typedef struct _GEClientInfo {
 
 #define GEGetClient(pClient)    ((GEClientInfoPtr)(dixLookupPrivate(&((pClient)->devPrivates), GEClientPrivateKey)))
 
-extern _X_EXPORT int (*ProcGEVector[ /*GENumRequests */ ]) (ClientPtr);
-extern _X_EXPORT int (*SProcGEVector[ /*GENumRequests */ ]) (ClientPtr);
-
 #endif                          /* _GEINT_H_ */
diff --git a/hw/xfree86/sdksyms.sh b/hw/xfree86/sdksyms.sh
index 334ed24..ed55cbb 100755
--- a/hw/xfree86/sdksyms.sh
+++ b/hw/xfree86/sdksyms.sh
@@ -54,7 +54,6 @@ cat > sdksyms.c << EOF
 #include "xvmcext.h"
 #endif
 #include "geext.h"
-#include "geint.h"
 #ifdef MITSHM
 #include "shmint.h"
 #endif
commit 2377690709de11087edc9d1116c9feaeb8f118ed
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 8 14:03:13 2014 -0400

    dga: Hide a bunch of implementation details
    
    Acked-by: Chris Wilson <chris at chris-wilson.co.uk>
    Reviewed-by: Aaron Plattner <aplattner at nvidia.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/common/dgaproc.h b/hw/xfree86/common/dgaproc.h
index 87e923f..7925bd4 100644
--- a/hw/xfree86/common/dgaproc.h
+++ b/hw/xfree86/common/dgaproc.h
@@ -54,57 +54,15 @@ typedef struct {
 
 /* DDX interface */
 
-extern _X_EXPORT int
- DGASetMode(int Index, int num, XDGAModePtr mode, PixmapPtr *pPix);
-
-extern _X_EXPORT void
- DGASetInputMode(int Index, Bool keyboard, Bool mouse);
-
-extern _X_EXPORT void
- DGASelectInput(int Index, ClientPtr client, long mask);
-
-extern _X_EXPORT Bool DGAAvailable(int Index);
-extern _X_EXPORT Bool DGAScreenAvailable(ScreenPtr pScreen);
-extern _X_EXPORT Bool DGAActive(int Index);
-extern _X_EXPORT void DGAShutdown(void);
-extern _X_EXPORT void DGAInstallCmap(ColormapPtr cmap);
-extern _X_EXPORT int DGAGetViewportStatus(int Index);
-extern _X_EXPORT int DGASync(int Index);
-
-extern _X_EXPORT int
- DGAFillRect(int Index, int x, int y, int w, int h, unsigned long color);
-
-extern _X_EXPORT int
- DGABlitRect(int Index, int srcx, int srcy, int w, int h, int dstx, int dsty);
-
-extern _X_EXPORT int
-
-DGABlitTransRect(int Index,
-                 int srcx, int srcy,
-                 int w, int h, int dstx, int dsty, unsigned long color);
-
-extern _X_EXPORT int
- DGASetViewport(int Index, int x, int y, int mode);
-
-extern _X_EXPORT int DGAGetModes(int Index);
-extern _X_EXPORT int DGAGetOldDGAMode(int Index);
-
-extern _X_EXPORT int DGAGetModeInfo(int Index, XDGAModePtr mode, int num);
-
-extern _X_EXPORT Bool DGAVTSwitch(void);
-extern _X_EXPORT Bool DGAStealButtonEvent(DeviceIntPtr dev, int Index,
-                                          int button, int is_down);
-extern _X_EXPORT Bool DGAStealMotionEvent(DeviceIntPtr dev, int Index, int dx,
-                                          int dy);
-extern _X_EXPORT Bool DGAStealKeyEvent(DeviceIntPtr dev, int Index,
-                                       int key_code, int is_down);
-
-extern _X_EXPORT Bool DGAOpenFramebuffer(int Index, char **name,
-                                         unsigned char **mem, int *size,
-                                         int *offset, int *flags);
-extern _X_EXPORT void DGACloseFramebuffer(int Index);
-extern _X_EXPORT Bool DGAChangePixmapMode(int Index, int *x, int *y, int mode);
-extern _X_EXPORT int DGACreateColormap(int Index, ClientPtr client, int id,
-                                       int mode, int alloc);
+extern Bool DGAScreenAvailable(ScreenPtr pScreen);
+extern Bool DGAActive(int Index);
+extern void DGAShutdown(void);
+
+extern Bool DGAVTSwitch(void);
+extern Bool DGAStealButtonEvent(DeviceIntPtr dev, int Index,
+                                int button, int is_down);
+extern Bool DGAStealMotionEvent(DeviceIntPtr dev, int Index, int dx, int dy);
+extern Bool DGAStealKeyEvent(DeviceIntPtr dev, int Index,
+                             int key_code, int is_down);
 
 #endif                          /* __DGAPROC_H */
diff --git a/hw/xfree86/common/xf86DGA.c b/hw/xfree86/common/xf86DGA.c
index 9533e1c..c689dcb 100644
--- a/hw/xfree86/common/xf86DGA.c
+++ b/hw/xfree86/common/xf86DGA.c
@@ -471,7 +471,7 @@ xf86SetDGAMode(ScrnInfoPtr pScrn, int num, DGADevicePtr devRet)
 
 /*********** exported ones ***************/
 
-void
+static void
 DGASetInputMode(int index, Bool keyboard, Bool mouse)
 {
     ScreenPtr pScreen = screenInfo.screens[index];
@@ -488,7 +488,7 @@ DGASetInputMode(int index, Bool keyboard, Bool mouse)
     }
 }
 
-Bool
+static Bool
 DGAChangePixmapMode(int index, int *x, int *y, int mode)
 {
     DGAScreenPtr pScreenPriv;
@@ -560,7 +560,7 @@ DGAScreenAvailable(ScreenPtr pScreen)
     return FALSE;
 }
 
-Bool
+static Bool
 DGAAvailable(int index)
 {
     ScreenPtr pScreen;
@@ -606,7 +606,7 @@ DGAShutdown(void)
 
 /* Called by the extension to initialize a mode */
 
-int
+static int
 DGASetMode(int index, int num, XDGAModePtr mode, PixmapPtr *pPix)
 {
     ScrnInfoPtr pScrn = xf86Screens[index];
@@ -626,7 +626,7 @@ DGASetMode(int index, int num, XDGAModePtr mode, PixmapPtr *pPix)
 
 /* Called from the extension to let the DDX know which events are requested */
 
-void
+static void
 DGASelectInput(int index, ClientPtr client, long mask)
 {
     DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
@@ -636,7 +636,7 @@ DGASelectInput(int index, ClientPtr client, long mask)
     pScreenPriv->input = mask;
 }
 
-int
+static int
 DGAGetViewportStatus(int index)
 {
     DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
@@ -649,7 +649,7 @@ DGAGetViewportStatus(int index)
     return (*pScreenPriv->funcs->GetViewport) (pScreenPriv->pScrn);
 }
 
-int
+static int
 DGASetViewport(int index, int x, int y, int mode)
 {
     DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
@@ -675,7 +675,7 @@ BitsClear(CARD32 data)
     return bits;
 }
 
-int
+static int
 DGACreateColormap(int index, ClientPtr client, int id, int mode, int alloc)
 {
     ScreenPtr pScreen = screenInfo.screens[index];
@@ -744,7 +744,7 @@ DGACreateColormap(int index, ClientPtr client, int id, int mode, int alloc)
 
 /*  Called by the extension to install a colormap on DGA active screens */
 
-void
+static void
 DGAInstallCmap(ColormapPtr cmap)
 {
     ScreenPtr pScreen = cmap->pScreen;
@@ -760,7 +760,7 @@ DGAInstallCmap(ColormapPtr cmap)
     (*pScreen->InstallColormap) (cmap);
 }
 
-int
+static int
 DGASync(int index)
 {
     DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
@@ -773,7 +773,7 @@ DGASync(int index)
     return Success;
 }
 
-int
+static int
 DGAFillRect(int index, int x, int y, int w, int h, unsigned long color)
 {
     DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
@@ -789,7 +789,7 @@ DGAFillRect(int index, int x, int y, int w, int h, unsigned long color)
     return BadMatch;
 }
 
-int
+static int
 DGABlitRect(int index, int srcx, int srcy, int w, int h, int dstx, int dsty)
 {
     DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
@@ -806,7 +806,7 @@ DGABlitRect(int index, int srcx, int srcy, int w, int h, int dstx, int dsty)
     return BadMatch;
 }
 
-int
+static int
 DGABlitTransRect(int index,
                  int srcx, int srcy,
                  int w, int h, int dstx, int dsty, unsigned long color)
@@ -826,7 +826,7 @@ DGABlitTransRect(int index,
     return BadMatch;
 }
 
-int
+static int
 DGAGetModes(int index)
 {
     DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
@@ -836,7 +836,7 @@ DGAGetModes(int index)
     return pScreenPriv->numModes;
 }
 
-int
+static int
 DGAGetModeInfo(int index, XDGAModePtr mode, int num)
 {
     DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
@@ -1126,7 +1126,7 @@ DGAProcessPointerEvent(ScreenPtr pScreen, DGAEvent * event, DeviceIntPtr mouse)
     }
 }
 
-Bool
+static Bool
 DGAOpenFramebuffer(int index,
                    char **name,
                    unsigned char **mem, int *size, int *offset, int *flags)
@@ -1140,7 +1140,7 @@ DGAOpenFramebuffer(int index,
                                                    flags);
 }
 
-void
+static void
 DGACloseFramebuffer(int index)
 {
     DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
@@ -1152,7 +1152,7 @@ DGACloseFramebuffer(int index)
 
 /*  For DGA 1.0 backwards compatibility only */
 
-int
+static int
 DGAGetOldDGAMode(int index)
 {
     DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
diff --git a/hw/xfree86/sdksyms.sh b/hw/xfree86/sdksyms.sh
index e141522..334ed24 100755
--- a/hw/xfree86/sdksyms.sh
+++ b/hw/xfree86/sdksyms.sh
@@ -180,12 +180,6 @@ cat > sdksyms.c << EOF
 #endif
 
 
-/* hw/xfree86/dixmods/extmod/Makefile.am -- module */
-#ifdef XFreeXDGA
-#include "dgaproc.h"
-#endif
-
-
 /* hw/xfree86/parser/Makefile.am */
 #include "xf86Parser.h"
 #include "xf86Optrec.h"
commit b5fbe9c6327fac88c09afce598238a7534521b69
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 8 13:37:34 2014 -0400

    xfree86: Hide some pre-randr mode validation details
    
    Acked-by: Chris Wilson <chris at chris-wilson.co.uk>
    Reviewed-by: Aaron Plattner <aplattner at nvidia.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/common/xf86.h b/hw/xfree86/common/xf86.h
index 49ff35b..1cde478 100644
--- a/hw/xfree86/common/xf86.h
+++ b/hw/xfree86/common/xf86.h
@@ -368,22 +368,11 @@ xf86GetBppFromDepth(ScrnInfoPtr pScrn, int depth);
 
 /* xf86Mode.c */
 
-extern _X_EXPORT int
-xf86GetNearestClock(ScrnInfoPtr scrp, int freq, Bool allowDiv2,
-                    int DivFactor, int MulFactor, int *divider);
 extern _X_EXPORT const char *
 xf86ModeStatusToString(ModeStatus status);
 extern _X_EXPORT ModeStatus
-xf86LookupMode(ScrnInfoPtr scrp, DisplayModePtr modep,
-               ClockRangePtr clockRanges, LookupModeFlags strategy);
-extern _X_EXPORT ModeStatus
 xf86CheckModeForMonitor(DisplayModePtr mode, MonPtr monitor);
 extern _X_EXPORT ModeStatus
-xf86InitialCheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode,
-                              ClockRangePtr clockRanges,
-                              LookupModeFlags strategy,
-                              int maxPitch, int virtualX, int virtualY);
-extern _X_EXPORT ModeStatus
 xf86CheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode, int flags);
 extern _X_EXPORT int
 xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes,
diff --git a/hw/xfree86/common/xf86Mode.c b/hw/xfree86/common/xf86Mode.c
index 9a5550f..3f446ae 100644
--- a/hw/xfree86/common/xf86Mode.c
+++ b/hw/xfree86/common/xf86Mode.c
@@ -112,11 +112,10 @@ printModeRejectMessage(int index, DisplayModePtr p, int status)
 }
 
 /*
- * xf86GetNearestClock --
- *	Find closest clock to given frequency (in kHz).  This assumes the
- *	number of clocks is greater than zero.
+ * Find closest clock to given frequency (in kHz).  This assumes the
+ * number of clocks is greater than zero.
  */
-int
+static int
 xf86GetNearestClock(ScrnInfoPtr scrp, int freq, Bool allowDiv2,
                     int DivFactor, int MulFactor, int *divider)
 {
@@ -451,7 +450,7 @@ xf86HandleBuiltinMode(ScrnInfoPtr scrp,
  * reason.
  */
 
-ModeStatus
+static ModeStatus
 xf86LookupMode(ScrnInfoPtr scrp, DisplayModePtr modep,
                ClockRangePtr clockRanges, LookupModeFlags strategy)
 {
@@ -845,7 +844,7 @@ xf86CheckModeSize(ScrnInfoPtr scrp, int w, int x, int y)
  *    maxVValue    maximum vertical timing value
  */
 
-ModeStatus
+static ModeStatus
 xf86InitialCheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode,
                               ClockRangePtr clockRanges,
                               LookupModeFlags strategy,
diff --git a/hw/xfree86/doc/ddxDesign.xml b/hw/xfree86/doc/ddxDesign.xml
index 6a9de9e..aed77a9 100644
--- a/hw/xfree86/doc/ddxDesign.xml
+++ b/hw/xfree86/doc/ddxDesign.xml
@@ -6957,28 +6957,6 @@ use of some of these secondary mode helper functions.
 
       <blockquote><para>
 	  <programlisting>
-    int xf86GetNearestClock(ScrnInfoPtr scrp, int freq, Bool allowDiv2,
-                            int *divider);
-	  </programlisting>
-	  <blockquote><para>
-      This function returns the index of the closest clock to the
-      frequency <parameter>freq</parameter> given (in kHz).  It assumes that
-      the number of clocks is greater than zero.  It requires that the
-      <structfield>numClocks</structfield> and <structfield>clock</structfield> fields of the
-      <structname>ScrnInfoRec</structname> are initialised.  The
-      <structfield>allowDiv2</structfield> field determines if the clocks can be
-      halved.  The <parameter>*divider</parameter> return value indicates
-      whether clock division is used when determining the clock returned.
-	    </para>
-
-	    <para>
-      This function is only for non-programmable clocks.
-	    </para>
-
-	  </blockquote></para></blockquote>
-
-      <blockquote><para>
-	  <programlisting>
     const char *xf86ModeStatusToString(ModeStatus status);
 	  </programlisting>
 	  <blockquote><para>
@@ -6990,59 +6968,6 @@ use of some of these secondary mode helper functions.
 
       <blockquote><para>
 	  <programlisting>
-    ModeStatus xf86LookupMode(ScrnInfoPtr scrp, DisplayModePtr modep,
-                     ClockRangePtr clockRanges, LookupModeFlags strategy);
-	  </programlisting>
-	  <blockquote><para>
-      This function takes a pointer to a mode with the name filled in,
-      and looks for a mode in the <structfield>modePool</structfield> list which
-      matches.  The parameters of the matching mode are filled in to
-      <parameter>*modep</parameter>.  The <parameter>clockRanges</parameter> and
-      <parameter>strategy</parameter> parameters are as for the
-      <function>xf86ValidateModes()</function> function above.
-	    </para>
-
-	    <para>
-      This function requires the <structfield>modePool</structfield>,
-      <structfield>clock[]</structfield>, <structfield>numClocks</structfield> and
-      <structfield>progClock</structfield> fields of the <structname>ScrnInfoRec</structname>
-      to be initialised before being called.
-	    </para>
-
-	    <para>
-      The return value is <constant>MODE_OK</constant> if a mode was found.
-      Otherwise it indicates why a matching mode could not be found.
-	    </para>
-
-	  </blockquote></para></blockquote>
-
-      <blockquote><para>
-	  <programlisting>
-    ModeStatus xf86InitialCheckModeForDriver(ScrnInfoPtr scrp,
-                                DisplayModePtr mode, ClockRangePtr clockRanges,
-                                LookupModeFlags strategy, int maxPitch,
-                                int virtualX, int virtualY);
-	  </programlisting>
-	  <blockquote><para>
-      This function checks the passed mode against some basic driver
-      constraints.  Apart from the ones passed explicitly, the
-      <structfield>maxHValue</structfield> and <structfield>maxVValue</structfield> fields of
-      the <structname>ScrnInfoRec</structname> are also used.  If the
-      <structfield>ValidMode</structfield> field of the <structname>ScrnInfoRec</structname>
-      is set, that function is also called to check the mode.  Next, the
-      mode is checked against the monitor's constraints.
-	    </para>
-
-	    <para>
-      If the mode is consistent with all constraints, the return value
-      is <constant>MODE_OK</constant>.  Otherwise the return value indicates
-      which constraint wasn't met.
-	    </para>
-
-	  </blockquote></para></blockquote>
-
-      <blockquote><para>
-	  <programlisting>
     void xf86DeleteMode(DisplayModePtr *modeList, DisplayModePtr mode);
 	  </programlisting>
 	  <blockquote><para>
commit 70b402be2626d4f4afb02b6f5baa543262548bd7
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 30 16:19:08 2014 -0400

    render: Hide/unexport some implementation details
    
    Acked-by: Chris Wilson <chris at chris-wilson.co.uk>
    Reviewed-by: Aaron Plattner <aplattner at nvidia.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/render/glyph.c b/render/glyph.c
index f3310db..ea865af 100644
--- a/render/glyph.c
+++ b/render/glyph.c
@@ -106,7 +106,7 @@ GlyphUninit(ScreenPtr pScreen)
     }
 }
 
-GlyphHashSetPtr
+static GlyphHashSetPtr
 FindGlyphHashSet(CARD32 filled)
 {
     int i;
@@ -117,7 +117,7 @@ FindGlyphHashSet(CARD32 filled)
     return 0;
 }
 
-GlyphRefPtr
+static GlyphRefPtr
 FindGlyphRef(GlyphHashPtr hash,
              CARD32 signature, Bool match, unsigned char sha1[20])
 {
@@ -245,7 +245,7 @@ FreeGlyphPicture(GlyphPtr glyph)
     }
 }
 
-void
+static void
 FreeGlyph(GlyphPtr glyph, int format)
 {
     CheckDuplicates(&globalGlyphs[format], "FreeGlyph");
@@ -383,7 +383,7 @@ AllocateGlyph(xGlyphInfo * gi, int fdepth)
     return 0;
 }
 
-Bool
+static Bool
 AllocateGlyphHash(GlyphHashPtr hash, GlyphHashSetPtr hashSet)
 {
     hash->table = calloc(hashSet->size, sizeof(GlyphRefRec));
@@ -394,7 +394,7 @@ AllocateGlyphHash(GlyphHashPtr hash, GlyphHashSetPtr hashSet)
     return TRUE;
 }
 
-Bool
+static Bool
 ResizeGlyphHash(GlyphHashPtr hash, CARD32 change, Bool global)
 {
     CARD32 tableEntries;
diff --git a/render/glyphstr.h b/render/glyphstr.h
index 2df055d..2f51bd2 100644
--- a/render/glyphstr.h
+++ b/render/glyphstr.h
@@ -90,47 +90,31 @@ typedef struct _GlyphList {
     PictFormatPtr format;
 } GlyphListRec, *GlyphListPtr;
 
-extern _X_EXPORT void
+extern void
  GlyphUninit(ScreenPtr pScreen);
 
-extern _X_EXPORT GlyphHashSetPtr FindGlyphHashSet(CARD32 filled);
-
-extern _X_EXPORT GlyphRefPtr
-FindGlyphRef(GlyphHashPtr hash,
-             CARD32 signature, Bool match, unsigned char sha1[20]);
-
-extern _X_EXPORT GlyphPtr FindGlyphByHash(unsigned char sha1[20], int format);
-
-extern _X_EXPORT int
+extern GlyphPtr FindGlyphByHash(unsigned char sha1[20], int format);
 
+extern int
 HashGlyph(xGlyphInfo * gi,
           CARD8 *bits, unsigned long size, unsigned char sha1[20]);
 
-extern _X_EXPORT void
- FreeGlyph(GlyphPtr glyph, int format);
-
-extern _X_EXPORT void
+extern void
  AddGlyph(GlyphSetPtr glyphSet, GlyphPtr glyph, Glyph id);
 
-extern _X_EXPORT Bool
+extern Bool
  DeleteGlyph(GlyphSetPtr glyphSet, Glyph id);
 
-extern _X_EXPORT GlyphPtr FindGlyph(GlyphSetPtr glyphSet, Glyph id);
-
-extern _X_EXPORT GlyphPtr AllocateGlyph(xGlyphInfo * gi, int format);
-
-extern _X_EXPORT Bool
- AllocateGlyphHash(GlyphHashPtr hash, GlyphHashSetPtr hashSet);
+extern GlyphPtr FindGlyph(GlyphSetPtr glyphSet, Glyph id);
 
-extern _X_EXPORT Bool
- ResizeGlyphHash(GlyphHashPtr hash, CARD32 change, Bool global);
+extern GlyphPtr AllocateGlyph(xGlyphInfo * gi, int format);
 
-extern _X_EXPORT Bool
+extern Bool
  ResizeGlyphSet(GlyphSetPtr glyphSet, CARD32 change);
 
-extern _X_EXPORT GlyphSetPtr AllocateGlyphSet(int fdepth, PictFormatPtr format);
+extern GlyphSetPtr AllocateGlyphSet(int fdepth, PictFormatPtr format);
 
-extern _X_EXPORT int
+extern int
  FreeGlyphSet(void *value, XID gid);
 
 #define GLYPH_HAS_GLYPH_PICTURE_ACCESSOR 1 /* used for api compat */
diff --git a/render/mipict.c b/render/mipict.c
index 2571fda..4b85512 100644
--- a/render/mipict.c
+++ b/render/mipict.c
@@ -46,7 +46,7 @@ miDestroyPicture(PicturePtr pPicture)
         RegionDestroy(pPicture->pCompositeClip);
 }
 
-void
+static void
 miDestroyPictureClip(PicturePtr pPicture)
 {
     if (pPicture->clientClip)
@@ -54,7 +54,7 @@ miDestroyPictureClip(PicturePtr pPicture)
     pPicture->clientClip = NULL;
 }
 
-int
+static int
 miChangePictureClip(PicturePtr pPicture, int type, void *value, int n)
 {
     ScreenPtr pScreen = pPicture->pDrawable->pScreen;
@@ -88,13 +88,13 @@ miChangePictureClip(PicturePtr pPicture, int type, void *value, int n)
     return Success;
 }
 
-void
+static void
 miChangePicture(PicturePtr pPicture, Mask mask)
 {
     return;
 }
 
-void
+static void
 miValidatePicture(PicturePtr pPicture, Mask mask)
 {
     DrawablePtr pDrawable = pPicture->pDrawable;
@@ -211,13 +211,13 @@ miValidatePicture(PicturePtr pPicture, Mask mask)
     }
 }
 
-int
+static int
 miChangePictureTransform(PicturePtr pPicture, PictTransform * transform)
 {
     return Success;
 }
 
-int
+static int
 miChangePictureFilter(PicturePtr pPicture,
                       int filter, xFixed * params, int nparams)
 {
@@ -499,7 +499,7 @@ miRenderPixelToColor(PictFormatPtr format, CARD32 pixel, xRenderColor * color)
     }
 }
 
-void
+static void
 miTriStrip(CARD8 op,
            PicturePtr pSrc,
            PicturePtr pDst,
@@ -523,7 +523,7 @@ miTriStrip(CARD8 op,
     free(tris);
 }
 
-void
+static void
 miTriFan(CARD8 op,
          PicturePtr pSrc,
          PicturePtr pDst,
diff --git a/render/mipict.h b/render/mipict.h
index 23ce9e8..3241be4 100644
--- a/render/mipict.h
+++ b/render/mipict.h
@@ -54,26 +54,6 @@ extern _X_EXPORT void
  miDestroyPicture(PicturePtr pPicture);
 
 extern _X_EXPORT void
- miDestroyPictureClip(PicturePtr pPicture);
-
-extern _X_EXPORT int
- miChangePictureClip(PicturePtr pPicture, int type, void *value, int n);
-
-extern _X_EXPORT void
- miChangePicture(PicturePtr pPicture, Mask mask);
-
-extern _X_EXPORT void
- miValidatePicture(PicturePtr pPicture, Mask mask);
-
-extern _X_EXPORT int
- miChangePictureTransform(PicturePtr pPicture, PictTransform * transform);
-
-extern _X_EXPORT int
-
-miChangePictureFilter(PicturePtr pPicture,
-                      int filter, xFixed * params, int nparams);
-
-extern _X_EXPORT void
  miCompositeSourceValidate(PicturePtr pPicture);
 
 extern _X_EXPORT Bool
@@ -122,22 +102,6 @@ miCompositeRects(CARD8 op,
                  xRenderColor * color, int nRect, xRectangle *rects);
 
 extern _X_EXPORT void
-
-miTriStrip(CARD8 op,
-           PicturePtr pSrc,
-           PicturePtr pDst,
-           PictFormatPtr maskFormat,
-           INT16 xSrc, INT16 ySrc, int npoints, xPointFixed * points);
-
-extern _X_EXPORT void
-
-miTriFan(CARD8 op,
-         PicturePtr pSrc,
-         PicturePtr pDst,
-         PictFormatPtr maskFormat,
-         INT16 xSrc, INT16 ySrc, int npoints, xPointFixed * points);
-
-extern _X_EXPORT void
  miTrapezoidBounds(int ntrap, xTrapezoid * traps, BoxPtr box);
 
 extern _X_EXPORT void
diff --git a/render/picture.c b/render/picture.c
index 60517a4..506aec4 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -61,7 +61,7 @@ PictureWindowFormat(WindowPtr pWindow)
                               WindowGetVisual(pWindow));
 }
 
-Bool
+static Bool
 PictureDestroyWindow(WindowPtr pWindow)
 {
     ScreenPtr pScreen = pWindow->drawable.pScreen;
@@ -82,7 +82,7 @@ PictureDestroyWindow(WindowPtr pWindow)
     return ret;
 }
 
-Bool
+static Bool
 PictureCloseScreen(ScreenPtr pScreen)
 {
     PictureScreenPtr ps = GetPictureScreen(pScreen);
@@ -102,7 +102,7 @@ PictureCloseScreen(ScreenPtr pScreen)
     return ret;
 }
 
-void
+static void
 PictureStoreColors(ColormapPtr pColormap, int ndef, xColorItem * pdef)
 {
     ScreenPtr pScreen = pColormap->pScreen;
@@ -163,7 +163,7 @@ addFormat(FormatInitRec formats[256], int nformat, CARD32 format, CARD8 depth)
 
 #define Mask(n) ((1 << (n)) - 1)
 
-PictFormatPtr
+static PictFormatPtr
 PictureCreateDefaultFormats(ScreenPtr pScreen, int *nformatp)
 {
     int nformats, f;
@@ -439,7 +439,7 @@ PictureFindVisual(ScreenPtr pScreen, VisualID visual)
     return 0;
 }
 
-Bool
+static Bool
 PictureInitIndexedFormat(ScreenPtr pScreen, PictFormatPtr format)
 {
     PictureScreenPtr ps = GetPictureScreenIfSet(pScreen);
@@ -625,6 +625,12 @@ GetPictureBytes(void *value, XID id, ResourceSizePtr size)
     }
 }
 
+static int
+FreePictFormat(void *pPictFormat, XID pid)
+{
+    return Success;
+}
+
 Bool
 PictureInit(ScreenPtr pScreen, PictFormatPtr formats, int nformats)
 {
@@ -724,7 +730,7 @@ PictureInit(ScreenPtr pScreen, PictFormatPtr formats, int nformats)
     return TRUE;
 }
 
-void
+static void
 SetPictureToDefaults(PicturePtr pPicture)
 {
     pPicture->refcnt = 1;
@@ -1430,12 +1436,6 @@ FreePicture(void *value, XID pid)
     return Success;
 }
 
-int
-FreePictFormat(void *pPictFormat, XID pid)
-{
-    return Success;
-}
-
 /**
  * ReduceCompositeOp is used to choose simpler ops for cases where alpha
  * channels are always one and so math on the alpha channel per pixel becomes
diff --git a/render/picture.h b/render/picture.h
index 66c85c5..087e54d 100644
--- a/render/picture.h
+++ b/render/picture.h
@@ -169,11 +169,11 @@ typedef enum _PictFormatShort {
 #define PictureCmapPolicyColor	    3
 #define PictureCmapPolicyAll	    4
 
-extern _X_EXPORT int PictureCmapPolicy;
+extern int PictureCmapPolicy;
 
-extern _X_EXPORT int PictureParseCmapPolicy(const char *name);
+extern int PictureParseCmapPolicy(const char *name);
 
-extern _X_EXPORT int RenderErrBase;
+extern int RenderErrBase;
 
 /* Fixed point updates from Carl Worth, USC, Information Sciences Institute */
 
diff --git a/render/picturestr.h b/render/picturestr.h
index 177f87b..33baef9 100644
--- a/render/picturestr.h
+++ b/render/picturestr.h
@@ -344,16 +344,14 @@ typedef struct _PictureScreen {
 } PictureScreenRec, *PictureScreenPtr;
 
 extern _X_EXPORT DevPrivateKeyRec PictureScreenPrivateKeyRec;
-
 #define PictureScreenPrivateKey (&PictureScreenPrivateKeyRec)
 
 extern _X_EXPORT DevPrivateKeyRec PictureWindowPrivateKeyRec;
-
 #define	PictureWindowPrivateKey (&PictureWindowPrivateKeyRec)
 
-extern _X_EXPORT RESTYPE PictureType;
-extern _X_EXPORT RESTYPE PictFormatType;
-extern _X_EXPORT RESTYPE GlyphSetType;
+extern RESTYPE PictureType;
+extern RESTYPE PictFormatType;
+extern RESTYPE GlyphSetType;
 
 #define GetPictureScreen(s) ((PictureScreenPtr)dixLookupPrivate(&(s)->devPrivates, PictureScreenPrivateKey))
 #define GetPictureScreenIfSet(s) (dixPrivateKeyRegistered(PictureScreenPrivateKey) ? GetPictureScreen(s) : NULL)
@@ -380,27 +378,12 @@ extern _X_EXPORT PictFormatPtr
  PictureWindowFormat(WindowPtr pWindow);
 
 extern _X_EXPORT Bool
- PictureDestroyWindow(WindowPtr pWindow);
-
-extern _X_EXPORT Bool
- PictureCloseScreen(ScreenPtr pScreen);
-
-extern _X_EXPORT void
- PictureStoreColors(ColormapPtr pColormap, int ndef, xColorItem * pdef);
-
-extern _X_EXPORT Bool
- PictureInitIndexedFormat(ScreenPtr pScreen, PictFormatPtr format);
-
-extern _X_EXPORT Bool
  PictureSetSubpixelOrder(ScreenPtr pScreen, int subpixel);
 
 extern _X_EXPORT int
  PictureGetSubpixelOrder(ScreenPtr pScreen);
 
 extern _X_EXPORT PictFormatPtr
-PictureCreateDefaultFormats(ScreenPtr pScreen, int *nformatp);
-
-extern _X_EXPORT PictFormatPtr
 PictureMatchVisual(ScreenPtr pScreen, int depth, VisualPtr pVisual);
 
 extern _X_EXPORT PictFormatPtr
@@ -415,14 +398,12 @@ extern _X_EXPORT int
 extern _X_EXPORT char *PictureGetFilterName(int id);
 
 extern _X_EXPORT int
-
 PictureAddFilter(ScreenPtr pScreen,
                  const char *filter,
                  PictFilterValidateParamsProcPtr ValidateParams,
                  int width, int height);
 
 extern _X_EXPORT Bool
-
 PictureSetFilterAlias(ScreenPtr pScreen, const char *filter, const char *alias);
 
 extern _X_EXPORT Bool
@@ -435,21 +416,16 @@ extern _X_EXPORT PictFilterPtr
 PictureFindFilter(ScreenPtr pScreen, char *name, int len);
 
 extern _X_EXPORT int
-
 SetPicturePictFilter(PicturePtr pPicture, PictFilterPtr pFilter,
                      xFixed * params, int nparams);
 
 extern _X_EXPORT int
-
 SetPictureFilter(PicturePtr pPicture, char *name, int len,
                  xFixed * params, int nparams);
 
 extern _X_EXPORT Bool
  PictureFinishInit(void);
 
-extern _X_EXPORT void
- SetPictureToDefaults(PicturePtr pPicture);
-
 extern _X_EXPORT PicturePtr
 CreatePicture(Picture pid,
               DrawablePtr pDrawable,
@@ -457,7 +433,6 @@ CreatePicture(Picture pid,
               Mask mask, XID *list, ClientPtr client, int *error);
 
 extern _X_EXPORT int
-
 ChangePicture(PicturePtr pPicture,
               Mask vmask, XID *vlist, DevUnion *ulist, ClientPtr client);
 
@@ -467,7 +442,6 @@ SetPictureClipRects(PicturePtr pPicture,
                     int xOrigin, int yOrigin, int nRect, xRectangle *rects);
 
 extern _X_EXPORT int
-
 SetPictureClipRegion(PicturePtr pPicture,
                      int xOrigin, int yOrigin, RegionPtr pRegion);
 
@@ -480,11 +454,7 @@ extern _X_EXPORT void
 extern _X_EXPORT int
  FreePicture(void *pPicture, XID pid);
 
-extern _X_EXPORT int
- FreePictFormat(void *pPictFormat, XID pid);
-
 extern _X_EXPORT void
-
 CompositePicture(CARD8 op,
                  PicturePtr pSrc,
                  PicturePtr pMask,
@@ -496,7 +466,6 @@ CompositePicture(CARD8 op,
                  INT16 xDst, INT16 yDst, CARD16 width, CARD16 height);
 
 extern _X_EXPORT void
-
 CompositeGlyphs(CARD8 op,
                 PicturePtr pSrc,
                 PicturePtr pDst,
@@ -505,13 +474,11 @@ CompositeGlyphs(CARD8 op,
                 INT16 ySrc, int nlist, GlyphListPtr lists, GlyphPtr * glyphs);
 
 extern _X_EXPORT void
-
 CompositeRects(CARD8 op,
                PicturePtr pDst,
                xRenderColor * color, int nRect, xRectangle *rects);
 
 extern _X_EXPORT void
-
 CompositeTrapezoids(CARD8 op,
                     PicturePtr pSrc,
                     PicturePtr pDst,
@@ -519,7 +486,6 @@ CompositeTrapezoids(CARD8 op,
                     INT16 xSrc, INT16 ySrc, int ntrap, xTrapezoid * traps);
 
 extern _X_EXPORT void
-
 CompositeTriangles(CARD8 op,
                    PicturePtr pSrc,
                    PicturePtr pDst,
@@ -528,7 +494,6 @@ CompositeTriangles(CARD8 op,
                    INT16 ySrc, int ntriangles, xTriangle * triangles);
 
 extern _X_EXPORT void
-
 CompositeTriStrip(CARD8 op,
                   PicturePtr pSrc,
                   PicturePtr pDst,
@@ -536,7 +501,6 @@ CompositeTriStrip(CARD8 op,
                   INT16 xSrc, INT16 ySrc, int npoints, xPointFixed * points);
 
 extern _X_EXPORT void
-
 CompositeTriFan(CARD8 op,
                 PicturePtr pSrc,
                 PicturePtr pDst,
@@ -547,12 +511,10 @@ Bool
  AnimCurInit(ScreenPtr pScreen);
 
 int
-
 AnimCursorCreate(CursorPtr *cursors, CARD32 *deltas, int ncursor,
                  CursorPtr *ppCursor, ClientPtr client, XID cid);
 
 extern _X_EXPORT void
-
 AddTraps(PicturePtr pPicture,
          INT16 xOff, INT16 yOff, int ntraps, xTrap * traps);
 
@@ -583,8 +545,8 @@ CreateConicalGradientPicture(Picture pid,
                              xFixed * stops, xRenderColor * colors, int *error);
 
 #ifdef PANORAMIX
-extern _X_EXPORT void PanoramiXRenderInit(void);
-extern _X_EXPORT void PanoramiXRenderReset(void);
+extern void PanoramiXRenderInit(void);
+extern void PanoramiXRenderReset(void);
 #endif
 
 /*
@@ -592,12 +554,10 @@ extern _X_EXPORT void PanoramiXRenderReset(void);
  */
 
 extern _X_EXPORT void
-
 PictTransform_from_xRenderTransform(PictTransformPtr pict,
                                     xRenderTransform * render);
 
 extern _X_EXPORT void
-
 xRenderTransform_from_PictTransform(xRenderTransform * render,
                                     PictTransformPtr pict);
 
commit a1c80bb7d5871e1c5ee21fc650834858054103bf
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 30 15:49:38 2014 -0400

    randr: Unexport some implementation details
    
    Acked-by: Chris Wilson <chris at chris-wilson.co.uk>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/randr/randrstr.h b/randr/randrstr.h
index 03974fd..472721a 100644
--- a/randr/randrstr.h
+++ b/randr/randrstr.h
@@ -64,10 +64,10 @@ typedef XID RROutput;
 typedef XID RRCrtc;
 typedef XID RRProvider;
 
-extern _X_EXPORT int RREventBase, RRErrorBase;
+extern int RREventBase, RRErrorBase;
 
-extern _X_EXPORT int (*ProcRandrVector[RRNumberRequests]) (ClientPtr);
-extern _X_EXPORT int (*SProcRandrVector[RRNumberRequests]) (ClientPtr);
+extern int (*ProcRandrVector[RRNumberRequests]) (ClientPtr);
+extern int (*SProcRandrVector[RRNumberRequests]) (ClientPtr);
 
 /*
  * Modeline for a monitor. Name follows directly after this struct
@@ -397,8 +397,8 @@ typedef struct _RRClient {
 /*  RRTimesRec	times[0]; */
 } RRClientRec, *RRClientPtr;
 
-extern _X_EXPORT RESTYPE RRClientType, RREventType;     /* resource types for event masks */
-extern _X_EXPORT DevPrivateKeyRec RRClientPrivateKeyRec;
+extern RESTYPE RRClientType, RREventType;     /* resource types for event masks */
+extern DevPrivateKeyRec RRClientPrivateKeyRec;
 
 #define RRClientPrivateKey (&RRClientPrivateKeyRec)
 extern _X_EXPORT RESTYPE RRCrtcType, RRModeType, RROutputType, RRProviderType;
commit b51f7f8582ab6c3cc9fa56c8d9721d0f240915e7
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 23 13:37:41 2014 -0400

    dix: Unexport various implementation details
    
    Acked-by: Chris Wilson <chris at chris-wilson.co.uk>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/dix/colormap.c b/dix/colormap.c
index a3e5a2c..89a17c4 100644
--- a/dix/colormap.c
+++ b/dix/colormap.c
@@ -64,6 +64,9 @@ SOFTWARE.
 #include "privates.h"
 #include "xace.h"
 
+typedef int (*ColorCompareProcPtr) (EntryPtr /*pent */ ,
+                                    xrgb * /*prgb */ );
+
 static Pixel FindBestPixel(EntryPtr /*pentFirst */ ,
                            int /*size */ ,
                            xrgb * /*prgb */ ,
@@ -748,6 +751,173 @@ UpdateColors(ColormapPtr pmap)
     free(defs);
 }
 
+/* Tries to find a color in pmap that exactly matches the one requested in prgb
+ * if it can't it allocates one.
+ * Starts looking at pentFirst + *pPixel, so if you want a specific pixel,
+ * load *pPixel with that value, otherwise set it to 0
+ */
+static int
+FindColor(ColormapPtr pmap, EntryPtr pentFirst, int size, xrgb * prgb,
+          Pixel * pPixel, int channel, int client, ColorCompareProcPtr comp)
+{
+    EntryPtr pent;
+    Bool foundFree;
+    Pixel pixel, Free = 0;
+    int npix, count, *nump = NULL;
+    Pixel **pixp = NULL, *ppix;
+    xColorItem def;
+
+    foundFree = FALSE;
+
+    if ((pixel = *pPixel) >= size)
+        pixel = 0;
+    /* see if there is a match, and also look for a free entry */
+    for (pent = pentFirst + pixel, count = size; --count >= 0;) {
+        if (pent->refcnt > 0) {
+            if ((*comp) (pent, prgb)) {
+                if (client >= 0)
+                    pent->refcnt++;
+                *pPixel = pixel;
+                switch (channel) {
+                case REDMAP:
+                    *pPixel <<= pmap->pVisual->offsetRed;
+                case PSEUDOMAP:
+                    break;
+                case GREENMAP:
+                    *pPixel <<= pmap->pVisual->offsetGreen;
+                    break;
+                case BLUEMAP:
+                    *pPixel <<= pmap->pVisual->offsetBlue;
+                    break;
+                }
+                goto gotit;
+            }
+        }
+        else if (!foundFree && pent->refcnt == 0) {
+            Free = pixel;
+            foundFree = TRUE;
+            /* If we're initializing the colormap, then we are looking for
+             * the first free cell we can find, not to minimize the number
+             * of entries we use.  So don't look any further. */
+            if (pmap->flags & BeingCreated)
+                break;
+        }
+        pixel++;
+        if (pixel >= size) {
+            pent = pentFirst;
+            pixel = 0;
+        }
+        else
+            pent++;
+    }
+
+    /* If we got here, we didn't find a match.  If we also didn't find
+     * a free entry, we're out of luck.  Otherwise, we'll usurp a free
+     * entry and fill it in */
+    if (!foundFree)
+        return BadAlloc;
+    pent = pentFirst + Free;
+    pent->fShared = FALSE;
+    pent->refcnt = (client >= 0) ? 1 : AllocTemporary;
+
+    switch (channel) {
+    case PSEUDOMAP:
+        pent->co.local.red = prgb->red;
+        pent->co.local.green = prgb->green;
+        pent->co.local.blue = prgb->blue;
+        def.red = prgb->red;
+        def.green = prgb->green;
+        def.blue = prgb->blue;
+        def.flags = (DoRed | DoGreen | DoBlue);
+        if (client >= 0)
+            pmap->freeRed--;
+        def.pixel = Free;
+        break;
+
+    case REDMAP:
+        pent->co.local.red = prgb->red;
+        def.red = prgb->red;
+        def.green = pmap->green[0].co.local.green;
+        def.blue = pmap->blue[0].co.local.blue;
+        def.flags = DoRed;
+        if (client >= 0)
+            pmap->freeRed--;
+        def.pixel = Free << pmap->pVisual->offsetRed;
+        break;
+
+    case GREENMAP:
+        pent->co.local.green = prgb->green;
+        def.red = pmap->red[0].co.local.red;
+        def.green = prgb->green;
+        def.blue = pmap->blue[0].co.local.blue;
+        def.flags = DoGreen;
+        if (client >= 0)
+            pmap->freeGreen--;
+        def.pixel = Free << pmap->pVisual->offsetGreen;
+        break;
+
+    case BLUEMAP:
+        pent->co.local.blue = prgb->blue;
+        def.red = pmap->red[0].co.local.red;
+        def.green = pmap->green[0].co.local.green;
+        def.blue = prgb->blue;
+        def.flags = DoBlue;
+        if (client >= 0)
+            pmap->freeBlue--;
+        def.pixel = Free << pmap->pVisual->offsetBlue;
+        break;
+    }
+    (*pmap->pScreen->StoreColors) (pmap, 1, &def);
+    pixel = Free;
+    *pPixel = def.pixel;
+
+ gotit:
+    if (pmap->flags & BeingCreated || client == -1)
+        return Success;
+    /* Now remember the pixel, for freeing later */
+    switch (channel) {
+    case PSEUDOMAP:
+    case REDMAP:
+        nump = pmap->numPixelsRed;
+        pixp = pmap->clientPixelsRed;
+        break;
+
+    case GREENMAP:
+        nump = pmap->numPixelsGreen;
+        pixp = pmap->clientPixelsGreen;
+        break;
+
+    case BLUEMAP:
+        nump = pmap->numPixelsBlue;
+        pixp = pmap->clientPixelsBlue;
+        break;
+    }
+    npix = nump[client];
+    ppix = reallocarray(pixp[client], npix + 1, sizeof(Pixel));
+    if (!ppix) {
+        pent->refcnt--;
+        if (!pent->fShared)
+            switch (channel) {
+            case PSEUDOMAP:
+            case REDMAP:
+                pmap->freeRed++;
+                break;
+            case GREENMAP:
+                pmap->freeGreen++;
+                break;
+            case BLUEMAP:
+                pmap->freeBlue++;
+                break;
+            }
+        return BadAlloc;
+    }
+    ppix[npix] = pixel;
+    pixp[client] = ppix;
+    nump[client]++;
+
+    return Success;
+}
+
 /* Get a read-only color from a ColorMap (probably slow for large maps)
  * Returns by changing the value in pred, pgreen, pblue and pPix
  */
@@ -1137,173 +1307,6 @@ FindColorInRootCmap(ColormapPtr pmap, EntryPtr pentFirst, int size,
     }
 }
 
-/* Tries to find a color in pmap that exactly matches the one requested in prgb
- * if it can't it allocates one.
- * Starts looking at pentFirst + *pPixel, so if you want a specific pixel,
- * load *pPixel with that value, otherwise set it to 0
- */
-int
-FindColor(ColormapPtr pmap, EntryPtr pentFirst, int size, xrgb * prgb,
-          Pixel * pPixel, int channel, int client, ColorCompareProcPtr comp)
-{
-    EntryPtr pent;
-    Bool foundFree;
-    Pixel pixel, Free = 0;
-    int npix, count, *nump = NULL;
-    Pixel **pixp = NULL, *ppix;
-    xColorItem def;
-
-    foundFree = FALSE;
-
-    if ((pixel = *pPixel) >= size)
-        pixel = 0;
-    /* see if there is a match, and also look for a free entry */
-    for (pent = pentFirst + pixel, count = size; --count >= 0;) {
-        if (pent->refcnt > 0) {
-            if ((*comp) (pent, prgb)) {
-                if (client >= 0)
-                    pent->refcnt++;
-                *pPixel = pixel;
-                switch (channel) {
-                case REDMAP:
-                    *pPixel <<= pmap->pVisual->offsetRed;
-                case PSEUDOMAP:
-                    break;
-                case GREENMAP:
-                    *pPixel <<= pmap->pVisual->offsetGreen;
-                    break;
-                case BLUEMAP:
-                    *pPixel <<= pmap->pVisual->offsetBlue;
-                    break;
-                }
-                goto gotit;
-            }
-        }
-        else if (!foundFree && pent->refcnt == 0) {
-            Free = pixel;
-            foundFree = TRUE;
-            /* If we're initializing the colormap, then we are looking for
-             * the first free cell we can find, not to minimize the number
-             * of entries we use.  So don't look any further. */
-            if (pmap->flags & BeingCreated)
-                break;
-        }
-        pixel++;
-        if (pixel >= size) {
-            pent = pentFirst;
-            pixel = 0;
-        }
-        else
-            pent++;
-    }
-
-    /* If we got here, we didn't find a match.  If we also didn't find
-     * a free entry, we're out of luck.  Otherwise, we'll usurp a free
-     * entry and fill it in */
-    if (!foundFree)
-        return BadAlloc;
-    pent = pentFirst + Free;
-    pent->fShared = FALSE;
-    pent->refcnt = (client >= 0) ? 1 : AllocTemporary;
-
-    switch (channel) {
-    case PSEUDOMAP:
-        pent->co.local.red = prgb->red;
-        pent->co.local.green = prgb->green;
-        pent->co.local.blue = prgb->blue;
-        def.red = prgb->red;
-        def.green = prgb->green;
-        def.blue = prgb->blue;
-        def.flags = (DoRed | DoGreen | DoBlue);
-        if (client >= 0)
-            pmap->freeRed--;
-        def.pixel = Free;
-        break;
-
-    case REDMAP:
-        pent->co.local.red = prgb->red;
-        def.red = prgb->red;
-        def.green = pmap->green[0].co.local.green;
-        def.blue = pmap->blue[0].co.local.blue;
-        def.flags = DoRed;
-        if (client >= 0)
-            pmap->freeRed--;
-        def.pixel = Free << pmap->pVisual->offsetRed;
-        break;
-
-    case GREENMAP:
-        pent->co.local.green = prgb->green;
-        def.red = pmap->red[0].co.local.red;
-        def.green = prgb->green;
-        def.blue = pmap->blue[0].co.local.blue;
-        def.flags = DoGreen;
-        if (client >= 0)
-            pmap->freeGreen--;
-        def.pixel = Free << pmap->pVisual->offsetGreen;
-        break;
-
-    case BLUEMAP:
-        pent->co.local.blue = prgb->blue;
-        def.red = pmap->red[0].co.local.red;
-        def.green = pmap->green[0].co.local.green;
-        def.blue = prgb->blue;
-        def.flags = DoBlue;
-        if (client >= 0)
-            pmap->freeBlue--;
-        def.pixel = Free << pmap->pVisual->offsetBlue;
-        break;
-    }
-    (*pmap->pScreen->StoreColors) (pmap, 1, &def);
-    pixel = Free;
-    *pPixel = def.pixel;
-
- gotit:
-    if (pmap->flags & BeingCreated || client == -1)
-        return Success;
-    /* Now remember the pixel, for freeing later */
-    switch (channel) {
-    case PSEUDOMAP:
-    case REDMAP:
-        nump = pmap->numPixelsRed;
-        pixp = pmap->clientPixelsRed;
-        break;
-
-    case GREENMAP:
-        nump = pmap->numPixelsGreen;
-        pixp = pmap->clientPixelsGreen;
-        break;
-
-    case BLUEMAP:
-        nump = pmap->numPixelsBlue;
-        pixp = pmap->clientPixelsBlue;
-        break;
-    }
-    npix = nump[client];
-    ppix = reallocarray(pixp[client], npix + 1, sizeof(Pixel));
-    if (!ppix) {
-        pent->refcnt--;
-        if (!pent->fShared)
-            switch (channel) {
-            case PSEUDOMAP:
-            case REDMAP:
-                pmap->freeRed++;
-                break;
-            case GREENMAP:
-                pmap->freeGreen++;
-                break;
-            case BLUEMAP:
-                pmap->freeBlue++;
-                break;
-            }
-        return BadAlloc;
-    }
-    ppix[npix] = pixel;
-    pixp[client] = ppix;
-    nump[client]++;
-
-    return Success;
-}
-
 /* Comparison functions -- passed to FindColor to determine if an
  * entry is already the color we're looking for or not */
 static int
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 9208582..dbbac8b 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -108,6 +108,7 @@ int ProcInitialConnection();
 
 #include "windowstr.h"
 #include <X11/fonts/fontstruct.h>
+#include <X11/fonts/fontutil.h>
 #include "dixfontstr.h"
 #include "gcstruct.h"
 #include "selection.h"
diff --git a/dix/dixfonts.c b/dix/dixfonts.c
index be389e8..968cee4 100644
--- a/dix/dixfonts.c
+++ b/dix/dixfonts.c
@@ -156,7 +156,7 @@ SetDefaultFont(const char *defaultfontname)
  * init_fpe() and free_fpe(), there shouldn't be any problem in using
  * freed data.
  */
-void
+static void
 QueueFontWakeup(FontPathElementPtr fpe)
 {
     int i;
@@ -179,7 +179,7 @@ QueueFontWakeup(FontPathElementPtr fpe)
     num_slept_fpes++;
 }
 
-void
+static void
 RemoveFontWakeup(FontPathElementPtr fpe)
 {
     int i, j;
@@ -195,7 +195,7 @@ RemoveFontWakeup(FontPathElementPtr fpe)
     }
 }
 
-void
+static void
 FontWakeup(void *data, int count, void *LastSelectMask)
 {
     int i;
@@ -849,7 +849,7 @@ ListFonts(ClientPtr client, unsigned char *pattern, unsigned length,
     return Success;
 }
 
-int
+static int
 doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c)
 {
     FontPathElementPtr fpe;
@@ -1105,7 +1105,7 @@ static ChangeGCVal clearGC[] = { {.ptr = NullPixmap} };
 
 #define clearGCmask (GCClipMask)
 
-int
+static int
 doPolyText(ClientPtr client, PTclosurePtr c)
 {
     FontPtr pFont = c->pGC->font, oldpFont;
@@ -1389,7 +1389,7 @@ PolyText(ClientPtr client, DrawablePtr pDraw, GC * pGC, unsigned char *pElt,
 #undef TextEltHeader
 #undef FontShiftSize
 
-int
+static int
 doImageText(ClientPtr client, ITclosurePtr c)
 {
     int err = Success, lgerr;   /* err is in X error, not font error, space */
diff --git a/dix/enterleave.c b/dix/enterleave.c
index 7f1f941..f0b1572 100644
--- a/dix/enterleave.c
+++ b/dix/enterleave.c
@@ -212,7 +212,7 @@ SetFocusOut(DeviceIntPtr dev)
  * @return The window that is the first ancestor of both 'a' and 'b', or the
  *         NullWindow if they do not have a common ancestor.
  */
-WindowPtr
+static WindowPtr
 CommonAncestor(WindowPtr a, WindowPtr b)
 {
     for (b = b->parent; b; b = b->parent)
diff --git a/dix/enterleave.h b/dix/enterleave.h
index a59d057..4b833d8 100644
--- a/dix/enterleave.h
+++ b/dix/enterleave.h
@@ -41,8 +41,6 @@ extern void EnterLeaveEvent(DeviceIntPtr mouse,
                             int type,
                             int mode, int detail, WindowPtr pWin, Window child);
 
-extern WindowPtr CommonAncestor(WindowPtr a, WindowPtr b);
-
 extern void CoreEnterLeaveEvent(DeviceIntPtr mouse,
                                 int type,
                                 int mode,
diff --git a/dix/main.c b/dix/main.c
index 09f9504..db3b9c0 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -95,6 +95,8 @@ Equipment Corporation.
 #include "cursorstr.h"
 #include "selection.h"
 #include <X11/fonts/font.h>
+#include <X11/fonts/fontstruct.h>
+#include <X11/fonts/fontutil.h>
 #include "opaque.h"
 #include "servermd.h"
 #include "hotplug.h"
diff --git a/hw/xfree86/sdksyms.sh b/hw/xfree86/sdksyms.sh
index 05ac410..e141522 100755
--- a/hw/xfree86/sdksyms.sh
+++ b/hw/xfree86/sdksyms.sh
@@ -295,8 +295,6 @@ cat > sdksyms.c << EOF
 #include "selection.h"
 #include "servermd.h"
 #include "site.h"
-#include "swaprep.h"
-#include "swapreq.h"
 #include "validate.h"
 #include "window.h"
 #include "windowstr.h"
diff --git a/include/Makefile.am b/include/Makefile.am
index 738b582..70b83ff 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -52,8 +52,6 @@ sdk_HEADERS =		\
 	selection.h	\
 	servermd.h	\
 	site.h		\
-	swaprep.h	\
-	swapreq.h	\
 	validate.h	\
 	window.h	\
 	windowstr.h	\
@@ -74,5 +72,7 @@ EXTRA_DIST = 	\
 	dixfontstubs.h eventconvert.h eventstr.h inpututils.h \
 	probes.h \
 	protocol-versions.h \
+	swaprep.h \
+	swapreq.h \
 	systemd-logind.h \
 	xsha1.h
diff --git a/include/colormap.h b/include/colormap.h
index 5f6b97f..f3b18a6 100644
--- a/include/colormap.h
+++ b/include/colormap.h
@@ -108,18 +108,6 @@ extern _X_EXPORT void FakeAllocColor(ColormapPtr /*pmap */ ,
 extern _X_EXPORT void FakeFreeColor(ColormapPtr /*pmap */ ,
                                     Pixel /*pixel */ );
 
-typedef int (*ColorCompareProcPtr) (EntryPtr /*pent */ ,
-                                    xrgb * /*prgb */ );
-
-extern _X_EXPORT int FindColor(ColormapPtr /*pmap */ ,
-                               EntryPtr /*pentFirst */ ,
-                               int /*size */ ,
-                               xrgb * /*prgb */ ,
-                               Pixel * /*pPixel */ ,
-                               int /*channel */ ,
-                               int /*client */ ,
-                               ColorCompareProcPtr /*comp */ );
-
 extern _X_EXPORT int QueryColors(ColormapPtr /*pmap */ ,
                                  int /*count */ ,
                                  Pixel * /*ppixIn */ ,
diff --git a/include/dixfont.h b/include/dixfont.h
index 48c6305..1895509 100644
--- a/include/dixfont.h
+++ b/include/dixfont.h
@@ -36,14 +36,6 @@ typedef struct _DIXFontProp *DIXFontPropPtr;
 
 extern _X_EXPORT Bool SetDefaultFont(const char * /*defaultfontname */ );
 
-extern _X_EXPORT void QueueFontWakeup(FontPathElementPtr /*fpe */ );
-
-extern _X_EXPORT void RemoveFontWakeup(FontPathElementPtr /*fpe */ );
-
-extern _X_EXPORT void FontWakeup(void *data,
-                                 int count,
-                                 void *LastSelectMask);
-
 extern _X_EXPORT int OpenFont(ClientPtr /*client */ ,
                               XID /*fid */ ,
                               Mask /*flags */ ,
@@ -64,14 +56,6 @@ extern _X_EXPORT int ListFonts(ClientPtr /*client */ ,
                                unsigned int /*length */ ,
                                unsigned int /*max_names */ );
 
-extern _X_EXPORT int
- doListFontsWithInfo(ClientPtr /*client */ ,
-                     LFWIclosurePtr /*c */ );
-
-extern _X_EXPORT int doPolyText(ClientPtr /*client */ ,
-                                PTclosurePtr    /*c */
-    );
-
 extern _X_EXPORT int PolyText(ClientPtr /*client */ ,
                               DrawablePtr /*pDraw */ ,
                               GCPtr /*pGC */ ,
@@ -82,9 +66,6 @@ extern _X_EXPORT int PolyText(ClientPtr /*client */ ,
                               int /*reqType */ ,
                               XID /*did */ );
 
-extern _X_EXPORT int doImageText(ClientPtr /*client */ ,
-                                 ITclosurePtr /*c */ );
-
 extern _X_EXPORT int ImageText(ClientPtr /*client */ ,
                                DrawablePtr /*pDraw */ ,
                                GCPtr /*pGC */ ,
@@ -126,22 +107,6 @@ extern _X_EXPORT void dixGetGlyphs(FontPtr /*font */ ,
                                    unsigned long * /*glyphcount */ ,
                                    CharInfoPtr * /*glyphs */ );
 
-extern _X_EXPORT void QueryGlyphExtents(FontPtr /*pFont */ ,
-                                        CharInfoPtr * /*charinfo */ ,
-                                        unsigned long /*count */ ,
-                                        ExtentInfoPtr /*info */ );
-
-extern _X_EXPORT Bool QueryTextExtents(FontPtr /*pFont */ ,
-                                       unsigned long /*count */ ,
-                                       unsigned char * /*chars */ ,
-                                       ExtentInfoPtr /*info */ );
-
-extern _X_EXPORT Bool ParseGlyphCachingMode(char * /*str */ );
-
-extern _X_EXPORT void InitGlyphCaching(void);
-
-extern _X_EXPORT void SetGlyphCachingMode(int /*newmode */ );
-
 extern _X_EXPORT void register_fpe_functions(void);
 
 #endif                          /* DIXFONT_H */
diff --git a/include/dixstruct.h b/include/dixstruct.h
index 6c13895..7575066 100644
--- a/include/dixstruct.h
+++ b/include/dixstruct.h
@@ -126,21 +126,18 @@ SetReqFds(ClientPtr client, int req_fds) {
 /*
  * Scheduling interface
  */
-extern _X_EXPORT long SmartScheduleTime;
-extern _X_EXPORT long SmartScheduleInterval;
-extern _X_EXPORT long SmartScheduleSlice;
-extern _X_EXPORT long SmartScheduleMaxSlice;
-extern _X_EXPORT Bool SmartScheduleDisable;
-extern _X_EXPORT void
-SmartScheduleStartTimer(void);
-extern _X_EXPORT void
-SmartScheduleStopTimer(void);
+extern long SmartScheduleTime;
+extern long SmartScheduleInterval;
+extern long SmartScheduleSlice;
+extern long SmartScheduleMaxSlice;
+extern Bool SmartScheduleDisable;
+extern void SmartScheduleStartTimer(void);
+extern void SmartScheduleStopTimer(void);
 
 #define SMART_MAX_PRIORITY  (20)
 #define SMART_MIN_PRIORITY  (-20)
 
-extern _X_EXPORT void
-SmartScheduleInit(void);
+extern void SmartScheduleInit(void);
 
 /* This prototype is used pervasively in Xext, dix */
 #define DISPATCH_PROC(func) int func(ClientPtr /* client */)
@@ -179,13 +176,13 @@ typedef struct _CallbackList {
 
 /* proc vectors */
 
-extern _X_EXPORT int (*InitialVector[3]) (ClientPtr /*client */ );
+extern int (*InitialVector[3]) (ClientPtr /*client */ );
 
 extern _X_EXPORT int (*ProcVector[256]) (ClientPtr /*client */ );
 
 extern _X_EXPORT int (*SwappedProcVector[256]) (ClientPtr /*client */ );
 
-extern _X_EXPORT ReplySwapPtr ReplySwapVector[256];
+extern ReplySwapPtr ReplySwapVector[256];
 
 extern _X_EXPORT int
 ProcBadRequest(ClientPtr /*client */ );
diff --git a/include/swaprep.h b/include/swaprep.h
index 3fa2a09..63c54c7 100644
--- a/include/swaprep.h
+++ b/include/swaprep.h
@@ -26,207 +26,207 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #ifndef SWAPREP_H
 #define SWAPREP_H 1
 
-extern _X_EXPORT void Swap32Write(ClientPtr /* pClient */ ,
-                                  int /* size */ ,
-                                  CARD32 * /* pbuf */ );
+extern void Swap32Write(ClientPtr /* pClient */ ,
+                        int /* size */ ,
+                        CARD32 * /* pbuf */ );
 
-extern _X_EXPORT void CopySwap32Write(ClientPtr /* pClient */ ,
-                                      int /* size */ ,
-                                      CARD32 * /* pbuf */ );
+extern void CopySwap32Write(ClientPtr /* pClient */ ,
+                            int /* size */ ,
+                            CARD32 * /* pbuf */ );
+
+extern void CopySwap16Write(ClientPtr /* pClient */ ,
+                            int /* size */ ,
+                            short * /* pbuf */ );
+
+extern void SGenericReply(ClientPtr /* pClient */ ,
+                          int /* size */ ,
+                          xGenericReply * /* pRep */ );
 
-extern _X_EXPORT void CopySwap16Write(ClientPtr /* pClient */ ,
+extern void SGetWindowAttributesReply(ClientPtr /* pClient */ ,
                                       int /* size */ ,
-                                      short * /* pbuf */ );
+                                      xGetWindowAttributesReply *
+                                      /* pRep */ );
+
+extern void SGetGeometryReply(ClientPtr /* pClient */ ,
+                              int /* size */ ,
+                              xGetGeometryReply * /* pRep */ );
+
+extern void SQueryTreeReply(ClientPtr /* pClient */ ,
+                            int /* size */ ,
+                            xQueryTreeReply * /* pRep */ );
+
+extern void SInternAtomReply(ClientPtr /* pClient */ ,
+                             int /* size */ ,
+                             xInternAtomReply * /* pRep */ );
+
+extern void SGetAtomNameReply(ClientPtr /* pClient */ ,
+                              int /* size */ ,
+                              xGetAtomNameReply * /* pRep */ );
 
-extern _X_EXPORT void SGenericReply(ClientPtr /* pClient */ ,
+extern void SGetPropertyReply(ClientPtr /* pClient */ ,
+                              int /* size */ ,
+                              xGetPropertyReply * /* pRep */ );
+
+extern void SListPropertiesReply(ClientPtr /* pClient */ ,
+                                 int /* size */ ,
+                                 xListPropertiesReply * /* pRep */ );
+
+extern void SGetSelectionOwnerReply(ClientPtr /* pClient */ ,
                                     int /* size */ ,
-                                    xGenericReply * /* pRep */ );
+                                    xGetSelectionOwnerReply *
+                                    /* pRep */ );
 
-extern _X_EXPORT void SGetWindowAttributesReply(ClientPtr /* pClient */ ,
-                                                int /* size */ ,
-                                                xGetWindowAttributesReply *
-                                                /* pRep */ );
+extern void SQueryPointerReply(ClientPtr /* pClient */ ,
+                               int /* size */ ,
+                               xQueryPointerReply * /* pRep */ );
 
-extern _X_EXPORT void SGetGeometryReply(ClientPtr /* pClient */ ,
-                                        int /* size */ ,
-                                        xGetGeometryReply * /* pRep */ );
+extern void SwapTimeCoordWrite(ClientPtr /* pClient */ ,
+                               int /* size */ ,
+                               xTimecoord * /* pRep */ );
 
-extern _X_EXPORT void SQueryTreeReply(ClientPtr /* pClient */ ,
-                                      int /* size */ ,
-                                      xQueryTreeReply * /* pRep */ );
+extern void SGetMotionEventsReply(ClientPtr /* pClient */ ,
+                                  int /* size */ ,
+                                  xGetMotionEventsReply *       /* pRep */
+    );
 
-extern _X_EXPORT void SInternAtomReply(ClientPtr /* pClient */ ,
-                                       int /* size */ ,
-                                       xInternAtomReply * /* pRep */ );
+extern void STranslateCoordsReply(ClientPtr /* pClient */ ,
+                                  int /* size */ ,
+                                  xTranslateCoordsReply *       /* pRep */
+    );
 
-extern _X_EXPORT void SGetAtomNameReply(ClientPtr /* pClient */ ,
-                                        int /* size */ ,
-                                        xGetAtomNameReply * /* pRep */ );
+extern void SGetInputFocusReply(ClientPtr /* pClient */ ,
+                                int /* size */ ,
+                                xGetInputFocusReply * /* pRep */ );
 
-extern _X_EXPORT void SGetPropertyReply(ClientPtr /* pClient */ ,
-                                        int /* size */ ,
-                                        xGetPropertyReply * /* pRep */ );
+extern void SQueryKeymapReply(ClientPtr /* pClient */ ,
+                              int /* size */ ,
+                              xQueryKeymapReply * /* pRep */ );
 
-extern _X_EXPORT void SListPropertiesReply(ClientPtr /* pClient */ ,
-                                           int /* size */ ,
-                                           xListPropertiesReply * /* pRep */ );
+extern void SQueryFontReply(ClientPtr /* pClient */ ,
+                            int /* size */ ,
+                            xQueryFontReply * /* pRep */ );
 
-extern _X_EXPORT void SGetSelectionOwnerReply(ClientPtr /* pClient */ ,
-                                              int /* size */ ,
-                                              xGetSelectionOwnerReply *
-                                              /* pRep */ );
+extern void SQueryTextExtentsReply(ClientPtr /* pClient */ ,
+                                   int /* size */ ,
+                                   xQueryTextExtentsReply *     /* pRep */
+    );
 
-extern _X_EXPORT void SQueryPointerReply(ClientPtr /* pClient */ ,
-                                         int /* size */ ,
-                                         xQueryPointerReply * /* pRep */ );
+extern void SListFontsReply(ClientPtr /* pClient */ ,
+                            int /* size */ ,
+                            xListFontsReply * /* pRep */ );
 
-extern _X_EXPORT void SwapTimeCoordWrite(ClientPtr /* pClient */ ,
-                                         int /* size */ ,
-                                         xTimecoord * /* pRep */ );
+extern void SListFontsWithInfoReply(ClientPtr /* pClient */ ,
+                                    int /* size */ ,
+                                    xListFontsWithInfoReply *
+                                    /* pRep */ );
 
-extern _X_EXPORT void SGetMotionEventsReply(ClientPtr /* pClient */ ,
-                                            int /* size */ ,
-                                            xGetMotionEventsReply * /* pRep */
-                                            );
+extern void SGetFontPathReply(ClientPtr /* pClient */ ,
+                              int /* size */ ,
+                              xGetFontPathReply * /* pRep */ );
 
-extern _X_EXPORT void STranslateCoordsReply(ClientPtr /* pClient */ ,
-                                            int /* size */ ,
-                                            xTranslateCoordsReply * /* pRep */
-                                            );
+extern void SGetImageReply(ClientPtr /* pClient */ ,
+                           int /* size */ ,
+                           xGetImageReply * /* pRep */ );
 
-extern _X_EXPORT void SGetInputFocusReply(ClientPtr /* pClient */ ,
-                                          int /* size */ ,
-                                          xGetInputFocusReply * /* pRep */ );
+extern void SListInstalledColormapsReply(ClientPtr /* pClient */ ,
+                                         int /* size */ ,
+                                         xListInstalledColormapsReply
+                                         * /* pRep */ );
 
-extern _X_EXPORT void SQueryKeymapReply(ClientPtr /* pClient */ ,
-                                        int /* size */ ,
-                                        xQueryKeymapReply * /* pRep */ );
+extern void SAllocColorReply(ClientPtr /* pClient */ ,
+                             int /* size */ ,
+                             xAllocColorReply * /* pRep */ );
 
-extern _X_EXPORT void SQueryFontReply(ClientPtr /* pClient */ ,
-                                      int /* size */ ,
-                                      xQueryFontReply * /* pRep */ );
+extern void SAllocNamedColorReply(ClientPtr /* pClient */ ,
+                                  int /* size */ ,
+                                  xAllocNamedColorReply *       /* pRep */
+    );
 
-extern _X_EXPORT void SQueryTextExtentsReply(ClientPtr /* pClient */ ,
-                                             int /* size */ ,
-                                             xQueryTextExtentsReply * /* pRep */
-                                             );
+extern void SAllocColorCellsReply(ClientPtr /* pClient */ ,
+                                  int /* size */ ,
+                                  xAllocColorCellsReply *       /* pRep */
+    );
 
-extern _X_EXPORT void SListFontsReply(ClientPtr /* pClient */ ,
-                                      int /* size */ ,
-                                      xListFontsReply * /* pRep */ );
+extern void SAllocColorPlanesReply(ClientPtr /* pClient */ ,
+                                   int /* size */ ,
+                                   xAllocColorPlanesReply *     /* pRep */
+    );
 
-extern _X_EXPORT void SListFontsWithInfoReply(ClientPtr /* pClient */ ,
-                                              int /* size */ ,
-                                              xListFontsWithInfoReply *
-                                              /* pRep */ );
+extern void SQColorsExtend(ClientPtr /* pClient */ ,
+                           int /* size */ ,
+                           xrgb * /* prgb */ );
 
-extern _X_EXPORT void SGetFontPathReply(ClientPtr /* pClient */ ,
-                                        int /* size */ ,
-                                        xGetFontPathReply * /* pRep */ );
+extern void SQueryColorsReply(ClientPtr /* pClient */ ,
+                              int /* size */ ,
+                              xQueryColorsReply * /* pRep */ );
 
-extern _X_EXPORT void SGetImageReply(ClientPtr /* pClient */ ,
-                                     int /* size */ ,
-                                     xGetImageReply * /* pRep */ );
+extern void SLookupColorReply(ClientPtr /* pClient */ ,
+                              int /* size */ ,
+                              xLookupColorReply * /* pRep */ );
 
-extern _X_EXPORT void SListInstalledColormapsReply(ClientPtr /* pClient */ ,
-                                                   int /* size */ ,
-                                                   xListInstalledColormapsReply
-                                                   * /* pRep */ );
+extern void SQueryBestSizeReply(ClientPtr /* pClient */ ,
+                                int /* size */ ,
+                                xQueryBestSizeReply * /* pRep */ );
 
-extern _X_EXPORT void SAllocColorReply(ClientPtr /* pClient */ ,
-                                       int /* size */ ,
-                                       xAllocColorReply * /* pRep */ );
+extern void SListExtensionsReply(ClientPtr /* pClient */ ,
+                                 int /* size */ ,
+                                 xListExtensionsReply * /* pRep */ );
 
-extern _X_EXPORT void SAllocNamedColorReply(ClientPtr /* pClient */ ,
-                                            int /* size */ ,
-                                            xAllocNamedColorReply * /* pRep */
-                                            );
+extern void SGetKeyboardMappingReply(ClientPtr /* pClient */ ,
+                                     int /* size */ ,
+                                     xGetKeyboardMappingReply *
+                                     /* pRep */ );
 
-extern _X_EXPORT void SAllocColorCellsReply(ClientPtr /* pClient */ ,
-                                            int /* size */ ,
-                                            xAllocColorCellsReply * /* pRep */
-                                            );
+extern void SGetPointerMappingReply(ClientPtr /* pClient */ ,
+                                    int /* size */ ,
+                                    xGetPointerMappingReply *
+                                    /* pRep */ );
 
-extern _X_EXPORT void SAllocColorPlanesReply(ClientPtr /* pClient */ ,
-                                             int /* size */ ,
-                                             xAllocColorPlanesReply * /* pRep */
-                                             );
+extern void SGetModifierMappingReply(ClientPtr /* pClient */ ,
+                                     int /* size */ ,
+                                     xGetModifierMappingReply *
+                                     /* pRep */ );
 
-extern _X_EXPORT void SQColorsExtend(ClientPtr /* pClient */ ,
+extern void SGetKeyboardControlReply(ClientPtr /* pClient */ ,
                                      int /* size */ ,
-                                     xrgb * /* prgb */ );
-
-extern _X_EXPORT void SQueryColorsReply(ClientPtr /* pClient */ ,
-                                        int /* size */ ,
-                                        xQueryColorsReply * /* pRep */ );
-
-extern _X_EXPORT void SLookupColorReply(ClientPtr /* pClient */ ,
-                                        int /* size */ ,
-                                        xLookupColorReply * /* pRep */ );
-
-extern _X_EXPORT void SQueryBestSizeReply(ClientPtr /* pClient */ ,
-                                          int /* size */ ,
-                                          xQueryBestSizeReply * /* pRep */ );
-
-extern _X_EXPORT void SListExtensionsReply(ClientPtr /* pClient */ ,
-                                           int /* size */ ,
-                                           xListExtensionsReply * /* pRep */ );
-
-extern _X_EXPORT void SGetKeyboardMappingReply(ClientPtr /* pClient */ ,
-                                               int /* size */ ,
-                                               xGetKeyboardMappingReply *
-                                               /* pRep */ );
-
-extern _X_EXPORT void SGetPointerMappingReply(ClientPtr /* pClient */ ,
-                                              int /* size */ ,
-                                              xGetPointerMappingReply *
-                                              /* pRep */ );
-
-extern _X_EXPORT void SGetModifierMappingReply(ClientPtr /* pClient */ ,
-                                               int /* size */ ,
-                                               xGetModifierMappingReply *
-                                               /* pRep */ );
-
-extern _X_EXPORT void SGetKeyboardControlReply(ClientPtr /* pClient */ ,
-                                               int /* size */ ,
-                                               xGetKeyboardControlReply *
-                                               /* pRep */ );
-
-extern _X_EXPORT void SGetPointerControlReply(ClientPtr /* pClient */ ,
-                                              int /* size */ ,
-                                              xGetPointerControlReply *
-                                              /* pRep */ );
-
-extern _X_EXPORT void SGetScreenSaverReply(ClientPtr /* pClient */ ,
-                                           int /* size */ ,
-                                           xGetScreenSaverReply * /* pRep */ );
-
-extern _X_EXPORT void SLHostsExtend(ClientPtr /* pClient */ ,
+                                     xGetKeyboardControlReply *
+                                     /* pRep */ );
+
+extern void SGetPointerControlReply(ClientPtr /* pClient */ ,
                                     int /* size */ ,
-                                    char * /* buf */ );
+                                    xGetPointerControlReply *
+                                    /* pRep */ );
 
-extern _X_EXPORT void SListHostsReply(ClientPtr /* pClient */ ,
-                                      int /* size */ ,
-                                      xListHostsReply * /* pRep */ );
+extern void SGetScreenSaverReply(ClientPtr /* pClient */ ,
+                                 int /* size */ ,
+                                 xGetScreenSaverReply * /* pRep */ );
+
+extern void SLHostsExtend(ClientPtr /* pClient */ ,
+                          int /* size */ ,
+                          char * /* buf */ );
+
+extern void SListHostsReply(ClientPtr /* pClient */ ,
+                            int /* size */ ,
+                            xListHostsReply * /* pRep */ );
 
-extern _X_EXPORT void SErrorEvent(xError * /* from */ ,
-                                  xError * /* to */ );
+extern void SErrorEvent(xError * /* from */ ,
+                        xError * /* to */ );
 
-extern _X_EXPORT void SwapConnSetupInfo(char * /* pInfo */ ,
-                                        char * /* pInfoTBase */ );
+extern void SwapConnSetupInfo(char * /* pInfo */ ,
+                              char * /* pInfoTBase */ );
 
-extern _X_EXPORT void WriteSConnectionInfo(ClientPtr /* pClient */ ,
-                                           unsigned long /* size */ ,
-                                           char * /* pInfo */ );
+extern void WriteSConnectionInfo(ClientPtr /* pClient */ ,
+                                 unsigned long /* size */ ,
+                                 char * /* pInfo */ );
 
-extern _X_EXPORT void SwapConnSetupPrefix(xConnSetupPrefix * /* pcspFrom */ ,
-                                          xConnSetupPrefix * /* pcspTo */ );
+extern void SwapConnSetupPrefix(xConnSetupPrefix * /* pcspFrom */ ,
+                                xConnSetupPrefix * /* pcspTo */ );
 
-extern _X_EXPORT void WriteSConnSetupPrefix(ClientPtr /* pClient */ ,
-                                            xConnSetupPrefix * /* pcsp */ );
+extern void WriteSConnSetupPrefix(ClientPtr /* pClient */ ,
+                                  xConnSetupPrefix * /* pcsp */ );
 
 #undef SWAPREP_PROC
-#define SWAPREP_PROC(func) extern _X_EXPORT void func(xEvent * /* from */, xEvent * /* to */)
+#define SWAPREP_PROC(func) extern void func(xEvent * /* from */, xEvent * /* to */)
 
 SWAPREP_PROC(SCirculateEvent);
 SWAPREP_PROC(SClientMessageEvent);
diff --git a/include/swapreq.h b/include/swapreq.h
index 07eff80..d696aa0 100644
--- a/include/swapreq.h
+++ b/include/swapreq.h
@@ -26,13 +26,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #ifndef SWAPREQ_H
 #define SWAPREQ_H 1
 
-extern _X_EXPORT void SwapColorItem(xColorItem * /* pItem */ );
+extern void SwapColorItem(xColorItem * /* pItem */ );
 
-extern _X_EXPORT void SwapConnClientPrefix(xConnClientPrefix * /* pCCP */ );
+extern void SwapConnClientPrefix(xConnClientPrefix * /* pCCP */ );
 
 #undef SWAPREQ_PROC
 
-#define SWAPREQ_PROC(func) extern _X_EXPORT int func(ClientPtr /* client */)
+#define SWAPREQ_PROC(func) extern int func(ClientPtr /* client */)
 
 SWAPREQ_PROC(SProcAllocColor);
 SWAPREQ_PROC(SProcAllocColorCells);
diff --git a/mi/miglblt.c b/mi/miglblt.c
index e9d3a1a..46268ae 100644
--- a/mi/miglblt.c
+++ b/mi/miglblt.c
@@ -53,6 +53,7 @@ SOFTWARE.
 #include	<X11/Xproto.h>
 #include	"misc.h"
 #include	<X11/fonts/fontstruct.h>
+#include	<X11/fonts/fontutil.h>
 #include	"dixfontstr.h"
 #include	"gcstruct.h"
 #include	"windowstr.h"
diff --git a/miext/damage/damage.c b/miext/damage/damage.c
index ce20169..746e798 100644
--- a/miext/damage/damage.c
+++ b/miext/damage/damage.c
@@ -32,6 +32,7 @@
 #include    <X11/fonts/font.h>
 #include    "dixfontstr.h"
 #include    <X11/fonts/fontstruct.h>
+#include    <X11/fonts/fontutil.h>
 #include    "mi.h"
 #include    "regionstr.h"
 #include    "globals.h"
diff --git a/os/utils.c b/os/utils.c
index 7fd395b..d09ca79 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -81,6 +81,7 @@ __stdcall unsigned long GetTickCount(void);
 #include <X11/Xtrans/Xtrans.h>
 #include "input.h"
 #include "dixfont.h"
+#include <X11/fonts/fontutil.h>
 #include "osdep.h"
 #include "extension.h"
 #ifdef X_POSIX_C_SOURCE
commit c4a0d6c9139d2c0107b80420cc2342614bbe95ef
Author: Adam Jackson <ajax at redhat.com>
Date:   Wed Oct 22 10:47:03 2014 -0400

    dri3: static cleanup
    
    Also remove unused window private key.
    
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/dri3/dri3.c b/dri3/dri3.c
index 385862a..d042b8b 100644
--- a/dri3/dri3.c
+++ b/dri3/dri3.c
@@ -26,9 +26,8 @@
 
 #include "dri3_priv.h"
 
-int dri3_request;
+static int dri3_request;
 DevPrivateKeyRec dri3_screen_private_key;
-DevPrivateKeyRec dri3_window_private_key;
 
 static int dri3_screen_generation;
 
diff --git a/dri3/dri3_priv.h b/dri3/dri3_priv.h
index e2fed83..e61ef22 100644
--- a/dri3/dri3_priv.h
+++ b/dri3/dri3_priv.h
@@ -32,8 +32,6 @@
 #include <randrstr.h>
 #include "dri3.h"
 
-extern int dri3_request;
-
 extern DevPrivateKeyRec dri3_screen_private_key;
 
 typedef struct dri3_screen_priv {
commit a69e9027e167a83281b96e13f3a77100876b72ae
Author: Adam Jackson <ajax at redhat.com>
Date:   Wed Oct 22 10:44:36 2014 -0400

    dri3: Remove unbuilt dri3_event.c
    
    The config notifies live in present, not dri3.
    
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/dri3/dri3_event.c b/dri3/dri3_event.c
deleted file mode 100644
index cb509a2..0000000
--- a/dri3/dri3_event.c
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Copyright © 2013 Keith Packard
- *
- * 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 the copyright holders not be used in advertising or
- * publicity pertaining to distribution of the software without specific,
- * written prior permission.  The copyright holders make no representations
- * about the suitability of this software for any purpose.  It is provided "as
- * is" without express or implied warranty.
- *
- * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL THE COPYRIGHT HOLDERS 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.
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "dri3_priv.h"
-
-RESTYPE dri3_event_type;
-
-static int
-dri3_free_event(void *data, XID id)
-{
-    dri3_event_ptr dri3_event = (dri3_event_ptr) data;
-    dri3_window_priv_ptr window_priv = dri3_window_priv(dri3_event->window);
-    dri3_event_ptr *previous, current;
-
-    for (previous = &window_priv->events; (current = *previous); previous = &current->next) {
-        if (current == dri3_event) {
-            *previous = dri3_event->next;
-            break;
-        }
-    }
-    free((void *) dri3_event);
-    return 1;
-
-}
-
-void
-dri3_free_events(WindowPtr window)
-{
-    dri3_window_priv_ptr window_priv = dri3_window_priv(window);
-    dri3_event_ptr event;
-
-    if (!window_priv)
-        return;
-
-    while ((event = window_priv->events))
-        FreeResource(event->id, RT_NONE);
-}
-
-static void
-dri3_event_swap(xGenericEvent *from, xGenericEvent *to)
-{
-    *to = *from;
-    swaps(&to->sequenceNumber);
-    swapl(&to->length);
-    swaps(&to->evtype);
-    switch (from->evtype) {
-    case DRI3_ConfigureNotify: {
-        xDRI3ConfigureNotify *c = (xDRI3ConfigureNotify *) to;
-
-        swapl(&c->eid);
-        swapl(&c->window);
-        swaps(&c->x);
-        swaps(&c->y);
-        swaps(&c->width);
-        swaps(&c->height);
-        swaps(&c->off_x);
-        swaps(&c->off_y);
-        swaps(&c->pixmap_width);
-        swaps(&c->pixmap_height);
-        swapl(&c->pixmap_flags);
-        break;
-    }
-    }
-}
-
-void
-dri3_send_config_notify(WindowPtr window, int x, int y, int w, int h, int bw, WindowPtr sibling)
-{
-    dri3_window_priv_ptr window_priv = dri3_window_priv(window);
-
-    if (window_priv) {
-        xDRI3ConfigureNotify cn = {
-            .type = GenericEvent,
-            .extension = dri3_request,
-            .length = (sizeof(xDRI3ConfigureNotify) - 32) >> 2,
-            .evtype = DRI3_ConfigureNotify,
-            .eid = 0,
-            .window = window->drawable.id,
-            .x = x,
-            .y = y,
-            .width = w,
-            .height = h,
-            .off_x = 0,
-            .off_y = 0,
-            .pixmap_width = w,
-            .pixmap_height = h,
-            .pixmap_flags = 0
-        };
-        dri3_event_ptr event;
-        dri3_screen_priv_ptr screen_priv = dri3_screen_priv(window->drawable.pScreen);
-
-        if (screen_priv->info && screen_priv->info->driver_config)
-            screen_priv->info->driver_config(window, &cn);
-
-        for (event = window_priv->events; event; event = event->next) {
-            if (event->mask & (1 << DRI3ConfigureNotify)) {
-                cn.eid = event->id;
-                WriteEventsToClient(event->client, 1, (xEvent *) &cn);
-            }
-        }
-    }
-}
-
-int
-dri3_select_input(ClientPtr client, XID eid, WindowPtr window, CARD32 mask)
-{
-    dri3_window_priv_ptr window_priv = dri3_window_priv(window);
-    dri3_event_ptr event;
-
-    if (!window_priv)
-        return BadAlloc;
-
-    event = calloc (1, sizeof (dri3_event_rec));
-    if (!event)
-        return BadAlloc;
-
-    event->client = client;
-    event->window = window;
-    event->id = eid;
-    event->mask = mask;
-
-    event->next = window_priv->events;
-    window_priv->events = event;
-
-    if (!AddResource(event->id, dri3_event_type, (void *) event))
-        return BadAlloc;
-
-    return Success;
-}
-
-Bool
-dri3_event_init(void)
-{
-    dri3_event_type = CreateNewResourceType(dri3_free_event, "DRI3Event");
-    if (!dri3_event_type)
-        return FALSE;
-
-    GERegisterExtension(dri3_request, dri3_event_swap);
-    return TRUE;
-}
commit 91f0d71c18254746e1d519f0d19d11f756a9588c
Author: Adam Jackson <ajax at redhat.com>
Date:   Wed Oct 22 10:38:11 2014 -0400

    parser: static cleanup
    
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/parser/InputClass.c b/hw/xfree86/parser/InputClass.c
index c2fbd22..29bd9fa 100644
--- a/hw/xfree86/parser/InputClass.c
+++ b/hw/xfree86/parser/InputClass.c
@@ -58,6 +58,82 @@ xf86ConfigSymTabRec InputClassTab[] = {
     {-1, ""},
 };
 
+static void
+xf86freeInputClassList(XF86ConfInputClassPtr ptr)
+{
+    XF86ConfInputClassPtr prev;
+
+    while (ptr) {
+        xf86MatchGroup *group, *next;
+        char **list;
+
+        TestFree(ptr->identifier);
+        TestFree(ptr->driver);
+
+        xorg_list_for_each_entry_safe(group, next, &ptr->match_product, entry) {
+            xorg_list_del(&group->entry);
+            for (list = group->values; *list; list++)
+                free(*list);
+            free(group);
+        }
+        xorg_list_for_each_entry_safe(group, next, &ptr->match_vendor, entry) {
+            xorg_list_del(&group->entry);
+            for (list = group->values; *list; list++)
+                free(*list);
+            free(group);
+        }
+        xorg_list_for_each_entry_safe(group, next, &ptr->match_device, entry) {
+            xorg_list_del(&group->entry);
+            for (list = group->values; *list; list++)
+                free(*list);
+            free(group);
+        }
+        xorg_list_for_each_entry_safe(group, next, &ptr->match_os, entry) {
+            xorg_list_del(&group->entry);
+            for (list = group->values; *list; list++)
+                free(*list);
+            free(group);
+        }
+        xorg_list_for_each_entry_safe(group, next, &ptr->match_pnpid, entry) {
+            xorg_list_del(&group->entry);
+            for (list = group->values; *list; list++)
+                free(*list);
+            free(group);
+        }
+        xorg_list_for_each_entry_safe(group, next, &ptr->match_usbid, entry) {
+            xorg_list_del(&group->entry);
+            for (list = group->values; *list; list++)
+                free(*list);
+            free(group);
+        }
+        xorg_list_for_each_entry_safe(group, next, &ptr->match_driver, entry) {
+            xorg_list_del(&group->entry);
+            for (list = group->values; *list; list++)
+                free(*list);
+            free(group);
+        }
+        xorg_list_for_each_entry_safe(group, next, &ptr->match_tag, entry) {
+            xorg_list_del(&group->entry);
+            for (list = group->values; *list; list++)
+                free(*list);
+            free(group);
+        }
+        xorg_list_for_each_entry_safe(group, next, &ptr->match_layout, entry) {
+            xorg_list_del(&group->entry);
+            for (list = group->values; *list; list++)
+                free(*list);
+            free(group);
+        }
+
+        TestFree(ptr->comment);
+        xf86optionListFree(ptr->option_lst);
+
+        prev = ptr;
+        ptr = ptr->list.next;
+        free(prev);
+    }
+}
+
 #define CLEANUP xf86freeInputClassList
 
 #define TOKEN_SEP "|"
@@ -354,79 +430,3 @@ xf86printInputClassSection(FILE * cf, XF86ConfInputClassPtr ptr)
         ptr = ptr->list.next;
     }
 }
-
-void
-xf86freeInputClassList(XF86ConfInputClassPtr ptr)
-{
-    XF86ConfInputClassPtr prev;
-
-    while (ptr) {
-        xf86MatchGroup *group, *next;
-        char **list;
-
-        TestFree(ptr->identifier);
-        TestFree(ptr->driver);
-
-        xorg_list_for_each_entry_safe(group, next, &ptr->match_product, entry) {
-            xorg_list_del(&group->entry);
-            for (list = group->values; *list; list++)
-                free(*list);
-            free(group);
-        }
-        xorg_list_for_each_entry_safe(group, next, &ptr->match_vendor, entry) {
-            xorg_list_del(&group->entry);
-            for (list = group->values; *list; list++)
-                free(*list);
-            free(group);
-        }
-        xorg_list_for_each_entry_safe(group, next, &ptr->match_device, entry) {
-            xorg_list_del(&group->entry);
-            for (list = group->values; *list; list++)
-                free(*list);
-            free(group);
-        }
-        xorg_list_for_each_entry_safe(group, next, &ptr->match_os, entry) {
-            xorg_list_del(&group->entry);
-            for (list = group->values; *list; list++)
-                free(*list);
-            free(group);
-        }
-        xorg_list_for_each_entry_safe(group, next, &ptr->match_pnpid, entry) {
-            xorg_list_del(&group->entry);
-            for (list = group->values; *list; list++)
-                free(*list);
-            free(group);
-        }
-        xorg_list_for_each_entry_safe(group, next, &ptr->match_usbid, entry) {
-            xorg_list_del(&group->entry);
-            for (list = group->values; *list; list++)
-                free(*list);
-            free(group);
-        }
-        xorg_list_for_each_entry_safe(group, next, &ptr->match_driver, entry) {
-            xorg_list_del(&group->entry);
-            for (list = group->values; *list; list++)
-                free(*list);
-            free(group);
-        }
-        xorg_list_for_each_entry_safe(group, next, &ptr->match_tag, entry) {
-            xorg_list_del(&group->entry);
-            for (list = group->values; *list; list++)
-                free(*list);
-            free(group);
-        }
-        xorg_list_for_each_entry_safe(group, next, &ptr->match_layout, entry) {
-            xorg_list_del(&group->entry);
-            for (list = group->values; *list; list++)
-                free(*list);
-            free(group);
-        }
-
-        TestFree(ptr->comment);
-        xf86optionListFree(ptr->option_lst);
-
-        prev = ptr;
-        ptr = ptr->list.next;
-        free(prev);
-    }
-}
diff --git a/hw/xfree86/parser/OutputClass.c b/hw/xfree86/parser/OutputClass.c
index 7e9a8ac..3f2082e 100644
--- a/hw/xfree86/parser/OutputClass.c
+++ b/hw/xfree86/parser/OutputClass.c
@@ -41,6 +41,32 @@ xf86ConfigSymTabRec OutputClassTab[] = {
     {-1, ""},
 };
 
+static void
+xf86freeOutputClassList(XF86ConfOutputClassPtr ptr)
+{
+    XF86ConfOutputClassPtr prev;
+
+    while (ptr) {
+        xf86MatchGroup *group, *next;
+        char **list;
+
+        TestFree(ptr->identifier);
+        TestFree(ptr->comment);
+        TestFree(ptr->driver);
+
+        xorg_list_for_each_entry_safe(group, next, &ptr->match_driver, entry) {
+            xorg_list_del(&group->entry);
+            for (list = group->values; *list; list++)
+                free(*list);
+            free(group);
+        }
+
+        prev = ptr;
+        ptr = ptr->list.next;
+        free(prev);
+    }
+}
+
 #define CLEANUP xf86freeOutputClassList
 
 #define TOKEN_SEP "|"
@@ -139,29 +165,3 @@ xf86printOutputClassSection(FILE * cf, XF86ConfOutputClassPtr ptr)
         ptr = ptr->list.next;
     }
 }
-
-void
-xf86freeOutputClassList(XF86ConfOutputClassPtr ptr)
-{
-    XF86ConfOutputClassPtr prev;
-
-    while (ptr) {
-        xf86MatchGroup *group, *next;
-        char **list;
-
-        TestFree(ptr->identifier);
-        TestFree(ptr->comment);
-        TestFree(ptr->driver);
-
-        xorg_list_for_each_entry_safe(group, next, &ptr->match_driver, entry) {
-            xorg_list_del(&group->entry);
-            for (list = group->values; *list; list++)
-                free(*list);
-            free(group);
-        }
-
-        prev = ptr;
-        ptr = ptr->list.next;
-        free(prev);
-    }
-}
diff --git a/hw/xfree86/parser/Screen.c b/hw/xfree86/parser/Screen.c
index b5b454f..4731970 100644
--- a/hw/xfree86/parser/Screen.c
+++ b/hw/xfree86/parser/Screen.c
@@ -76,6 +76,33 @@ static xf86ConfigSymTabRec DisplayTab[] = {
     {-1, ""},
 };
 
+static void
+xf86freeModeList(XF86ModePtr ptr)
+{
+    XF86ModePtr prev;
+
+    while (ptr) {
+        TestFree(ptr->mode_name);
+        prev = ptr;
+        ptr = ptr->list.next;
+        free(prev);
+    }
+}
+
+static void
+xf86freeDisplayList(XF86ConfDisplayPtr ptr)
+{
+    XF86ConfDisplayPtr prev;
+
+    while (ptr) {
+        xf86freeModeList(ptr->disp_mode_lst);
+        xf86optionListFree(ptr->disp_option_lst);
+        prev = ptr;
+        ptr = ptr->list.next;
+        free(prev);
+    }
+}
+
 #define CLEANUP xf86freeDisplayList
 
 static XF86ConfDisplayPtr
@@ -433,28 +460,7 @@ xf86printScreenSection(FILE * cf, XF86ConfScreenPtr ptr)
 
 }
 
-void
-xf86freeScreenList(XF86ConfScreenPtr ptr)
-{
-    XF86ConfScreenPtr prev;
-    int i;
-    while (ptr) {
-        TestFree(ptr->scrn_identifier);
-        TestFree(ptr->scrn_monitor_str);
-        TestFree(ptr->scrn_device_str);
-        for (i = 0; i < ptr->num_gpu_devices; i++)
-            TestFree(ptr->scrn_gpu_device_str[i]);
-        TestFree(ptr->scrn_comment);
-        xf86optionListFree(ptr->scrn_option_lst);
-        xf86freeAdaptorLinkList(ptr->scrn_adaptor_lst);
-        xf86freeDisplayList(ptr->scrn_display_lst);
-        prev = ptr;
-        ptr = ptr->list.next;
-        free(prev);
-    }
-}
-
-void
+static void
 xf86freeAdaptorLinkList(XF86ConfAdaptorLinkPtr ptr)
 {
     XF86ConfAdaptorLinkPtr prev;
@@ -468,26 +474,20 @@ xf86freeAdaptorLinkList(XF86ConfAdaptorLinkPtr ptr)
 }
 
 void
-xf86freeDisplayList(XF86ConfDisplayPtr ptr)
-{
-    XF86ConfDisplayPtr prev;
-
-    while (ptr) {
-        xf86freeModeList(ptr->disp_mode_lst);
-        xf86optionListFree(ptr->disp_option_lst);
-        prev = ptr;
-        ptr = ptr->list.next;
-        free(prev);
-    }
-}
-
-void
-xf86freeModeList(XF86ModePtr ptr)
+xf86freeScreenList(XF86ConfScreenPtr ptr)
 {
-    XF86ModePtr prev;
-
+    XF86ConfScreenPtr prev;
+    int i;
     while (ptr) {
-        TestFree(ptr->mode_name);
+        TestFree(ptr->scrn_identifier);
+        TestFree(ptr->scrn_monitor_str);
+        TestFree(ptr->scrn_device_str);
+        for (i = 0; i < ptr->num_gpu_devices; i++)
+            TestFree(ptr->scrn_gpu_device_str[i]);
+        TestFree(ptr->scrn_comment);
+        xf86optionListFree(ptr->scrn_option_lst);
+        xf86freeAdaptorLinkList(ptr->scrn_adaptor_lst);
+        xf86freeDisplayList(ptr->scrn_display_lst);
         prev = ptr;
         ptr = ptr->list.next;
         free(prev);
diff --git a/hw/xfree86/parser/Vendor.c b/hw/xfree86/parser/Vendor.c
index 4f6e510..f137a4e 100644
--- a/hw/xfree86/parser/Vendor.c
+++ b/hw/xfree86/parser/Vendor.c
@@ -68,6 +68,22 @@ static xf86ConfigSymTabRec VendorSubTab[] = {
     {-1, ""},
 };
 
+static void
+xf86freeVendorSubList(XF86ConfVendSubPtr ptr)
+{
+    XF86ConfVendSubPtr prev;
+
+    while (ptr) {
+        TestFree(ptr->vs_identifier);
+        TestFree(ptr->vs_name);
+        TestFree(ptr->vs_comment);
+        xf86optionListFree(ptr->vs_option_lst);
+        prev = ptr;
+        ptr = ptr->list.next;
+        free(prev);
+    }
+}
+
 #define CLEANUP xf86freeVendorSubList
 
 static XF86ConfVendSubPtr
@@ -215,19 +231,3 @@ xf86freeVendorList(XF86ConfVendorPtr p)
     xf86optionListFree(p->vnd_option_lst);
     free(p);
 }
-
-void
-xf86freeVendorSubList(XF86ConfVendSubPtr ptr)
-{
-    XF86ConfVendSubPtr prev;
-
-    while (ptr) {
-        TestFree(ptr->vs_identifier);
-        TestFree(ptr->vs_name);
-        TestFree(ptr->vs_comment);
-        xf86optionListFree(ptr->vs_option_lst);
-        prev = ptr;
-        ptr = ptr->list.next;
-        free(prev);
-    }
-}
diff --git a/hw/xfree86/parser/configProcs.h b/hw/xfree86/parser/configProcs.h
index 774e2a2..e6c231e 100644
--- a/hw/xfree86/parser/configProcs.h
+++ b/hw/xfree86/parser/configProcs.h
@@ -55,12 +55,10 @@ int xf86validateInput(XF86ConfigPtr p);
 /* InputClass.c */
 XF86ConfInputClassPtr xf86parseInputClassSection(void);
 void xf86printInputClassSection(FILE * f, XF86ConfInputClassPtr ptr);
-void xf86freeInputClassList(XF86ConfInputClassPtr ptr);
 
 /* OutputClass.c */
 XF86ConfOutputClassPtr xf86parseOutputClassSection(void);
 void xf86printOutputClassSection(FILE * f, XF86ConfOutputClassPtr ptr);
-void xf86freeOutputClassList(XF86ConfOutputClassPtr ptr);
 
 /* Layout.c */
 XF86ConfLayoutPtr xf86parseLayoutSection(void);
@@ -92,16 +90,12 @@ XF86ConfInputPtr xf86parsePointerSection(void);
 XF86ConfScreenPtr xf86parseScreenSection(void);
 void xf86printScreenSection(FILE * cf, XF86ConfScreenPtr ptr);
 extern _X_EXPORT void xf86freeScreenList(XF86ConfScreenPtr ptr);
-void xf86freeAdaptorLinkList(XF86ConfAdaptorLinkPtr ptr);
-void xf86freeDisplayList(XF86ConfDisplayPtr ptr);
-void xf86freeModeList(XF86ModePtr ptr);
 int xf86validateScreen(XF86ConfigPtr p);
 
 /* Vendor.c */
 XF86ConfVendorPtr xf86parseVendorSection(void);
 void xf86freeVendorList(XF86ConfVendorPtr p);
 void xf86printVendorSection(FILE * cf, XF86ConfVendorPtr ptr);
-void xf86freeVendorSubList(XF86ConfVendSubPtr ptr);
 
 /* Video.c */
 XF86ConfVideoAdaptorPtr xf86parseVideoAdaptorSection(void);
commit c732bb2799ad7ff6b0cdd9c65487466e6a9b76e7
Author: Adam Jackson <ajax at redhat.com>
Date:   Wed Oct 22 10:31:29 2014 -0400

    present: static cleanup
    
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/present/present_event.c b/present/present_event.c
index d3a59ea..c586c9a 100644
--- a/present/present_event.c
+++ b/present/present_event.c
@@ -26,7 +26,7 @@
 
 #include "present_priv.h"
 
-RESTYPE present_event_type;
+static RESTYPE present_event_type;
 
 static int
 present_free_event(void *data, XID id)
diff --git a/present/present_priv.h b/present/present_priv.h
index f5c1652..996292e 100644
--- a/present/present_priv.h
+++ b/present/present_priv.h
@@ -147,8 +147,6 @@ present_window_priv(WindowPtr window)
 present_window_priv_ptr
 present_get_window_priv(WindowPtr window, Bool create);
 
-extern RESTYPE present_event_type;
-
 /*
  * present.c
  */
diff --git a/present/present_request.c b/present/present_request.c
index 7c53e72..35320b6 100644
--- a/present/present_request.c
+++ b/present/present_request.c
@@ -234,7 +234,7 @@ proc_present_query_capabilities (ClientPtr client)
     return Success;
 }
 
-int (*proc_present_vector[PresentNumberRequests]) (ClientPtr) = {
+static int (*proc_present_vector[PresentNumberRequests]) (ClientPtr) = {
     proc_present_query_version,            /* 0 */
     proc_present_pixmap,                   /* 1 */
     proc_present_notify_msc,               /* 2 */
@@ -319,7 +319,7 @@ sproc_present_query_capabilities (ClientPtr client)
     return (*proc_present_vector[stuff->presentReqType]) (client);
 }
 
-int (*sproc_present_vector[PresentNumberRequests]) (ClientPtr) = {
+static int (*sproc_present_vector[PresentNumberRequests]) (ClientPtr) = {
     sproc_present_query_version,           /* 0 */
     sproc_present_pixmap,                  /* 1 */
     sproc_present_notify_msc,              /* 2 */
commit 0db457b2b5b6e314e912efc62f158f8f0b8d48af
Author: Adam Jackson <ajax at redhat.com>
Date:   Wed Jul 8 15:56:55 2015 -0400

    dmx: Fix the build
    
    Broken since:
    
        commit 4fd81823fafcd103e8d890f4c0f7c2f90e822336
        Author: Dave Airlie <airlied at gmail.com>
        Date:   Tue Jun 30 14:54:42 2015 +1000
    
            prime: add rotation support for offloaded outputs (v2)
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/configure.ac b/configure.ac
index 328563e..98d0821 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2268,7 +2268,7 @@ if test "x$DMX" = xyes; then
 	fi
 	DMX_INCLUDES="$XEXT_INC $RENDER_INC $RECORD_INC"
 	XDMX_CFLAGS="$DMXMODULES_CFLAGS"
-	XDMX_LIBS="$FB_LIB $MI_LIB $XEXT_LIB $RENDER_LIB $RECORD_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB  $DRI3_LIB $PRESENT_LIB $MIEXT_SYNC_LIB $MIEXT_SHADOW_LIB $MIEXT_DAMAGE_LIB $COMPOSITE_LIB $DAMAGE_LIB $MAIN_LIB $DIX_LIB $CONFIG_LIB $OS_LIB $FIXES_LIB"
+	XDMX_LIBS="$FB_LIB $MI_LIB $XEXT_LIB $RANDR_LIB $RENDER_LIB $RECORD_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB  $DRI3_LIB $PRESENT_LIB $MIEXT_SYNC_LIB $MIEXT_SHADOW_LIB $MIEXT_DAMAGE_LIB $COMPOSITE_LIB $DAMAGE_LIB $MAIN_LIB $DIX_LIB $CONFIG_LIB $OS_LIB $FIXES_LIB"
 	XDMX_SYS_LIBS="$DMXMODULES_LIBS"
 	AC_SUBST([XDMX_CFLAGS])
 	AC_SUBST([XDMX_LIBS])
commit 90db5edf119187f8b1b9207c8c384d6cd7ef9edc
Author: Dave Airlie <airlied at gmail.com>
Date:   Tue Jun 30 14:54:42 2015 +1000

    prime: add rotation support for offloaded outputs (v2)
    
    One of the lacking features with output offloading was
    that screen rotation didn't work at all.
    
    This patch makes 0/90/180/270 rotation work with USB output
    and GPU outputs.
    
    When it allocates the shared pixmap it allocates it rotated,
    and any updates to the shared pixmap are done using a composite
    path that does the rotation. The slave GPU then doesn't need
    to know about the rotation and just displays the pixmap.
    
    v2:
    rewrite the sync dirty helper to use the dst pixmap, and
    avoid any strange hobbits and rotations.
    
    This breaks ABI in two places.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/dix/pixmap.c b/dix/pixmap.c
index 00e298f..05aebc4 100644
--- a/dix/pixmap.c
+++ b/dix/pixmap.c
@@ -40,7 +40,9 @@ from The Open Group.
 #include "gcstruct.h"
 #include "servermd.h"
 #include "site.h"
-
+#include "X11/extensions/render.h"
+#include "picturestr.h"
+#include "randrstr.h"
 /*
  *  Scratch pixmap management and device independent pixmap allocation
  *  function.
@@ -164,9 +166,10 @@ PixmapPtr PixmapShareToSlave(PixmapPtr pixmap, ScreenPtr slave)
 }
 
 Bool
-PixmapStartDirtyTracking2(PixmapPtr src,
-			  PixmapPtr slave_dst,
-			  int x, int y, int dst_x, int dst_y)
+PixmapStartDirtyTracking(PixmapPtr src,
+                         PixmapPtr slave_dst,
+                         int x, int y, int dst_x, int dst_y,
+                         Rotation rotation)
 {
     ScreenPtr screen = src->drawable.pScreen;
     PixmapDirtyUpdatePtr dirty_update;
@@ -181,11 +184,22 @@ PixmapStartDirtyTracking2(PixmapPtr src,
     dirty_update->y = y;
     dirty_update->dst_x = dst_x;
     dirty_update->dst_y = dst_y;
-
+    dirty_update->rotation = rotation;
     dirty_update->damage = DamageCreate(NULL, NULL,
                                         DamageReportNone,
                                         TRUE, src->drawable.pScreen,
                                         src->drawable.pScreen);
+
+    if (rotation != RR_Rotate_0) {
+        RRTransformCompute(x, y,
+                           slave_dst->drawable.width,
+                           slave_dst->drawable.height,
+                           rotation,
+                           NULL,
+                           &dirty_update->transform,
+                           &dirty_update->f_transform,
+                           &dirty_update->f_inverse);
+    }
     if (!dirty_update->damage) {
         free(dirty_update);
         return FALSE;
@@ -197,14 +211,6 @@ PixmapStartDirtyTracking2(PixmapPtr src,
 }
 
 Bool
-PixmapStartDirtyTracking(PixmapPtr src,
-			 PixmapPtr slave_dst,
-			 int x, int y)
-{
-   return PixmapStartDirtyTracking2(src, slave_dst, x, y, 0, 0);
-}
-
-Bool
 PixmapStopDirtyTracking(PixmapPtr src, PixmapPtr slave_dst)
 {
     ScreenPtr screen = src->drawable.pScreen;
@@ -220,42 +226,16 @@ PixmapStopDirtyTracking(PixmapPtr src, PixmapPtr slave_dst)
     return TRUE;
 }
 
-/*
- * this function can possibly be improved and optimised, by clipping
- * instead of iterating
- */
-Bool PixmapSyncDirtyHelper(PixmapDirtyUpdatePtr dirty, RegionPtr dirty_region)
+static void
+PixmapDirtyCopyArea(PixmapPtr dst,
+                    PixmapDirtyUpdatePtr dirty,
+                    RegionPtr dirty_region)
 {
     ScreenPtr pScreen = dirty->src->drawable.pScreen;
     int n;
     BoxPtr b;
-    RegionPtr region = DamageRegion(dirty->damage);
     GCPtr pGC;
-    PixmapPtr dst;
-    SourceValidateProcPtr SourceValidate;
-
-    /*
-     * SourceValidate is used by the software cursor code
-     * to pull the cursor off of the screen when reading
-     * bits from the frame buffer. Bypassing this function
-     * leaves the software cursor in place
-     */
-    SourceValidate = pScreen->SourceValidate;
-    pScreen->SourceValidate = NULL;
-
-    RegionTranslate(dirty_region, dirty->x, dirty->y);
-    RegionIntersect(dirty_region, dirty_region, region);
-
-    if (RegionNil(dirty_region)) {
-        RegionUninit(dirty_region);
-        return FALSE;
-    }
 
-    dst = dirty->slave_dst->master_pixmap;
-    if (!dst)
-        dst = dirty->slave_dst;
-
-    RegionTranslate(dirty_region, -dirty->x, -dirty->y);
     n = RegionNumRects(dirty_region);
     b = RegionRects(dirty_region);
 
@@ -271,11 +251,123 @@ Bool PixmapSyncDirtyHelper(PixmapDirtyUpdatePtr dirty, RegionPtr dirty_region)
         h = dst_box.y2 - dst_box.y1;
 
         pGC->ops->CopyArea(&dirty->src->drawable, &dst->drawable, pGC,
-                           dirty->x + dst_box.x1, dirty->y + dst_box.y1, w, h, dirty->dst_x + dst_box.x1, dirty->dst_y + dst_box.y1);
+                           dirty->x + dst_box.x1, dirty->y + dst_box.y1, w, h,
+                           dirty->dst_x + dst_box.x1,
+                           dirty->dst_y + dst_box.y1);
         b++;
     }
     FreeScratchGC(pGC);
+}
 
+static void
+PixmapDirtyCompositeRotate(PixmapPtr dst_pixmap,
+                           PixmapDirtyUpdatePtr dirty,
+                           RegionPtr dirty_region)
+{
+    ScreenPtr pScreen = dirty->src->drawable.pScreen;
+    PictFormatPtr format = PictureWindowFormat(pScreen->root);
+    PicturePtr src, dst;
+    XID include_inferiors = IncludeInferiors;
+    int n = RegionNumRects(dirty_region);
+    BoxPtr b = RegionRects(dirty_region);
+    int error;
+
+    src = CreatePicture(None,
+                        &dirty->src->drawable,
+                        format,
+                        CPSubwindowMode,
+                        &include_inferiors, serverClient, &error);
+    if (!src)
+        return;
+
+    dst = CreatePicture(None,
+                        &dst_pixmap->drawable,
+                        format, 0L, NULL, serverClient, &error);
+    if (!dst)
+        return;
+
+    error = SetPictureTransform(src, &dirty->transform);
+    if (error)
+        return;
+    while (n--) {
+        BoxRec dst_box;
+
+        dst_box = *b;
+        dst_box.x1 += dirty->x;
+        dst_box.x2 += dirty->x;
+        dst_box.y1 += dirty->y;
+        dst_box.y2 += dirty->y;
+        pixman_f_transform_bounds(&dirty->f_inverse, &dst_box);
+
+        CompositePicture(PictOpSrc,
+                         src, NULL, dst,
+                         dst_box.x1,
+                         dst_box.y1,
+                         0, 0,
+                         dst_box.x1,
+                         dst_box.y1,
+                         dst_box.x2 - dst_box.x1,
+                         dst_box.y2 - dst_box.y1);
+        b++;
+    }
+
+    FreePicture(src, None);
+    FreePicture(dst, None);
+}
+
+/*
+ * this function can possibly be improved and optimised, by clipping
+ * instead of iterating
+ * Drivers are free to implement their own version of this.
+ */
+Bool PixmapSyncDirtyHelper(PixmapDirtyUpdatePtr dirty)
+{
+    ScreenPtr pScreen = dirty->src->drawable.pScreen;
+    RegionPtr region = DamageRegion(dirty->damage);
+    PixmapPtr dst;
+    SourceValidateProcPtr SourceValidate;
+    RegionRec pixregion;
+    BoxRec box;
+
+    dst = dirty->slave_dst->master_pixmap;
+    if (!dst)
+        dst = dirty->slave_dst;
+
+    box.x1 = 0;
+    box.y1 = 0;
+    if (dirty->rotation == RR_Rotate_90 ||
+        dirty->rotation == RR_Rotate_270) {
+        box.x2 = dst->drawable.height;
+        box.y2 = dst->drawable.width;
+    } else {
+        box.x2 = dst->drawable.width;
+        box.y2 = dst->drawable.height;
+    }
+    RegionInit(&pixregion, &box, 1);
+
+    /*
+     * SourceValidate is used by the software cursor code
+     * to pull the cursor off of the screen when reading
+     * bits from the frame buffer. Bypassing this function
+     * leaves the software cursor in place
+     */
+    SourceValidate = pScreen->SourceValidate;
+    pScreen->SourceValidate = NULL;
+
+    RegionTranslate(&pixregion, dirty->x, dirty->y);
+    RegionIntersect(&pixregion, &pixregion, region);
+
+    if (RegionNil(&pixregion)) {
+        RegionUninit(&pixregion);
+        return FALSE;
+    }
+
+    RegionTranslate(&pixregion, -dirty->x, -dirty->y);
+
+    if (!pScreen->root || dirty->rotation == RR_Rotate_0)
+        PixmapDirtyCopyArea(dst, dirty, &pixregion);
+    else
+        PixmapDirtyCompositeRotate(dst, dirty, &pixregion);
     pScreen->SourceValidate = SourceValidate;
     return TRUE;
 }
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 7ee7590..324b8bd 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -541,7 +541,7 @@ redisplay_dirty(ScreenPtr screen, PixmapDirtyUpdatePtr dirty)
 
         PixmapRegionInit(&pixregion, dirty->slave_dst);
         DamageRegionAppend(&dirty->slave_dst->drawable, &pixregion);
-        PixmapSyncDirtyHelper(dirty, &pixregion);
+        PixmapSyncDirtyHelper(dirty);
 
         DamageRegionProcessPending(&dirty->slave_dst->drawable);
         RegionUninit(&pixregion);
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index dc7d9f6..ef5b087 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -581,7 +581,7 @@ drmmode_set_scanout_pixmap_gpu(xf86CrtcPtr crtc, PixmapPtr ppix)
         screen->height = screenpix->drawable.height = max_height;
     }
     drmmode_crtc->prime_pixmap_x = this_x;
-    PixmapStartDirtyTracking2(ppix, screenpix, 0, 0, this_x, 0);
+    PixmapStartDirtyTracking(ppix, screenpix, 0, 0, this_x, 0, RR_Rotate_0);
     return TRUE;
 }
 
diff --git a/hw/xfree86/modes/xf86Rotate.c b/hw/xfree86/modes/xf86Rotate.c
index bc1ea21..4aa8f8d 100644
--- a/hw/xfree86/modes/xf86Rotate.c
+++ b/hw/xfree86/modes/xf86Rotate.c
@@ -360,6 +360,8 @@ xf86CrtcRotate(xf86CrtcPtr crtc)
     RRTransformPtr transform = NULL;
     Bool damage = FALSE;
 
+    if (pScreen->isGPU)
+        return TRUE;
     if (crtc->transformPresent)
         transform = &crtc->transform;
 
diff --git a/include/pixmap.h b/include/pixmap.h
index 9656c3a..c6a7736 100644
--- a/include/pixmap.h
+++ b/include/pixmap.h
@@ -50,7 +50,7 @@ SOFTWARE.
 #include "misc.h"
 #include "screenint.h"
 #include "regionstr.h"
-
+#include <X11/extensions/randr.h>
 /* types for Drawable */
 #define DRAWABLE_WINDOW 0
 #define DRAWABLE_PIXMAP 1
@@ -115,16 +115,12 @@ extern _X_EXPORT void FreePixmap(PixmapPtr /*pPixmap */ );
 extern _X_EXPORT PixmapPtr
 PixmapShareToSlave(PixmapPtr pixmap, ScreenPtr slave);
 
+#define HAS_DIRTYTRACKING_ROTATION 1
 extern _X_EXPORT Bool
 PixmapStartDirtyTracking(PixmapPtr src,
                          PixmapPtr slave_dst,
-                         int x, int y);
-
-#define HAS_DIRTYTRACKING2 1
-extern _X_EXPORT Bool
-PixmapStartDirtyTracking2(PixmapPtr src,
-			  PixmapPtr slave_dst,
-			  int x, int y, int dst_x, int dst_y);
+                         int x, int y, int dst_x, int dst_y,
+                         Rotation rotation);
 
 extern _X_EXPORT Bool
 PixmapStopDirtyTracking(PixmapPtr src, PixmapPtr slave_dst);
@@ -132,6 +128,6 @@ PixmapStopDirtyTracking(PixmapPtr src, PixmapPtr slave_dst);
 /* helper function, drivers can do this themselves if they can do it more
    efficently */
 extern _X_EXPORT Bool
-PixmapSyncDirtyHelper(PixmapDirtyUpdatePtr dirty, RegionPtr dirty_region);
+PixmapSyncDirtyHelper(PixmapDirtyUpdatePtr dirty);
 
 #endif                          /* PIXMAP_H */
diff --git a/include/pixmapstr.h b/include/pixmapstr.h
index 380e483..4bd2465 100644
--- a/include/pixmapstr.h
+++ b/include/pixmapstr.h
@@ -51,6 +51,8 @@ SOFTWARE.
 #include "regionstr.h"
 #include "privates.h"
 #include "damage.h"
+#include <X11/extensions/randr.h>
+#include "picturestr.h"
 
 typedef struct _Drawable {
     unsigned char type;         /* DRAWABLE_<type> */
@@ -91,6 +93,9 @@ typedef struct _PixmapDirtyUpdate {
     DamagePtr damage;
     struct xorg_list ent;
     int dst_x, dst_y;
+    Rotation rotation;
+    PictTransform transform;
+    struct pixman_f_transform f_transform, f_inverse;
 } PixmapDirtyUpdateRec;
 
 static inline void
diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index faf0563..a627fe7 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -55,6 +55,7 @@ SOFTWARE.
 #include <X11/Xproto.h>
 #include "dix.h"
 #include "privates.h"
+#include <X11/extensions/randr.h>
 
 typedef struct _PixmapFormat {
     unsigned char depth;
@@ -340,7 +341,9 @@ typedef Bool (*SharePixmapBackingProcPtr)(PixmapPtr, ScreenPtr, void **);
 typedef Bool (*SetSharedPixmapBackingProcPtr)(PixmapPtr, void *);
 
 typedef Bool (*StartPixmapTrackingProcPtr)(PixmapPtr, PixmapPtr,
-                                           int x, int y);
+                                           int x, int y,
+                                           int dst_x, int dst_y,
+                                           Rotation rotation);
 
 typedef Bool (*StopPixmapTrackingProcPtr)(PixmapPtr, PixmapPtr);
 
diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index e95b049..050d975 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -387,7 +387,7 @@ RRCrtcDetachScanoutPixmap(RRCrtcPtr crtc)
 
 static Bool
 rrCreateSharedPixmap(RRCrtcPtr crtc, int width, int height,
-                     int x, int y)
+                     int x, int y, Rotation rotation)
 {
     PixmapPtr mpix, spix;
     ScreenPtr master = crtc->pScreen->current_master;
@@ -434,13 +434,33 @@ rrCreateSharedPixmap(RRCrtcPtr crtc, int width, int height,
 
     crtc->scanout_pixmap = spix;
 
-    master->StartPixmapTracking(mscreenpix, spix, x, y);
+    master->StartPixmapTracking(mscreenpix, spix, x, y, 0, 0, rotation);
     return TRUE;
 }
 
+static void crtc_to_box(BoxPtr box, RRCrtcPtr crtc)
+{
+    box->x1 = crtc->x;
+    box->y1 = crtc->y;
+    switch (crtc->rotation) {
+    case RR_Rotate_0:
+    case RR_Rotate_180:
+    default:
+        box->x2 = crtc->x + crtc->mode->mode.width;
+        box->y2 = crtc->y + crtc->mode->mode.height;
+        break;
+    case RR_Rotate_90:
+    case RR_Rotate_270:
+        box->x2 = crtc->x + crtc->mode->mode.height;
+        box->y2 = crtc->y + crtc->mode->mode.width;
+        break;
+    }
+}
+
 static Bool
 rrCheckPixmapBounding(ScreenPtr pScreen,
-                      RRCrtcPtr rr_crtc, int x, int y, int w, int h)
+                      RRCrtcPtr rr_crtc, Rotation rotation,
+                      int x, int y, int w, int h)
 {
     RegionRec root_pixmap_region, total_region, new_crtc_region;
     int c;
@@ -461,16 +481,19 @@ rrCheckPixmapBounding(ScreenPtr pScreen,
 
         if (crtc == rr_crtc) {
             newbox.x1 = x;
-            newbox.x2 = x + w;
             newbox.y1 = y;
-            newbox.y2 = y + h;
+            if (rotation == RR_Rotate_90 ||
+                rotation == RR_Rotate_270) {
+                newbox.x2 = x + h;
+                newbox.y2 = y + w;
+            } else {
+                newbox.x2 = x + w;
+                newbox.y2 = y + h;
+            }
         } else {
             if (!crtc->mode)
                 continue;
-            newbox.x1 = crtc->x;
-            newbox.x2 = crtc->x + crtc->mode->mode.width;
-            newbox.y1 = crtc->y;
-            newbox.y2 = crtc->y + crtc->mode->mode.height;
+            crtc_to_box(&newbox, crtc);
         }
         RegionInit(&new_crtc_region, &newbox, 1);
         RegionUnion(&total_region, &total_region, &new_crtc_region);
@@ -483,17 +506,20 @@ rrCheckPixmapBounding(ScreenPtr pScreen,
 
             if (slave_crtc == rr_crtc) {
                 newbox.x1 = x;
-                newbox.x2 = x + w;
                 newbox.y1 = y;
-                newbox.y2 = y + h;
+                if (rotation == RR_Rotate_90 ||
+                    rotation == RR_Rotate_270) {
+                    newbox.x2 = x + h;
+                    newbox.y2 = y + w;
+                } else {
+                    newbox.x2 = x + w;
+                    newbox.y2 = y + h;
+                }
             }
             else {
                 if (!slave_crtc->mode)
                     continue;
-                newbox.x1 = slave_crtc->x;
-                newbox.x2 = slave_crtc->x + slave_crtc->mode->mode.width;
-                newbox.y1 = slave_crtc->y;
-                newbox.y2 = slave_crtc->y + slave_crtc->mode->mode.height;
+                crtc_to_box(&newbox, slave_crtc);
             }
             RegionInit(&new_crtc_region, &newbox, 1);
             RegionUnion(&total_region, &total_region, &new_crtc_region);
@@ -561,12 +587,12 @@ RRCrtcSet(RRCrtcPtr crtc,
                 height = mode->mode.height;
             }
             ret = rrCheckPixmapBounding(master, crtc,
-                                        x, y, width, height);
+                                        rotation, x, y, width, height);
             if (!ret)
                 return FALSE;
 
             if (pScreen->current_master) {
-                ret = rrCreateSharedPixmap(crtc, width, height, x, y);
+                ret = rrCreateSharedPixmap(crtc, width, height, x, y, rotation);
             }
         }
 #if RANDR_12_INTERFACE
commit 991712f1e8deeb6289ee0abd9910e279d6396246
Merge: 0cd2280 3c85911
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Jul 8 10:43:31 2015 -0700

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

commit 0cd228073ad3b7eb72cef8b61128324895ee6cd4
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Mon Jun 29 15:08:51 2015 +0100

    hw/xwin: printf format fixes for Pixel type
    
    Pixel is CARD32, so inside the server has type unsigned int (x86_64) or unsigned
    long (x86)
    
    Cast to unsigned int and use a %u format
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Colin Harrison <colin.harrison at virgin.net>

diff --git a/hw/xwin/wincmap.c b/hw/xwin/wincmap.c
index 318bfac..000334c 100644
--- a/hw/xwin/wincmap.c
+++ b/hw/xwin/wincmap.c
@@ -360,8 +360,8 @@ winGetPaletteDIB(ScreenPtr pScreen, ColormapPtr pcmap)
         nBlue = rgbColors[i].rgbBlue << 8;
 
 #if CYGDEBUG
-        winDebug("winGetPaletteDIB - Allocating a color: %d; "
-                 "%d %d %d\n", pixel, nRed, nGreen, nBlue);
+        winDebug("winGetPaletteDIB - Allocating a color: %u; "
+                 "%d %d %d\n", (unsigned int)pixel, nRed, nGreen, nBlue);
 #endif
 
         /* Allocate a entry in the X colormap */
@@ -445,8 +445,8 @@ winGetPaletteDD(ScreenPtr pScreen, ColormapPtr pcmap)
         nGreen = ppeColors[i].peGreen << 8;
         nBlue = ppeColors[i].peBlue << 8;
 #if CYGDEBUG
-        winDebug("winGetPaletteDD - Allocating a color: %d; "
-                 "%d %d %d\n", pixel, nRed, nGreen, nBlue);
+        winDebug("winGetPaletteDD - Allocating a color: %u; "
+                 "%d %d %d\n", (unsigned int)pixel, nRed, nGreen, nBlue);
 #endif
         if (AllocColor(pcmap, &nRed, &nGreen, &nBlue, &pixel, 0) != Success) {
             ErrorF("winGetPaletteDD - AllocColor () failed, pixel %d\n", i);
commit e3cfeb949a9c9363beacdb00acdd9723ed54fac2
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Fri Feb 6 20:22:11 2015 +0000

    hw/xwin: printf format fixes for WPARAM and LPARAM types
    
    Some Win32 API types are different fundamental types in the 32-bit and 64-bit
    
    This problem is then further compounded by the fact that whilst both 32-bit
    Cygwin and 32-bit MinGW use the ILP32 data model, 64-bit MinGW uses the LLP64
    data model, but 64-bit Cygwin uses the LP64 data model.
    
    This makes it impossible to write printf format specifiers which are correct for
    all those targets, so we use some macros to provide the correct specifier for
    the target.
    
    LPARAM and WPARAM are integer types which can contain a pointer
    
    LPARAM is long in ILP32 and long long in LLP64
    WPARAM is unsigned int in ILP32 and unsigned long long in LLP64
    
    Generally, these are just used to passs integer parameters, so for simplicity,
    cast to int and use an int-compatible format
    
    In the specific case of WM_CHANGECBCHAIN, they are used to pass HWND, so cast to
    that type and print using an appropriate format.
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Colin Harrison <colin.harrison at virgin.net>

diff --git a/hw/xwin/winclipboard/wndproc.c b/hw/xwin/winclipboard/wndproc.c
index e1517f2..d17cf2e 100644
--- a/hw/xwin/winclipboard/wndproc.c
+++ b/hw/xwin/winclipboard/wndproc.c
@@ -194,9 +194,9 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 
     case WM_CHANGECBCHAIN:
     {
-        winDebug("winClipboardWindowProc - WM_CHANGECBCHAIN: wParam(%x) "
-                 "lParam(%x) s_hwndNextViewer(%p)\n",
-                 wParam, lParam, s_hwndNextViewer);
+        winDebug("winClipboardWindowProc - WM_CHANGECBCHAIN: wParam(%p) "
+                 "lParam(%p) s_hwndNextViewer(%p)\n",
+                 (HWND)wParam, (HWND)lParam, s_hwndNextViewer);
 
         if ((HWND) wParam == s_hwndNextViewer) {
             s_hwndNextViewer = (HWND) lParam;
@@ -441,7 +441,7 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
         int best_target = 0;
 
         winDebug("winClipboardWindowProc - WM_RENDERFORMAT %d - Hello.\n",
-                 wParam);
+                 (int)wParam);
 
         /* Flag whether to convert to Unicode or not */
         fConvertToUnicode = (CF_UNICODETEXT == wParam);
diff --git a/hw/xwin/winkeybd.c b/hw/xwin/winkeybd.c
index f034225..ab53af4 100644
--- a/hw/xwin/winkeybd.c
+++ b/hw/xwin/winkeybd.c
@@ -74,7 +74,7 @@ winTranslateKey(WPARAM wParam, LPARAM lParam)
     int iParamScanCode = LOBYTE(iParam);
     int iScanCode;
 
-    winDebug("winTranslateKey: wParam %08x lParam %08x\n", wParam, lParam);
+    winDebug("winTranslateKey: wParam %08x lParam %08x\n", (int)wParam, (int)lParam);
 
 /* WM_ key messages faked by Vista speech recognition (WSR) don't have a
  * scan code.
diff --git a/hw/xwin/winmsg.c b/hw/xwin/winmsg.c
index 79399a4..575bc47 100644
--- a/hw/xwin/winmsg.c
+++ b/hw/xwin/winmsg.c
@@ -158,8 +158,8 @@ winDebugWin32Message(const char *function, HWND hwnd, UINT message,
             getenv("WIN_DEBUG_WM_USER")) {
             winDebug("%s - Message WM_USER + %d\n", function,
                      message - WM_USER);
-            winDebug("\thwnd 0x%p wParam 0x%x lParam 0x%x\n", hwnd, wParam,
-                     lParam);
+            winDebug("\thwnd 0x%p wParam 0x%x lParam 0x%x\n", hwnd, (int)wParam,
+                     (int)lParam);
         }
     }
     else if (message < MESSAGE_NAMES_LEN && MESSAGE_NAMES[message]) {
@@ -170,8 +170,8 @@ winDebugWin32Message(const char *function, HWND hwnd, UINT message,
         buffer[63] = 0;
         if (force || getenv("WIN_DEBUG_MESSAGES") || getenv(buffer)) {
             winDebug("%s - Message %s\n", function, MESSAGE_NAMES[message]);
-            winDebug("\thwnd 0x%p wParam 0x%x lParam 0x%x\n", hwnd, wParam,
-                     lParam);
+            winDebug("\thwnd 0x%p wParam 0x%x lParam 0x%x\n", hwnd, (int)wParam,
+                     (int)lParam);
         }
     }
 }
diff --git a/hw/xwin/winwndproc.c b/hw/xwin/winwndproc.c
index 3228fa4..123b84f 100644
--- a/hw/xwin/winwndproc.c
+++ b/hw/xwin/winwndproc.c
@@ -168,7 +168,7 @@ winWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 
         ErrorF("winWindowProc - WM_DISPLAYCHANGE - new width: %d "
                "new height: %d new bpp: %d\n",
-               LOWORD(lParam), HIWORD(lParam), wParam);
+               LOWORD(lParam), HIWORD(lParam), (int)wParam);
 
         /* 0 bpp has no defined meaning, ignore this message */
         if (wParam == 0)
commit 4f8661fac985306c56330cae69ffc19e5dd0af61
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Fri Feb 6 19:19:41 2015 +0000

    hw/xwin: printf format fixes for LONG type
    
    Some Win32 API types are different fundamental types in the 32-bit and 64-bit
    versions.
    
    This problem is then further compounded by the fact that whilst both 32-bit
    Cygwin and 32-bit MinGW use the ILP32 data model, 64-bit MinGW uses the LLP64
    data model, but 64-bit Cygwin uses the LP64 data model.
    
    This makes it impossible to write printf format specifiers which are correct for
    all those targets
    
    In the Win32 API, DWORD is an signed, 32-bit type.  It is defined in terms of a
    long, except in the LP64 data model, where it is an int.
    
    It should always be safe to cast it to int and use %d.
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Colin Harrison <colin.harrison at virgin.net>

diff --git a/hw/xwin/wincreatewnd.c b/hw/xwin/wincreatewnd.c
index 6c5b21d..b2f797c 100644
--- a/hw/xwin/wincreatewnd.c
+++ b/hw/xwin/wincreatewnd.c
@@ -357,10 +357,11 @@ winCreateBoundingWindowWindowed(ScreenPtr pScreen)
     }
 
     winDebug("winCreateBoundingWindowWindowed - WindowClient "
-             "w %ld h %ld r %ld l %ld b %ld t %ld\n",
-             rcClient.right - rcClient.left,
-             rcClient.bottom - rcClient.top,
-             rcClient.right, rcClient.left, rcClient.bottom, rcClient.top);
+             "w %d  h %d r %d l %d b %d t %d\n",
+             (int)(rcClient.right - rcClient.left),
+             (int)(rcClient.bottom - rcClient.top),
+             (int)rcClient.right, (int)rcClient.left,
+             (int)rcClient.bottom, (int)rcClient.top);
 
     /* We adjust the visual size if the user did not specify it */
     if (!
diff --git a/hw/xwin/winmultiwindowwindow.c b/hw/xwin/winmultiwindowwindow.c
index 91bd956..f4de912 100644
--- a/hw/xwin/winmultiwindowwindow.c
+++ b/hw/xwin/winmultiwindowwindow.c
@@ -220,7 +220,7 @@ winPositionWindowMultiWindow(WindowPtr pWin, int x, int y)
 #if CYGMULTIWINDOW_DEBUG
     lpRc = &rcNew;
     ErrorF("winPositionWindowMultiWindow - drawable (%d, %d)-(%d, %d)\n",
-           lpRc->left, lpRc->top, lpRc->right, lpRc->bottom);
+           (int)lpRc->left, (int)lpRc->top, (int)lpRc->right, (int)lpRc->bottom);
 #endif
 
     /*
@@ -238,15 +238,15 @@ winPositionWindowMultiWindow(WindowPtr pWin, int x, int y)
 
     lpRc = &rcNew;
     ErrorF("winPositionWindowMultiWindow - rcNew (%d, %d)-(%d, %d)\n",
-           lpRc->left, lpRc->top, lpRc->right, lpRc->bottom);
+           (int)lpRc->left, (int)lpRc->top, (int)lpRc->right, (int)lpRc->bottom);
 
     lpRc = &rcOld;
     ErrorF("winPositionWindowMultiWindow - rcOld (%d, %d)-(%d, %d)\n",
-           lpRc->left, lpRc->top, lpRc->right, lpRc->bottom);
+           (int)lpRc->left, (int)lpRc->top, (int)lpRc->right, (int)lpRc->bottom);
 
     lpRc = &rcClient;
     ErrorF("rcClient (%d, %d)-(%d, %d)\n",
-           lpRc->left, lpRc->top, lpRc->right, lpRc->bottom);
+           (int)lpRc->left, (int)lpRc->top, (int)lpRc->right, (int)lpRc->bottom);
 #endif
 
     /* Check if the old rectangle and new rectangle are the same */
@@ -256,8 +256,8 @@ winPositionWindowMultiWindow(WindowPtr pWin, int x, int y)
 #endif
 
 #if CYGWINDOWING_DEBUG
-        ErrorF("\tMoveWindow to (%ld, %ld) - %ldx%ld\n", rcNew.left, rcNew.top,
-               rcNew.right - rcNew.left, rcNew.bottom - rcNew.top);
+        ErrorF("\tMoveWindow to (%d, %d) - %dx%d\n", (int)rcNew.left, (int)rcNew.top,
+               (int)(rcNew.right - rcNew.left), (int)(rcNew.bottom - rcNew.top));
 #endif
         /* Change the position and dimensions of the Windows window */
         MoveWindow(hWnd,
@@ -948,8 +948,8 @@ winAdjustXWindow(WindowPtr pWin, HWND hwnd)
     SetRect(&rcDraw, x, y, x + pDraw->width, y + pDraw->height);
 #ifdef CYGMULTIWINDOW_DEBUG
     winDebug("\tDrawable extend {%d, %d, %d, %d}, {%d, %d}\n",
-             rcDraw.left, rcDraw.top, rcDraw.right, rcDraw.bottom,
-             rcDraw.right - rcDraw.left, rcDraw.bottom - rcDraw.top);
+             (int)rcDraw.left, (int)rcDraw.top, (int)rcDraw.right, (int)rcDraw.bottom,
+             (int)(rcDraw.right - rcDraw.left), (int)(rcDraw.bottom - rcDraw.top));
 #endif
     dwExStyle = GetWindowLongPtr(hwnd, GWL_EXSTYLE);
     dwStyle = GetWindowLongPtr(hwnd, GWL_STYLE);
@@ -962,11 +962,11 @@ winAdjustXWindow(WindowPtr pWin, HWND hwnd)
     GetWindowRect(hwnd, &rcWin);
 #ifdef CYGMULTIWINDOW_DEBUG
     winDebug("\tWindow extend {%d, %d, %d, %d}, {%d, %d}\n",
-             rcWin.left, rcWin.top, rcWin.right, rcWin.bottom,
-             rcWin.right - rcWin.left, rcWin.bottom - rcWin.top);
+             (int)rcWin.left, (int)rcWin.top, (int)rcWin.right, (int)rcWin.bottom,
+             (int)(rcWin.right - rcWin.left), (int)(rcWin.bottom - rcWin.top));
     winDebug("\tDraw extend {%d, %d, %d, %d}, {%d, %d}\n",
-             rcDraw.left, rcDraw.top, rcDraw.right, rcDraw.bottom,
-             rcDraw.right - rcDraw.left, rcDraw.bottom - rcDraw.top);
+             (int)rcDraw.left, (int)rcDraw.top, (int)rcDraw.right, (int)rcDraw.bottom,
+             (int)(rcDraw.right - rcDraw.left), (int)(rcDraw.bottom - rcDraw.top));
 #endif
 
     if (EqualRect(&rcDraw, &rcWin)) {
diff --git a/hw/xwin/winmultiwindowwndproc.c b/hw/xwin/winmultiwindowwndproc.c
index eb7b55e..656f6c2 100644
--- a/hw/xwin/winmultiwindowwndproc.c
+++ b/hw/xwin/winmultiwindowwndproc.c
@@ -770,20 +770,20 @@ winTopLevelWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
             ErrorF("\nCYGWINDOWING Dump:\n"
                    "\tdrawable: (%hd, %hd) - %hdx%hd\n", pDraw->x,
                    pDraw->y, pDraw->width, pDraw->height);
-            ErrorF("\twindPlace: (%ld, %ld) - %ldx%ld\n", pRect->left,
-                   pRect->top, pRect->right - pRect->left,
-                   pRect->bottom - pRect->top);
+            ErrorF("\twindPlace: (%d, %d) - %dx%d\n", (int)pRect->left,
+                   (int)pRect->top, (int)(pRect->right - pRect->left),
+                   (int)(pRect->bottom - pRect->top));
             if (GetClientRect(hwnd, &rc)) {
                 pRect = &rc;
-                ErrorF("\tClientRect: (%ld, %ld) - %ldx%ld\n", pRect->left,
-                       pRect->top, pRect->right - pRect->left,
-                       pRect->bottom - pRect->top);
+                ErrorF("\tClientRect: (%d, %d) - %dx%d\n", (int)pRect->left,
+                       (int)pRect->top, (int)(pRect->right - pRect->left),
+                       (int)(pRect->bottom - pRect->top));
             }
             if (GetWindowRect(hwnd, &rc)) {
                 pRect = &rc;
-                ErrorF("\tWindowRect: (%ld, %ld) - %ldx%ld\n", pRect->left,
-                       pRect->top, pRect->right - pRect->left,
-                       pRect->bottom - pRect->top);
+                ErrorF("\tWindowRect: (%d, %d) - %dx%d\n", (int)pRect->left,
+                       (int)pRect->top, (int)(pRect->right - pRect->left),
+                       (int)(pRect->bottom - pRect->top));
             }
             ErrorF("\n");
         }
@@ -1081,9 +1081,9 @@ winTopLevelWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 
         winDebug
             ("winTopLevelWindowProc - WM_STYLECHANGING client area {%d, %d, %d, %d}, {%d x %d}\n",
-             wi.rcClient.left, wi.rcClient.top, wi.rcClient.right,
-             wi.rcClient.bottom, wi.rcClient.right - wi.rcClient.left,
-             wi.rcClient.bottom - wi.rcClient.top);
+             (int)wi.rcClient.left, (int)wi.rcClient.top, (int)wi.rcClient.right,
+             (int)wi.rcClient.bottom, (int)(wi.rcClient.right - wi.rcClient.left),
+             (int)(wi.rcClient.bottom - wi.rcClient.top));
 
         newWinRect = wi.rcClient;
         if (!AdjustWindowRectEx(&newWinRect, dwStyle, FALSE, dwExStyle))
@@ -1092,9 +1092,9 @@ winTopLevelWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 
         winDebug
             ("winTopLevelWindowProc - WM_STYLECHANGING window area should be {%d, %d, %d, %d}, {%d x %d}\n",
-             newWinRect.left, newWinRect.top, newWinRect.right,
-             newWinRect.bottom, newWinRect.right - newWinRect.left,
-             newWinRect.bottom - newWinRect.top);
+             (int)newWinRect.left, (int)newWinRect.top, (int)newWinRect.right,
+             (int)newWinRect.bottom, (int)(newWinRect.right - newWinRect.left),
+             (int)(newWinRect.bottom - newWinRect.top));
 
         /*
            Style change hasn't happened yet, so we can't adjust the window size yet, as the winAdjustXWindow()
diff --git a/hw/xwin/winrandr.c b/hw/xwin/winrandr.c
index 1b34085..7392507 100644
--- a/hw/xwin/winrandr.c
+++ b/hw/xwin/winrandr.c
@@ -178,8 +178,9 @@ winRandRScreenSetSize(ScreenPtr pScreen,
          */
         AdjustWindowRectEx(&rcClient, dwStyle, FALSE, dwExStyle);
 
-        ErrorF("winRandRScreenSetSize new window area w: %ld h: %ld\n",
-               rcClient.right - rcClient.left, rcClient.bottom - rcClient.top);
+        ErrorF("winRandRScreenSetSize new window area w: %d h: %d\n",
+               (int)(rcClient.right - rcClient.left),
+               (int)(rcClient.bottom - rcClient.top));
 
         SetWindowPos(pScreenPriv->hwndScreen, NULL,
                      0, 0, rcClient.right - rcClient.left,
diff --git a/hw/xwin/winshadgdi.c b/hw/xwin/winshadgdi.c
index 7c31175..bf65517 100644
--- a/hw/xwin/winshadgdi.c
+++ b/hw/xwin/winshadgdi.c
@@ -199,7 +199,7 @@ winQueryRGBBitsAndMasks(ScreenPtr pScreen)
         winDebug("%s - Masks: %08x %08x %08x\n", __FUNCTION__,
                  (unsigned int)pdw[0], (unsigned int)pdw[1], (unsigned int)pdw[2]);
         winDebug("%s - Bitmap: %dx%d %d bpp %d planes\n", __FUNCTION__,
-                 pbmih->biWidth, pbmih->biHeight, pbmih->biBitCount,
+                 (int)pbmih->biWidth, (int)pbmih->biHeight, pbmih->biBitCount,
                  pbmih->biPlanes);
         winDebug("%s - Compression: %u %s\n", __FUNCTION__,
                  (unsigned int)pbmih->biCompression,
commit aa83c61f510121da20b56e8f7de700193f7d16b5
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Fri Feb 6 19:46:45 2015 +0000

    hw/xwin: printf format fixes for DWORD type
    
    Some Win32 API types are different fundamental types in the 32-bit and 64-bit
    versions.
    
    This problem is then further compounded by the fact that whilst both 32-bit
    Cygwin and 32-bit MinGW use the ILP32 data model, 64-bit MinGW uses the LLP64
    data model, but 64-bit Cygwin uses the LP64 data model.
    
    This makes it impossible to write printf format specifiers which are correct for
    all those targets
    
    In the Win32 API, DWORD is an unsigned, 32-bit type.  It is defined in terms of
    an unsigned long, except in the LP64 data model, where it is an unsigned int.
    
    It should always be safe to cast it to unsigned int and use %u or %x.
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Colin Harrison <colin.harrison at virgin.net>

diff --git a/hw/xwin/glx/indirect.c b/hw/xwin/glx/indirect.c
index 93cdb29..e4be642 100644
--- a/hw/xwin/glx/indirect.c
+++ b/hw/xwin/glx/indirect.c
@@ -253,7 +253,7 @@ pfdOut(const PIXELFORMATDESCRIPTOR * pfd)
     ErrorF("PIXELFORMATDESCRIPTOR:\n");
     ErrorF("nSize = %u\n", pfd->nSize);
     ErrorF("nVersion = %u\n", pfd->nVersion);
-    ErrorF("dwFlags = %lu = {", pfd->dwFlags);
+    ErrorF("dwFlags = %u = {", (unsigned int)pfd->dwFlags);
     DUMP_PFD_FLAG(PFD_DOUBLEBUFFER);
     DUMP_PFD_FLAG(PFD_STEREO);
     DUMP_PFD_FLAG(PFD_DRAW_TO_WINDOW);
@@ -297,9 +297,9 @@ pfdOut(const PIXELFORMATDESCRIPTOR * pfd)
     ErrorF("cAuxBuffers = %hhu\n", pfd->cAuxBuffers);
     ErrorF("iLayerType = %hhu\n", pfd->iLayerType);
     ErrorF("bReserved = %hhu\n", pfd->bReserved);
-    ErrorF("dwLayerMask = %lu\n", pfd->dwLayerMask);
-    ErrorF("dwVisibleMask = %lu\n", pfd->dwVisibleMask);
-    ErrorF("dwDamageMask = %lu\n", pfd->dwDamageMask);
+    ErrorF("dwLayerMask = %u\n", (unsigned int)pfd->dwLayerMask);
+    ErrorF("dwVisibleMask = %u\n", (unsigned int)pfd->dwVisibleMask);
+    ErrorF("dwDamageMask = %u\n", (unsigned int)pfd->dwDamageMask);
     ErrorF("\n");
 }
 
@@ -1862,8 +1862,8 @@ glxWinCreateConfigs(HDC hdc, glxWinScreen * screen)
         if (!(pfd.dwFlags & (PFD_DRAW_TO_WINDOW | PFD_DRAW_TO_BITMAP)) ||
             !(pfd.dwFlags & PFD_SUPPORT_OPENGL)) {
             GLWIN_DEBUG_MSG
-                ("pixelFormat %d has unsuitable flags 0x%08lx, skipping", i + 1,
-                 pfd.dwFlags);
+                ("pixelFormat %d has unsuitable flags 0x%08x, skipping", i + 1,
+                 (unsigned int)pfd.dwFlags);
             continue;
         }
 
diff --git a/hw/xwin/winclipboard/xevents.c b/hw/xwin/winclipboard/xevents.c
index bf44ac9..aee6c86 100644
--- a/hw/xwin/winclipboard/xevents.c
+++ b/hw/xwin/winclipboard/xevents.c
@@ -309,7 +309,7 @@ winClipboardFlushXEvents(HWND hwnd,
             /* Access the clipboard */
             if (!OpenClipboard(hwnd)) {
                 ErrorF("winClipboardFlushXEvents - SelectionRequest - "
-                       "OpenClipboard () failed: %08lx\n", GetLastError());
+                       "OpenClipboard () failed: %08x\n", (unsigned int)GetLastError());
 
                 /* Abort */
                 fAbort = TRUE;
@@ -369,7 +369,7 @@ winClipboardFlushXEvents(HWND hwnd,
             }
             if (!hGlobal) {
                 ErrorF("winClipboardFlushXEvents - SelectionRequest - "
-                       "GetClipboardData () failed: %08lx\n", GetLastError());
+                       "GetClipboardData () failed: %08x\n", (unsigned int)GetLastError());
 
                 /* Abort */
                 fAbort = TRUE;
@@ -706,7 +706,7 @@ winClipboardFlushXEvents(HWND hwnd,
             /* Check that global memory was allocated */
             if (!hGlobal) {
                 ErrorF("winClipboardFlushXEvents - SelectionNotify "
-                       "GlobalAlloc failed, aborting: %ld\n", GetLastError());
+                       "GlobalAlloc failed, aborting: %08x\n", (unsigned int)GetLastError());
 
                 /* Abort */
                 fAbort = TRUE;
diff --git a/hw/xwin/windialogs.c b/hw/xwin/windialogs.c
index 6fe3fc4..c83b49b 100644
--- a/hw/xwin/windialogs.c
+++ b/hw/xwin/windialogs.c
@@ -443,9 +443,9 @@ winChangeDepthDlgProc(HWND hwndDialog, UINT message,
 #endif
 
 #if CYGDEBUG
-        winDebug("winChangeDepthDlgProc - WM_INITDIALOG - orig bpp: %d, "
+        winDebug("winChangeDepthDlgProc - WM_INITDIALOG - orig bpp: %u, "
                  "current bpp: %d\n",
-                 s_pScreenInfo->dwBPP,
+                 (unsigned int)s_pScreenInfo->dwBPP,
                  GetDeviceCaps(s_pScreenPriv->hdcScreen, BITSPIXEL));
 #endif
 
@@ -455,9 +455,9 @@ winChangeDepthDlgProc(HWND hwndDialog, UINT message,
 
     case WM_DISPLAYCHANGE:
 #if CYGDEBUG
-        winDebug("winChangeDepthDlgProc - WM_DISPLAYCHANGE - orig bpp: %d, "
+        winDebug("winChangeDepthDlgProc - WM_DISPLAYCHANGE - orig bpp: %u, "
                  "new bpp: %d\n",
-                 s_pScreenInfo->dwBPP,
+                 (unsigned int)s_pScreenInfo->dwBPP,
                  GetDeviceCaps(s_pScreenPriv->hdcScreen, BITSPIXEL));
 #endif
 
diff --git a/hw/xwin/winkeybd.c b/hw/xwin/winkeybd.c
index e7202a6..f034225 100644
--- a/hw/xwin/winkeybd.c
+++ b/hw/xwin/winkeybd.c
@@ -504,7 +504,7 @@ winSendKeyEvent(DWORD dwKey, Bool fDown)
     QueueKeyboardEvents(g_pwinKeyboard, fDown ? KeyPress : KeyRelease,
                         dwKey + MIN_KEYCODE);
 
-    winDebug("winSendKeyEvent: dwKey: %d, fDown: %d\n", dwKey, fDown);
+    winDebug("winSendKeyEvent: dwKey: %u, fDown: %u\n", (unsigned int)dwKey, fDown);
 }
 
 BOOL
diff --git a/hw/xwin/winkeyhook.c b/hw/xwin/winkeyhook.c
index fe77b21..66d68f6 100644
--- a/hw/xwin/winkeyhook.c
+++ b/hw/xwin/winkeyhook.c
@@ -84,7 +84,7 @@ winKeyboardMessageHookLL(int iCode, WPARAM wParam, LPARAM lParam)
     /* Pass keystrokes on to our main message loop */
     if (iCode == HC_ACTION) {
         winDebug("winKeyboardMessageHook: vkCode: %08x scanCode: %08x\n",
-                 p->vkCode, p->scanCode);
+                 (unsigned int)p->vkCode, (unsigned int)p->scanCode);
 
         switch (wParam) {
         case WM_KEYDOWN:
diff --git a/hw/xwin/winmultiwindowwindow.c b/hw/xwin/winmultiwindowwindow.c
index 4a208dd..91bd956 100644
--- a/hw/xwin/winmultiwindowwindow.c
+++ b/hw/xwin/winmultiwindowwindow.c
@@ -954,7 +954,7 @@ winAdjustXWindow(WindowPtr pWin, HWND hwnd)
     dwExStyle = GetWindowLongPtr(hwnd, GWL_EXSTYLE);
     dwStyle = GetWindowLongPtr(hwnd, GWL_STYLE);
 #ifdef CYGMULTIWINDOW_DEBUG
-    winDebug("\tWindowStyle: %08x %08x\n", dwStyle, dwExStyle);
+    winDebug("\tWindowStyle: %08x %08x\n", (unsigned int)dwStyle, (unsigned int)dwExStyle);
 #endif
     AdjustWindowRectEx(&rcDraw, dwStyle, FALSE, dwExStyle);
 
diff --git a/hw/xwin/winmultiwindowwndproc.c b/hw/xwin/winmultiwindowwndproc.c
index ab892f2..eb7b55e 100644
--- a/hw/xwin/winmultiwindowwndproc.c
+++ b/hw/xwin/winmultiwindowwndproc.c
@@ -1064,7 +1064,7 @@ winTopLevelWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
         dwStyle = GetWindowLongPtr(hwnd, GWL_STYLE);
 
         winDebug("winTopLevelWindowProc - WM_STYLECHANGING from %08x %08x\n",
-                 dwStyle, dwExStyle);
+                 (unsigned int)dwStyle, (unsigned int)dwExStyle);
 
         if (wParam == GWL_EXSTYLE)
             dwExStyle = newStyle;
@@ -1073,7 +1073,7 @@ winTopLevelWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
             dwStyle = newStyle;
 
         winDebug("winTopLevelWindowProc - WM_STYLECHANGING to %08x %08x\n",
-                 dwStyle, dwExStyle);
+                 (unsigned int)dwStyle, (unsigned int)dwExStyle);
 
         /* Get client rect in screen coordinates */
         wi.cbSize = sizeof(WINDOWINFO);
diff --git a/hw/xwin/winscrinit.c b/hw/xwin/winscrinit.c
index e68ee12..735ce93 100644
--- a/hw/xwin/winscrinit.c
+++ b/hw/xwin/winscrinit.c
@@ -89,8 +89,8 @@ winScreenInit(ScreenPtr pScreen, int argc, char **argv)
     DWORD dwInitialBPP;
 
 #if CYGDEBUG || YES
-    winDebug("winScreenInit - dwWidth: %ld dwHeight: %ld\n",
-             pScreenInfo->dwWidth, pScreenInfo->dwHeight);
+    winDebug("winScreenInit - dwWidth: %u dwHeight: %u\n",
+             (unsigned int)pScreenInfo->dwWidth, (unsigned int)pScreenInfo->dwHeight);
 #endif
 
     /* Allocate privates for this screen */
diff --git a/hw/xwin/winshadddnl.c b/hw/xwin/winshadddnl.c
index 48599b2..d4f940e 100644
--- a/hw/xwin/winshadddnl.c
+++ b/hw/xwin/winshadddnl.c
@@ -200,8 +200,10 @@ winAllocateFBShadowDDNL(ScreenPtr pScreen)
     DDPIXELFORMAT ddpfPrimary;
 
 #if CYGDEBUG
-    winDebug("winAllocateFBShadowDDNL - w %d h %d d %d\n",
-             pScreenInfo->dwWidth, pScreenInfo->dwHeight, pScreenInfo->dwDepth);
+    winDebug("winAllocateFBShadowDDNL - w %u h %u d %u\n",
+             (unsigned int)pScreenInfo->dwWidth,
+             (unsigned int)pScreenInfo->dwHeight,
+             (unsigned int)pScreenInfo->dwDepth);
 #endif
 
     /* Set the padded screen width */
@@ -400,10 +402,11 @@ winAllocateFBShadowDDNL(ScreenPtr pScreen)
 
 #if CYGDEBUG
     winDebug("winAllocateFBShadowDDNL - Primary masks: %08x %08x %08x "
-             "dwRGBBitCount: %d\n",
-             ddpfPrimary.u2.dwRBitMask,
-             ddpfPrimary.u3.dwGBitMask,
-             ddpfPrimary.u4.dwBBitMask, ddpfPrimary.u1.dwRGBBitCount);
+             "dwRGBBitCount: %u\n",
+             (unsigned int)ddpfPrimary.u2.dwRBitMask,
+             (unsigned int)ddpfPrimary.u3.dwGBitMask,
+             (unsigned int)ddpfPrimary.u4.dwBBitMask,
+             (unsigned int)ddpfPrimary.u1.dwRGBBitCount);
 #endif
 
     /* Describe the shadow surface to be created */
diff --git a/hw/xwin/winshadgdi.c b/hw/xwin/winshadgdi.c
index 3d222ad..7c31175 100644
--- a/hw/xwin/winshadgdi.c
+++ b/hw/xwin/winshadgdi.c
@@ -121,7 +121,7 @@ winQueryScreenDIBFormat(ScreenPtr pScreen, BITMAPINFOHEADER * pbmih)
     pdw = (DWORD *) ((CARD8 *) pbmih + sizeof(BITMAPINFOHEADER));
 
     winDebug("winQueryScreenDIBFormat - First call masks: %08x %08x %08x\n",
-             pdw[0], pdw[1], pdw[2]);
+             (unsigned int)pdw[0], (unsigned int)pdw[1], (unsigned int)pdw[2]);
 #endif
 
     /* Get optimal color table, or the optimal bitfields */
@@ -197,12 +197,12 @@ winQueryRGBBitsAndMasks(ScreenPtr pScreen)
 
 #if CYGDEBUG
         winDebug("%s - Masks: %08x %08x %08x\n", __FUNCTION__,
-                 pdw[0], pdw[1], pdw[2]);
+                 (unsigned int)pdw[0], (unsigned int)pdw[1], (unsigned int)pdw[2]);
         winDebug("%s - Bitmap: %dx%d %d bpp %d planes\n", __FUNCTION__,
                  pbmih->biWidth, pbmih->biHeight, pbmih->biBitCount,
                  pbmih->biPlanes);
-        winDebug("%s - Compression: %d %s\n", __FUNCTION__,
-                 pbmih->biCompression,
+        winDebug("%s - Compression: %u %s\n", __FUNCTION__,
+                 (unsigned int)pbmih->biCompression,
                  (pbmih->biCompression ==
                   BI_RGB ? "(BI_RGB)" : (pbmih->biCompression ==
                                          BI_RLE8 ? "(BI_RLE8)" : (pbmih->
commit 487f2595c9dd9a5c3c600168a108963e87602561
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Fri Feb 6 20:48:26 2015 +0000

    hw/xwin: printf format fixes in xevents.c
    
    Window and Atom types derive from XID, which is always unsigned long in client
    code, so use %ld format specifier
    
    XTextProperty.nitems is of type unsigned long, so use %lu format specifier
    
    ulReturnBytesLeft is of type unsigned long, so use %lu format specifier
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Colin Harrison <colin.harrison at virgin.net>

diff --git a/hw/xwin/winclipboard/xevents.c b/hw/xwin/winclipboard/xevents.c
index 835195b..bf44ac9 100644
--- a/hw/xwin/winclipboard/xevents.c
+++ b/hw/xwin/winclipboard/xevents.c
@@ -107,7 +107,7 @@ MonitorSelection(XFixesSelectionNotifyEvent * e, unsigned int i)
 
     /* Save new selection owner or None */
     s_iOwners[i] = e->owner;
-    winDebug("MonitorSelection - %s - Now owned by XID %x\n",
+    winDebug("MonitorSelection - %s - Now owned by XID %lx\n",
              szSelectionNames[i], e->owner);
 }
 
@@ -172,7 +172,7 @@ winClipboardSelectionNotifyTargets(HWND hwnd, Window iWindow, Display *pDisplay,
         Atom atom = prop[i];
         char *pszAtomName = XGetAtomName(pDisplay, atom);
         data->targetList[i] = atom;
-        winDebug("winClipboardFlushXEvents - SelectionNotify - target[%d] %d = %s\n", i, atom, pszAtomName);
+        winDebug("winClipboardFlushXEvents - SelectionNotify - target[%d] %ld = %s\n", i, atom, pszAtomName);
         XFree(pszAtomName);
       }
 
@@ -231,7 +231,7 @@ winClipboardFlushXEvents(HWND hwnd,
         {
             char *pszAtomName = NULL;
 
-            winDebug("SelectionRequest - target %d\n",
+            winDebug("SelectionRequest - target %ld\n",
                      event.xselectionrequest.target);
 
             pszAtomName = XGetAtomName(pDisplay,
@@ -561,7 +561,7 @@ winClipboardFlushXEvents(HWND hwnd,
             */
             if (event.xselection.property == None) {
                     ErrorF("winClipboardFlushXEvents - SelectionNotify - "
-                           "Conversion to format %d refused.\n",
+                           "Conversion to format %ld refused.\n",
                            event.xselection.target);
                     return WIN_XEVENTS_FAILED;
                 }
@@ -591,7 +591,7 @@ winClipboardFlushXEvents(HWND hwnd,
             {
                 char *pszAtomName = NULL;
 
-                winDebug("SelectionNotify - returned data %d left %d\n",
+                winDebug("SelectionNotify - returned data %lu left %lu\n",
                          xtpText.nitems, ulReturnBytesLeft);
                 pszAtomName = XGetAtomName(pDisplay, xtpText.encoding);
                 winDebug("Notify atom name %s\n", pszAtomName);
commit 98798fcf0d1dc66c539abb2ecec0acc676d0b574
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Fri Feb 6 20:42:54 2015 +0000

    hw/xwin: printf format fix in winProcessXEventsTimeout()
    
    remainingTime is computed as a long int, so use %ld format specifier
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Colin Harrison <colin.harrison at virgin.net>

diff --git a/hw/xwin/winclipboard/wndproc.c b/hw/xwin/winclipboard/wndproc.c
index 229a948..e1517f2 100644
--- a/hw/xwin/winclipboard/wndproc.c
+++ b/hw/xwin/winclipboard/wndproc.c
@@ -104,7 +104,7 @@ winProcessXEventsTimeout(HWND hwnd, Window iWindow, Display * pDisplay,
         remainingTime = dwStopTime - GetTickCount();
         tv.tv_sec = remainingTime / 1000;
         tv.tv_usec = (remainingTime % 1000) * 1000;
-        winDebug("winProcessXEventsTimeout () - %d milliseconds left\n",
+        winDebug("winProcessXEventsTimeout () - %ld milliseconds left\n",
                  remainingTime);
 
         /* Break out if no time left */
commit 5b6f511c2fcad4edaccedbeb9842680cf3aeffb1
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Fri Feb 6 20:40:46 2015 +0000

    hw/xwin: printf format fix in winCreateDefColormap()
    
    Use %lu for unsigned long
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Colin Harrison <colin.harrison at virgin.net>

diff --git a/hw/xwin/wincmap.c b/hw/xwin/wincmap.c
index 1bdc7df..318bfac 100644
--- a/hw/xwin/wincmap.c
+++ b/hw/xwin/wincmap.c
@@ -515,7 +515,7 @@ winCreateDefColormap(ScreenPtr pScreen)
      */
 
 #if CYGDEBUG
-    winDebug("winCreateDefColormap - defColormap: %d\n", pScreen->defColormap);
+    winDebug("winCreateDefColormap - defColormap: %lu\n", pScreen->defColormap);
 #endif
 
     /* Allocate an X colormap, owned by client 0 */
commit eb679671560b21206a47476dfbc23518d8d46588
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Fri Feb 6 20:38:26 2015 +0000

    hw/xwin: printf format fixes in winAllocatePrivates()
    
    serverGeneration is of type unsigned long, so use %lu format specifier
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Colin Harrison <colin.harrison at virgin.net>

diff --git a/hw/xwin/winallpriv.c b/hw/xwin/winallpriv.c
index 629af92..816b030 100644
--- a/hw/xwin/winallpriv.c
+++ b/hw/xwin/winallpriv.c
@@ -48,8 +48,8 @@ winAllocatePrivates(ScreenPtr pScreen)
     winPrivScreenPtr pScreenPriv;
 
 #if CYGDEBUG
-    winDebug("winAllocateScreenPrivates - g_ulServerGeneration: %d "
-             "serverGeneration: %d\n", g_ulServerGeneration, serverGeneration);
+    winDebug("winAllocateScreenPrivates - g_ulServerGeneration: %lu "
+             "serverGeneration: %lu\n", g_ulServerGeneration, serverGeneration);
 #endif
 
     /* We need a new slot for our privates if the screen gen has changed */
commit 0d6c499b9976d305e13685eb79b4bb7cd4250f58
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Fri Feb 6 20:27:11 2015 +0000

    hw/xwin: printf format fixes in winConfigKeyboard()
    
    struct winInfoRec.keyboard members are of type long, not type int
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Colin Harrison <colin.harrison at virgin.net>

diff --git a/hw/xwin/winconfig.c b/hw/xwin/winconfig.c
index 321dfee..d26cc93 100644
--- a/hw/xwin/winconfig.c
+++ b/hw/xwin/winconfig.c
@@ -263,7 +263,7 @@ winConfigKeyboard(DeviceIntPtr pDevice)
                 break;
             }
             g_winInfo.keyboard.rate = (kbd_speed > 0) ? kbd_speed : 1;
-            winMsgVerb(X_PROBED, 1, "Setting autorepeat to delay=%d, rate=%d\n",
+            winMsgVerb(X_PROBED, 1, "Setting autorepeat to delay=%ld, rate=%ld\n",
                        g_winInfo.keyboard.delay, g_winInfo.keyboard.rate);
         }
     }
commit ba468e003e32c406f4885c8cb3deeb1c8175cd45
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Mon Jun 29 14:25:49 2015 +0100

    hw/xwin: printf format fixes for XID type
    
    XID inside the server has type unsigned int (x86_64) or unsigned long (x86)
    
    Follow the example of the rest of the server and cast to unsigned int and use
    a %u or %x format.
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Colin Harrison <colin.harrison at virgin.net>

diff --git a/hw/xwin/glx/winpriv.c b/hw/xwin/glx/winpriv.c
index 9b4baf3..e6afbff 100644
--- a/hw/xwin/glx/winpriv.c
+++ b/hw/xwin/glx/winpriv.c
@@ -21,7 +21,7 @@ void
 HWND
 winGetWindowInfo(WindowPtr pWin)
 {
-    winTrace("%s: pWin %p XID 0x%x\n", __FUNCTION__, pWin, pWin->drawable.id);
+    winTrace("%s: pWin %p XID 0x%x\n", __FUNCTION__, pWin, (unsigned int)pWin->drawable.id);
 
     /* a real window was requested */
     if (pWin != NULL) {
diff --git a/hw/xwin/winmultiwindowicons.c b/hw/xwin/winmultiwindowicons.c
index c22e688..cc45387 100644
--- a/hw/xwin/winmultiwindowicons.c
+++ b/hw/xwin/winmultiwindowicons.c
@@ -449,8 +449,9 @@ winXIconToHICON(Display * pDisplay, Window id, int iconSize)
 
         hints = XGetWMHints(pDisplay, id);
         if (hints) {
-            winDebug("winXIconToHICON: id 0x%x icon_pixmap hint %x\n", id,
-                     hints->icon_pixmap);
+            winDebug("winXIconToHICON: id 0x%x icon_pixmap hint 0x%x\n",
+                     (unsigned int)id,
+                     (unsigned int)hints->icon_pixmap);
 
             if (hints->icon_pixmap) {
                 Window root;
@@ -465,8 +466,8 @@ winXIconToHICON(Display * pDisplay, Window id, int iconSize)
                 xImageIcon =
                     XGetImage(pDisplay, hints->icon_pixmap, 0, 0, width, height,
                               0xFFFFFFFF, ZPixmap);
-                winDebug("winXIconToHICON: id 0x%x icon Ximage 0x%p\n", id,
-                         xImageIcon);
+                winDebug("winXIconToHICON: id 0x%x icon Ximage 0x%p\n",
+                         (unsigned int)id, xImageIcon);
 
                 if (hints->icon_mask)
                     xImageMask =
diff --git a/hw/xwin/winmultiwindowwindow.c b/hw/xwin/winmultiwindowwindow.c
index 1ecf0b9..4a208dd 100644
--- a/hw/xwin/winmultiwindowwindow.c
+++ b/hw/xwin/winmultiwindowwindow.c
@@ -379,8 +379,9 @@ winReparentWindowMultiWindow(WindowPtr pWin, WindowPtr pPriorParent)
 
     winDebug
         ("winReparentMultiWindow - pWin:%p XID:0x%x, reparent from pWin:%p XID:0x%x to pWin:%p XID:0x%x\n",
-         pWin, pWin->drawable.id, pPriorParent, pPriorParent->drawable.id,
-         pWin->parent, pWin->parent->drawable.id);
+         pWin, (unsigned int)pWin->drawable.id,
+         pPriorParent, (unsigned int)pPriorParent->drawable.id,
+         pWin->parent, (unsigned int)pWin->parent->drawable.id);
 
     WIN_UNWRAP(ReparentWindow);
     if (pScreen->ReparentWindow)
@@ -493,7 +494,7 @@ winCreateWindowsWindow(WindowPtr pWin)
     winInitMultiWindowClass();
 
     winDebug("winCreateWindowsTopLevelWindow - pWin:%p XID:0x%x \n", pWin,
-             pWin->drawable.id);
+             (unsigned int)pWin->drawable.id);
 
     iX = pWin->drawable.x + GetSystemMetrics(SM_XVIRTUALSCREEN);
     iY = pWin->drawable.y + GetSystemMetrics(SM_YVIRTUALSCREEN);
@@ -619,7 +620,7 @@ winDestroyWindowsWindow(WindowPtr pWin)
     HICON hIconSm;
 
     winDebug("winDestroyWindowsWindow - pWin:%p XID:0x%x \n", pWin,
-             pWin->drawable.id);
+             (unsigned int)pWin->drawable.id);
 
     /* Bail out if the Windows window handle is invalid */
     if (pWinPriv->hWnd == NULL)
@@ -713,7 +714,7 @@ winGetWindowID(WindowPtr pWin)
     FindClientResourcesByType(c, RT_WINDOW, winFindWindow, &wi);
 
 #if CYGMULTIWINDOW_DEBUG
-    ErrorF("winGetWindowID - Window ID: %d\n", wi.id);
+    ErrorF("winGetWindowID - Window ID: %u\n", (unsigned int)wi.id);
 #endif
 
     return wi.id;
@@ -993,8 +994,9 @@ winAdjustXWindow(WindowPtr pWin, HWND hwnd)
     vlist[2] = pDraw->width + dW;
     vlist[3] = pDraw->height + dH;
 #if CYGWINDOWING_DEBUG
-    ErrorF("\tConfigureWindow to (%ld, %ld) - %ldx%ld\n", vlist[0], vlist[1],
-           vlist[2], vlist[3]);
+    ErrorF("\tConfigureWindow to (%u, %u) - %ux%u\n",
+           (unsigned int)vlist[0], (unsigned int)vlist[1],
+           (unsigned int)vlist[2], (unsigned int)vlist[3]);
 #endif
     return ConfigureWindow(pWin, CWX | CWY | CWWidth | CWHeight,
                            vlist, wClient(pWin));
commit dcb797b31f0affdc4b08b000dd92ec38fa261953
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Thu Oct 2 14:28:46 2014 +0100

    hw/xwin: printf format fixes for HWND type
    
    HWND derives from HANDLE, a pointer type, so we should use the %p format
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Colin Harrison <colin.harrison at virgin.net>

diff --git a/hw/xwin/winclipboard/wndproc.c b/hw/xwin/winclipboard/wndproc.c
index 1ea5bc6..229a948 100644
--- a/hw/xwin/winclipboard/wndproc.c
+++ b/hw/xwin/winclipboard/wndproc.c
@@ -195,7 +195,7 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
     case WM_CHANGECBCHAIN:
     {
         winDebug("winClipboardWindowProc - WM_CHANGECBCHAIN: wParam(%x) "
-                 "lParam(%x) s_hwndNextViewer(%x)\n",
+                 "lParam(%x) s_hwndNextViewer(%p)\n",
                  wParam, lParam, s_hwndNextViewer);
 
         if ((HWND) wParam == s_hwndNextViewer) {
@@ -236,7 +236,7 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
         first = GetClipboardViewer();   /* Get handle to first viewer in chain. */
         if (first == hwnd)
             return 0;           /* Make sure it's not us! */
-        winDebug("  WM_WM_REINIT: Replacing us(%x) with %x at head "
+        winDebug("  WM_WM_REINIT: Replacing us(%p) with %p at head "
                  "of chain\n", hwnd, s_hwndNextViewer);
         s_fCBCInitialized = FALSE;
         ChangeClipboardChain(hwnd, s_hwndNextViewer);
diff --git a/hw/xwin/winmsg.c b/hw/xwin/winmsg.c
index 56e7a09..79399a4 100644
--- a/hw/xwin/winmsg.c
+++ b/hw/xwin/winmsg.c
@@ -158,7 +158,7 @@ winDebugWin32Message(const char *function, HWND hwnd, UINT message,
             getenv("WIN_DEBUG_WM_USER")) {
             winDebug("%s - Message WM_USER + %d\n", function,
                      message - WM_USER);
-            winDebug("\thwnd 0x%x wParam 0x%x lParam 0x%x\n", hwnd, wParam,
+            winDebug("\thwnd 0x%p wParam 0x%x lParam 0x%x\n", hwnd, wParam,
                      lParam);
         }
     }
@@ -170,7 +170,7 @@ winDebugWin32Message(const char *function, HWND hwnd, UINT message,
         buffer[63] = 0;
         if (force || getenv("WIN_DEBUG_MESSAGES") || getenv(buffer)) {
             winDebug("%s - Message %s\n", function, MESSAGE_NAMES[message]);
-            winDebug("\thwnd 0x%x wParam 0x%x lParam 0x%x\n", hwnd, wParam,
+            winDebug("\thwnd 0x%p wParam 0x%x lParam 0x%x\n", hwnd, wParam,
                      lParam);
         }
     }
commit f1d14266672c8130e992dd9d0c08fd1cef0f08cb
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Wed Oct 1 22:12:26 2014 +0100

    hw/xwin: Ensure format warnings in winclipboard/
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Colin Harrison <colin.harrison at virgin.net>

diff --git a/hw/xwin/winclipboard/internal.h b/hw/xwin/winclipboard/internal.h
index c6bde84..6c26caf 100644
--- a/hw/xwin/winclipboard/internal.h
+++ b/hw/xwin/winclipboard/internal.h
@@ -50,8 +50,8 @@
  * References to external symbols
  */
 
-extern void winDebug(const char *format, ...);
-extern void ErrorF(const char *format, ...);
+extern void winDebug(const char *format, ...) _X_ATTRIBUTE_PRINTF(1, 2);
+extern void ErrorF(const char *format, ...) _X_ATTRIBUTE_PRINTF(1, 2);
 
 /*
  * winclipboardtextconv.c
commit 38f340b13e693a0d456a9ab22a6474c8f55375fa
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Mon Jun 29 15:30:36 2015 +0100

    hw/xwin: Remove GetTickCount() from various pieces of debugging output
    
    The use of %d format for the DWORD return value of GetTickCount() isn't
    portable, but it doesn't seem to be worth fixing it when this information isn't
    very useful (and is redundant to the timestamping of log messages we now have)
    
    Instead just remove these uses of GetTickCount()
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Colin Harrison <colin.harrison at virgin.net>

diff --git a/hw/xwin/winmultiwindowwindow.c b/hw/xwin/winmultiwindowwindow.c
index c22d690..1ecf0b9 100644
--- a/hw/xwin/winmultiwindowwindow.c
+++ b/hw/xwin/winmultiwindowwindow.c
@@ -219,8 +219,8 @@ winPositionWindowMultiWindow(WindowPtr pWin, int x, int y)
 
 #if CYGMULTIWINDOW_DEBUG
     lpRc = &rcNew;
-    ErrorF("winPositionWindowMultiWindow - (%d ms)drawable (%d, %d)-(%d, %d)\n",
-           GetTickCount(), lpRc->left, lpRc->top, lpRc->right, lpRc->bottom);
+    ErrorF("winPositionWindowMultiWindow - drawable (%d, %d)-(%d, %d)\n",
+           lpRc->left, lpRc->top, lpRc->right, lpRc->bottom);
 #endif
 
     /*
@@ -237,16 +237,16 @@ winPositionWindowMultiWindow(WindowPtr pWin, int x, int y)
     GetClientRect(hWnd, &rcClient);
 
     lpRc = &rcNew;
-    ErrorF("winPositionWindowMultiWindow - (%d ms)rcNew (%d, %d)-(%d, %d)\n",
-           GetTickCount(), lpRc->left, lpRc->top, lpRc->right, lpRc->bottom);
+    ErrorF("winPositionWindowMultiWindow - rcNew (%d, %d)-(%d, %d)\n",
+           lpRc->left, lpRc->top, lpRc->right, lpRc->bottom);
 
     lpRc = &rcOld;
-    ErrorF("winPositionWindowMultiWindow - (%d ms)rcOld (%d, %d)-(%d, %d)\n",
-           GetTickCount(), lpRc->left, lpRc->top, lpRc->right, lpRc->bottom);
+    ErrorF("winPositionWindowMultiWindow - rcOld (%d, %d)-(%d, %d)\n",
+           lpRc->left, lpRc->top, lpRc->right, lpRc->bottom);
 
     lpRc = &rcClient;
-    ErrorF("(%d ms)rcClient (%d, %d)-(%d, %d)\n",
-           GetTickCount(), lpRc->left, lpRc->top, lpRc->right, lpRc->bottom);
+    ErrorF("rcClient (%d, %d)-(%d, %d)\n",
+           lpRc->left, lpRc->top, lpRc->right, lpRc->bottom);
 #endif
 
     /* Check if the old rectangle and new rectangle are the same */
diff --git a/hw/xwin/winmultiwindowwm.c b/hw/xwin/winmultiwindowwm.c
index 6599dfb..1efe96a 100644
--- a/hw/xwin/winmultiwindowwm.c
+++ b/hw/xwin/winmultiwindowwm.c
@@ -772,8 +772,8 @@ winMultiWindowWMProc(void *pArg)
         }
 
 #if CYGMULTIWINDOW_DEBUG
-        ErrorF("winMultiWindowWMProc - %d ms MSG: %d ID: %d\n",
-               GetTickCount(), (int) pNode->msg.msg, (int) pNode->msg.dwID);
+        ErrorF("winMultiWindowWMProc - MSG: %d ID: %d\n",
+               (int) pNode->msg.msg, (int) pNode->msg.dwID);
 #endif
 
         /* Branch on the message type */
diff --git a/hw/xwin/winmultiwindowwndproc.c b/hw/xwin/winmultiwindowwndproc.c
index d296f0f..ab892f2 100644
--- a/hw/xwin/winmultiwindowwndproc.c
+++ b/hw/xwin/winmultiwindowwndproc.c
@@ -1037,9 +1037,8 @@ winTopLevelWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
         default:
             strcpy(buf, "UNKNOWN_FLAG");
         }
-        ErrorF("winTopLevelWindowProc - WM_SIZE to %dx%d (%s) - %d ms\n",
-               (int) LOWORD(lParam), (int) HIWORD(lParam), buf,
-               (int) (GetTickCount()));
+        ErrorF("winTopLevelWindowProc - WM_SIZE to %dx%d (%s)\n",
+               (int) LOWORD(lParam), (int) HIWORD(lParam), buf);
     }
 #endif
         if (!hasEnteredSizeMove) {
diff --git a/hw/xwin/winwin32rootlesswndproc.c b/hw/xwin/winwin32rootlesswndproc.c
index f65811c..79d9591 100644
--- a/hw/xwin/winwin32rootlesswndproc.c
+++ b/hw/xwin/winwin32rootlesswndproc.c
@@ -858,8 +858,7 @@ winMWExtWMWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 
     case WM_MOVE:
 #if CYGMULTIWINDOW_DEBUG
-        winDebug("winMWExtWMWindowProc - WM_MOVE - %d ms\n",
-                 (unsigned int) GetTickCount());
+        winDebug("winMWExtWMWindowProc - WM_MOVE\n");
 #endif
         if (g_fNoConfigureWindow)
             break;
@@ -902,8 +901,7 @@ winMWExtWMWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 
     case WM_SHOWWINDOW:
 #if CYGMULTIWINDOW_DEBUG || TRUE
-        winDebug("winMWExtWMWindowProc - WM_SHOWWINDOW - %d ms\n",
-                 (unsigned int) GetTickCount());
+        winDebug("winMWExtWMWindowProc - WM_SHOWWINDOW\n");
 #endif
         /* Bail out if the window is being hidden */
         if (!wParam)
@@ -1155,8 +1153,7 @@ winMWExtWMWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
         /* see dix/window.c */
         /* FIXME: Maximize/Restore? */
 #if CYGMULTIWINDOW_DEBUG
-        winDebug("winMWExtWMWindowProc - WM_SIZE - %d ms\n",
-                 (unsigned int) GetTickCount());
+        winDebug("winMWExtWMWindowProc - WM_SIZE\n");
 #endif
 #if CYGMULTIWINDOW_DEBUG
         winDebug("\t(%d, %d) %d\n", (short) LOWORD(lParam),
@@ -1224,8 +1221,7 @@ winMWExtWMWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 
     case WM_ACTIVATEAPP:
 #if CYGMULTIWINDOW_DEBUG
-        winDebug("winMWExtWMWindowProc - WM_ACTIVATEAPP - %d ms\n",
-                 (unsigned int) GetTickCount());
+        winDebug("winMWExtWMWindowProc - WM_ACTIVATEAPP\n");
 #endif
         if (wParam) {
             if (winIsInternalWMRunning(pScreenInfo)) {
@@ -1257,16 +1253,14 @@ winMWExtWMWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 
     case WM_ENTERSIZEMOVE:
 #if CYGMULTIWINDOW_DEBUG
-        winDebug("winMWExtWMWindowProc - WM_ENTERSIZEMOVE - %d ms\n",
-                 (unsigned int) GetTickCount());
+        winDebug("winMWExtWMWindowProc - WM_ENTERSIZEMOVE\n");
 #endif
         pRLWinPriv->fMovingOrSizing = TRUE;
         break;
 
     case WM_EXITSIZEMOVE:
 #if CYGMULTIWINDOW_DEBUG
-        winDebug("winMWExtWMWindowProc - WM_EXITSIZEMOVE - %d ms\n",
-                 (unsigned int) GetTickCount());
+        winDebug("winMWExtWMWindowProc - WM_EXITSIZEMOVE\n");
 #endif
         pRLWinPriv->fMovingOrSizing = FALSE;
 
commit 732e3b9c08532f40656010eac9d128601cc88c3f
Author: Michel Dänzer <michel.daenzer at amd.com>
Date:   Mon Jul 6 18:45:51 2015 -0700

    Instead of one glTexSubImage2D call for each glyph.
    
    This significantly reduces the amount of time it takes for xterm to start
    up on a fresh X server with the radeonsi driver.
    
    v2: Use GLYPHWIDTHBYTESPADDED instead of hardcoding 4 bytes glyph
        alignment (Keith Packard)
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glamor/glamor_font.c b/glamor/glamor_font.c
index cc0fecf..6b3a16a 100644
--- a/glamor/glamor_font.c
+++ b/glamor/glamor_font.c
@@ -45,6 +45,7 @@ glamor_font_get(ScreenPtr screen, FontPtr font)
     unsigned char       c[2];
     CharInfoPtr         glyph;
     unsigned long       count;
+    char                *bits;
 
     if (glamor_priv->glsl_version < 130)
         return NULL;
@@ -62,8 +63,6 @@ glamor_font_get(ScreenPtr screen, FontPtr font)
     if (glamor_font->realized)
         return glamor_font;
 
-    glamor_font->realized = TRUE;
-
     /* Figure out how many glyphs are in the font */
     num_cols = font->info.lastCol - font->info.firstCol + 1;
     num_rows = font->info.lastRow - font->info.firstRow + 1;
@@ -81,6 +80,10 @@ glamor_font_get(ScreenPtr screen, FontPtr font)
     overall_width = glyph_width_bytes * num_cols;
     overall_height = glyph_height * num_rows;
 
+    bits = malloc(overall_width * overall_height);
+    if (!bits)
+        return NULL;
+
     /* Check whether the font has a default character */
     c[0] = font->info.lastRow + 1;
     c[1] = font->info.lastCol + 1;
@@ -100,12 +103,6 @@ glamor_font_get(ScreenPtr screen, FontPtr font)
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 
-    /* Allocate storage */
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_R8UI, overall_width, overall_height,
-                 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, NULL);
-
-    glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
-
     /* Paint all of the glyphs */
     for (row = 0; row < num_rows; row++) {
         for (col = 0; col < num_cols; col++) {
@@ -114,13 +111,29 @@ glamor_font_get(ScreenPtr screen, FontPtr font)
 
             (*font->get_glyphs)(font, 1, c, TwoD16Bit, &count, &glyph);
 
-            if (count)
-                glTexSubImage2D(GL_TEXTURE_2D, 0, col * glyph_width_bytes, row * glyph_height,
-                                GLYPHWIDTHBYTES(glyph), GLYPHHEIGHTPIXELS(glyph),
-                                GL_RED_INTEGER, GL_UNSIGNED_BYTE, glyph->bits);
+            if (count) {
+                char *dst = bits + row * glyph_height * overall_width +
+                    col * glyph_width_bytes;
+                char *src = glyph->bits;
+                unsigned y;
+
+                for (y = 0; y < GLYPHHEIGHTPIXELS(glyph); y++) {
+                    memcpy(dst, src, GLYPHWIDTHBYTES(glyph));
+                    dst += overall_width;
+                    src += GLYPHWIDTHBYTESPADDED(glyph);
+                }
+            }
         }
     }
 
+    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_R8UI, overall_width, overall_height,
+                 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, bits);
+
+    free(bits);
+
+    glamor_font->realized = TRUE;
+
     return glamor_font;
 }
 
commit ac94cdb9df94dd26688de6d3d9143ac48f7b3c7b
Author: Julien Cristau <jcristau at debian.org>
Date:   Thu Jul 2 20:16:21 2015 +0200

    mi: fix typo in warning about overflowing queue
    
    Debian bug#726041
    
    Reported-by: Vincent Hobeïka <vincent.hobeika at gmail.com>
    Signed-off-by: Julien Cristau <jcristau at debian.org>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/mi/mieq.c b/mi/mieq.c
index 8907a6e..b7be193 100644
--- a/mi/mieq.c
+++ b/mi/mieq.c
@@ -599,7 +599,7 @@ mieqProcessInputEvents(void)
         ErrorF("[mi] EQ processing has resumed after %lu dropped events.\n",
                (unsigned long) miEventQueue.dropped);
         ErrorF
-            ("[mi] This may be caused my a misbehaving driver monopolizing the server's resources.\n");
+            ("[mi] This may be caused by a misbehaving driver monopolizing the server's resources.\n");
         miEventQueue.dropped = 0;
     }
 
commit e3624aa5fde658c44724a7ea21f5df9e3c586923
Author: Dave Airlie <airlied at gmail.com>
Date:   Wed Jul 1 20:41:15 2015 +1000

    xserver: fix build with glamor disabled.
    
    This fixes modesetting when glamor is disabled.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 8603338..7ee7590 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -1000,6 +1000,7 @@ msSharePixmapBacking(PixmapPtr ppix, ScreenPtr screen, void **handle)
 static Bool
 msSetSharedPixmapBacking(PixmapPtr ppix, void *fd_handle)
 {
+#ifdef GLAMOR
     ScreenPtr screen = ppix->drawable.pScreen;
     ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
     modesettingPtr ms = modesettingPTR(scrn);
@@ -1020,6 +1021,9 @@ msSetSharedPixmapBacking(PixmapPtr ppix, void *fd_handle)
         return ret;
 
     return TRUE;
+#else
+    return FALSE;
+#endif
 }
 
 static Bool
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 8dbac07..dc7d9f6 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -146,6 +146,7 @@ drmmode_create_bo(drmmode_ptr drmmode, drmmode_bo *bo,
 Bool
 drmmode_bo_for_pixmap(drmmode_ptr drmmode, drmmode_bo *bo, PixmapPtr pixmap)
 {
+#ifdef GLAMOR
     ScreenPtr screen = xf86ScrnToScreen(drmmode->scrn);
     uint16_t pitch;
     uint32_t size;
@@ -165,9 +166,9 @@ drmmode_bo_for_pixmap(drmmode_ptr drmmode, drmmode_bo *bo, PixmapPtr pixmap)
                    "Failed to get fd for flip to new front.\n");
         return FALSE;
     }
-
     bo->dumb = dumb_get_bo_from_fd(drmmode->fd, fd, pitch, size);
     close(fd);
+#endif
 
     return bo->dumb != NULL;
 }
diff --git a/hw/xfree86/drivers/modesetting/present.c b/hw/xfree86/drivers/modesetting/present.c
index 0905398..bb2976b 100644
--- a/hw/xfree86/drivers/modesetting/present.c
+++ b/hw/xfree86/drivers/modesetting/present.c
@@ -641,8 +641,8 @@ static present_screen_info_rec ms_present_screen_info = {
     .flush = ms_present_flush,
 
     .capabilities = PresentCapabilityNone,
-    .check_flip = ms_present_check_flip,
 #ifdef GLAMOR
+    .check_flip = ms_present_check_flip,
     .flip = ms_present_flip,
     .unflip = ms_present_unflip,
 #endif
commit 3703c88ac18063a35fd8c0fc52fee52d8c669638
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Jul 1 16:23:45 2015 -0700

    glamor: Use GL_ARB_debug_output to log GL errors.
    
    This should help people debugging when glamor does something stupid on
    their driver.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>

diff --git a/glamor/glamor.c b/glamor/glamor.c
index 702efd1..50d85ff 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -384,6 +384,45 @@ glamor_check_instruction_count(int gl_version)
     return TRUE;
 }
 
+static void GLAPIENTRY
+glamor_debug_output_callback(GLenum source,
+                             GLenum type,
+                             GLuint id,
+                             GLenum severity,
+                             GLsizei length,
+                             const GLchar *message,
+                             const void *userParam)
+{
+    ScreenPtr screen = (void *)userParam;
+    LogMessageVerb(X_ERROR, 0, "glamor%d: GL error: %*s\n",
+               screen->myNum, length, message);
+}
+
+/**
+ * Configures GL_ARB_debug_output to give us immediate callbacks when
+ * GL errors occur, so that we can log them.
+ */
+static void
+glamor_setup_debug_output(ScreenPtr screen)
+{
+    if (!epoxy_has_gl_extension("GL_ARB_debug_output"))
+        return;
+
+    glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
+    glDebugMessageControl(GL_DEBUG_SOURCE_API,
+                          GL_DEBUG_TYPE_ERROR,
+                          GL_DONT_CARE,
+                          0, NULL, GL_TRUE);
+    glDebugMessageCallback(glamor_debug_output_callback,
+                           screen);
+
+    /* If KHR_debug is present, all debug output is disabled by
+     * default on non-debug contexts.
+     */
+    if (epoxy_has_gl_extension("GL_KHR_debug"))
+        glEnable(GL_DEBUG_OUTPUT);
+}
+
 /** Set up glamor for an already-configured GL context. */
 Bool
 glamor_init(ScreenPtr screen, unsigned int flags)
@@ -531,6 +570,8 @@ glamor_init(ScreenPtr screen, unsigned int flags)
         epoxy_gl_version() >= 30 ||
         epoxy_has_gl_extension("GL_NV_pack_subimage");
 
+    glamor_setup_debug_output(screen);
+
     glamor_priv->use_quads = (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP);
     /* Driver-specific hack: Avoid using GL_QUADS on VC4, where
      * they'll be emulated more expensively than we can with our
commit f4dfd282d311e5f23631d33e0251bad1854b1ab9
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Jul 1 14:46:55 2015 -0700

    glamor: Add an assert to catch the previous bug.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Acked-by: Michel Dänzer <michel.daenzer at amd.com>

diff --git a/glamor/glamor_transfer.c b/glamor/glamor_transfer.c
index aa5e861..155d7e0 100644
--- a/glamor/glamor_transfer.c
+++ b/glamor/glamor_transfer.c
@@ -186,6 +186,8 @@ glamor_download_boxes(PixmapPtr pixmap, BoxPtr in_boxes, int in_nbox,
         BoxPtr                  boxes = in_boxes;
         int                     nbox = in_nbox;
 
+        /* This should not be called on GLAMOR_FBO_NO_FBO-allocated pixmaps. */
+        assert(fbo->fb);
         glBindFramebuffer(GL_FRAMEBUFFER, fbo->fb);
 
         while (nbox--) {
commit c268d2fc33318f9ea0019053fa5de18f193e704e
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Jul 2 17:06:27 2015 -0600

    glamor: Fix bad rendering of glyphs after an a1 glyph upload. (v3)
    
    Fixes regressions since Eric's "don't make an FBO for the glyph atlas"
    change.  The a1 upload was a fallback, as expected.  However, fallback
    reads use glReadPixels() because there's no glGetTexSubImage2D() to
    match glTexSubImage2D().  We were just binding the 0 FBO value, so the
    glReadPixels() would throw a GL error instead of getting any data.
    After the fallback was done we'd write back the undefined data to the
    atlas, blowing away the entire rest of the atlas because we didn't
    specify any bounds on our prepare.
    
    To fix the fallbacks to actually work, we'd need a prepare path that
    allocates some memory memory do a full glGetTexImage() into, then
    memcpy out of that.  Instead, just dodge the general fallback by
    implementing the specific upload we need to do here, which should also
    be *much* faster at uploading a1 glyphs since it's not
    readpixels/texsubimaging back and forth.
    
    v3: Use CopyPlane to a temp pixmap for the upload
    v4: Rewrite anholt's commit message to be from keithp's perspective
        (changes by anholt)
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Eric Anholt <eric at anholt.net>

diff --git a/glamor/glamor_composite_glyphs.c b/glamor/glamor_composite_glyphs.c
index e92f1d9..cd88524 100644
--- a/glamor/glamor_composite_glyphs.c
+++ b/glamor/glamor_composite_glyphs.c
@@ -64,45 +64,58 @@ glamor_copy_glyph(PixmapPtr     glyph_pixmap,
         .x2 = glyph_draw->width,
         .y2 = glyph_draw->height,
     };
+    PixmapPtr upload_pixmap = glyph_pixmap;
 
-    if (glyph_pixmap->drawable.bitsPerPixel == atlas_draw->bitsPerPixel) {
-        glamor_upload_boxes((PixmapPtr) atlas_draw,
-                            &box, 1,
-                            0, 0,
-                            x, y,
-                            glyph_pixmap->devPrivate.ptr,
-                            glyph_pixmap->devKind);
-    } else {
-        GCPtr scratch_gc = GetScratchGC(atlas_draw->depth, atlas_draw->pScreen);
-        ChangeGCVal changes[2];
-        if (!scratch_gc)
-            return;
+    if (glyph_pixmap->drawable.bitsPerPixel != atlas_draw->bitsPerPixel) {
 
-        /* If we're dealing with 1-bit glyphs, we upload them to
-         * the cache as normal 8-bit alpha, since that's what GL
-         * can handle.
+        /* If we're dealing with 1-bit glyphs, we copy them to a
+         * temporary 8-bit pixmap and upload them from there, since
+         * that's what GL can handle.
          */
-        assert(glyph_draw->depth == 1);
-        assert(atlas_draw->depth == 8);
+        ScreenPtr       screen = atlas_draw->pScreen;
+        GCPtr           scratch_gc;
+        ChangeGCVal     changes[2];
+
+        upload_pixmap = glamor_create_pixmap(screen,
+                                             glyph_draw->width,
+                                             glyph_draw->height,
+                                             atlas_draw->depth,
+                                             GLAMOR_CREATE_PIXMAP_CPU);
+        if (!upload_pixmap)
+            return;
 
+        scratch_gc = GetScratchGC(upload_pixmap->drawable.depth, screen);
+        if (!scratch_gc) {
+            glamor_destroy_pixmap(upload_pixmap);
+            return;
+        }
         changes[0].val = 0xff;
         changes[1].val = 0x00;
         if (ChangeGC(NullClient, scratch_gc,
-                     GCForeground|GCBackground, changes) != Success)
-            goto bail_gc;
-        ValidateGC(atlas_draw, scratch_gc);
+                     GCForeground|GCBackground, changes) != Success) {
+            glamor_destroy_pixmap(upload_pixmap);
+            FreeScratchGC(scratch_gc);
+            return;
+        }
+        ValidateGC(&upload_pixmap->drawable, scratch_gc);
 
         (*scratch_gc->ops->CopyPlane)(glyph_draw,
-                                      atlas_draw,
+                                      &upload_pixmap->drawable,
                                       scratch_gc,
                                       0, 0,
                                       glyph_draw->width,
                                       glyph_draw->height,
-                                      x, y, 0x1);
-
-    bail_gc:
-        FreeScratchGC(scratch_gc);
+                                      0, 0, 0x1);
     }
+    glamor_upload_boxes((PixmapPtr) atlas_draw,
+                        &box, 1,
+                        0, 0,
+                        x, y,
+                        upload_pixmap->devPrivate.ptr,
+                        upload_pixmap->devKind);
+
+    if (upload_pixmap != glyph_pixmap)
+        glamor_destroy_pixmap(upload_pixmap);
 }
 
 static Bool
commit 5c440817f7c128c9a9d78ef9672f22641dbeeaa1
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Jun 30 15:01:53 2015 -0700

    glamor: Use ARRAY_SIZE in a couple more places for consistency.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>

diff --git a/glamor/glamor_program.c b/glamor/glamor_program.c
index 5619216..416c54a 100644
--- a/glamor/glamor_program.c
+++ b/glamor/glamor_program.c
@@ -145,8 +145,6 @@ static glamor_location_var location_vars[] = {
     },
 };
 
-#define NUM_LOCATION_VARS       (sizeof location_vars / sizeof location_vars[0])
-
 static char *
 add_var(char *cur, const char *add)
 {
@@ -170,7 +168,7 @@ vs_location_vars(glamor_program_location locations)
     int l;
     char *vars = strdup("");
 
-    for (l = 0; vars && l < NUM_LOCATION_VARS; l++)
+    for (l = 0; vars && l < ARRAY_SIZE(location_vars); l++)
         if (locations & location_vars[l].location)
             vars = add_var(vars, location_vars[l].vs_vars);
     return vars;
@@ -182,7 +180,7 @@ fs_location_vars(glamor_program_location locations)
     int l;
     char *vars = strdup("");
 
-    for (l = 0; vars && l < NUM_LOCATION_VARS; l++)
+    for (l = 0; vars && l < ARRAY_SIZE(location_vars); l++)
         if (locations & location_vars[l].location)
             vars = add_var(vars, location_vars[l].fs_vars);
     return vars;
diff --git a/glamor/glamor_render.c b/glamor/glamor_render.c
index 78de8d7..488d1a7 100644
--- a/glamor/glamor_render.c
+++ b/glamor/glamor_render.c
@@ -707,10 +707,7 @@ combine_pict_format(PictFormatShort * des, const PictFormatShort src,
         return TRUE;
     }
 
-    for (i = 0;
-         i <
-         sizeof(pict_format_combine_tab) /
-         sizeof(pict_format_combine_tab[0]); i++) {
+    for (i = 0; i < ARRAY_SIZE(pict_format_combine_tab); i++) {
         if ((src_type == pict_format_combine_tab[i][0]
              && mask_type == pict_format_combine_tab[i][1])
             || (src_type == pict_format_combine_tab[i][1]
commit 7b6edb52435f474c43130f6ac4c6b2d2b28814f5
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Jun 30 14:59:55 2015 -0700

    glamor: Mark a bunch of single-file data static.
    
    This gives the compiler a chance to optimize when the data is never
    changed -- for example, with pict_format_combine_tab, the compiler
    ends up inlining the 24 bytes of data into just 10 more bytes of code.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>

diff --git a/glamor/glamor_core.c b/glamor/glamor_core.c
index 4f3526c..79f5981b 100644
--- a/glamor/glamor_core.c
+++ b/glamor/glamor_core.c
@@ -283,7 +283,7 @@ glamor_init_finish_access_shaders(ScreenPtr screen)
     glUniform1i(glamor_priv->finish_access_swap_rb[1], 0);
 }
 
-GCOps glamor_gc_ops = {
+static GCOps glamor_gc_ops = {
     .FillSpans = glamor_fill_spans,
     .SetSpans = glamor_set_spans,
     .PutImage = glamor_put_image,
diff --git a/glamor/glamor_program.c b/glamor/glamor_program.c
index 1dc5f19..5619216 100644
--- a/glamor/glamor_program.c
+++ b/glamor/glamor_program.c
@@ -499,7 +499,7 @@ use_source_solid(CARD8 op, PicturePtr src, PicturePtr dst, glamor_program *prog)
     return TRUE;
 }
 
-const glamor_facet glamor_source_solid = {
+static const glamor_facet glamor_source_solid = {
     .name = "render_solid",
     .fs_exec = "       vec4 source = fg;\n",
     .locations = glamor_program_location_fg,
@@ -517,7 +517,7 @@ use_source_picture(CARD8 op, PicturePtr src, PicturePtr dst, glamor_program *pro
                               prog->fill_size_inv_uniform);
 }
 
-const glamor_facet glamor_source_picture = {
+static const glamor_facet glamor_source_picture = {
     .name = "render_picture",
     .vs_exec =  "       fill_pos = (fill_offset + primitive.xy + pos) * fill_size_inv;\n",
     .fs_exec =  "       vec4 source = texture2D(sampler, fill_pos);\n",
@@ -533,14 +533,14 @@ use_source_1x1_picture(CARD8 op, PicturePtr src, PicturePtr dst, glamor_program
     return glamor_set_texture_pixmap((PixmapPtr) src->pDrawable);
 }
 
-const glamor_facet glamor_source_1x1_picture = {
+static const glamor_facet glamor_source_1x1_picture = {
     .name = "render_picture",
     .fs_exec =  "       vec4 source = texture2D(sampler, vec2(0.5));\n",
     .locations = glamor_program_location_fillsamp,
     .use_render = use_source_1x1_picture,
 };
 
-const glamor_facet *glamor_facet_source[glamor_program_source_count] = {
+static const glamor_facet *glamor_facet_source[glamor_program_source_count] = {
     [glamor_program_source_solid] = &glamor_source_solid,
     [glamor_program_source_picture] = &glamor_source_picture,
     [glamor_program_source_1x1_picture] = &glamor_source_1x1_picture,
diff --git a/glamor/glamor_render.c b/glamor/glamor_render.c
index 509ebb8..78de8d7 100644
--- a/glamor/glamor_render.c
+++ b/glamor/glamor_render.c
@@ -660,7 +660,7 @@ glamor_flush_composite_rects(ScreenPtr screen)
     glamor_glDrawArrays_GL_QUADS(glamor_priv, glamor_priv->render_nr_quads);
 }
 
-int pict_format_combine_tab[][3] = {
+static const int pict_format_combine_tab[][3] = {
     {PICT_TYPE_ARGB, PICT_TYPE_A, PICT_TYPE_ARGB},
     {PICT_TYPE_ABGR, PICT_TYPE_A, PICT_TYPE_ABGR},
 };
commit 3fe6731b17ae953d49db4c1bf95e0022244513e1
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Jun 30 14:50:43 2015 -0700

    glamor: Make a bunch of single-file glamor functions static.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>

diff --git a/glamor/glamor_largepixmap.c b/glamor/glamor_largepixmap.c
index cbfd033..9a6c95e 100644
--- a/glamor/glamor_largepixmap.c
+++ b/glamor/glamor_largepixmap.c
@@ -2,6 +2,10 @@
 
 #include "glamor_priv.h"
 
+static void
+glamor_get_transform_extent_from_box(struct pixman_box32 *box,
+                                     struct pixman_transform *transform);
+
 static inline glamor_pixmap_private *
 __glamor_large(glamor_pixmap_private *pixmap_priv) {
     assert(glamor_pixmap_priv_is_large(pixmap_priv));
@@ -681,7 +685,7 @@ glamor_compute_clipped_regions(PixmapPtr pixmap,
 /* XXX overflow still exist. maybe we need to change to use region32.
  * by default. Or just use region32 for repeat cases?
  **/
-glamor_pixmap_clipped_regions *
+static glamor_pixmap_clipped_regions *
 glamor_compute_transform_clipped_regions(PixmapPtr pixmap,
                                          struct pixman_transform *transform,
                                          RegionPtr region, int *n_region,
@@ -876,7 +880,7 @@ glamor_merge_clipped_regions(PixmapPtr pixmap,
  * boundary and can avoid some overhead.
  *
  **/
-Bool
+static Bool
 glamor_get_transform_block_size(struct pixman_transform *transform,
                                 int block_w, int block_h,
                                 int *transformed_block_w,
@@ -925,7 +929,7 @@ glamor_get_transform_block_size(struct pixman_transform *transform,
 	p.v[0] = x;  \
 	p.v[1] = y;  \
 	p.v[2] = 1.0; } while (0)
-void
+static void
 glamor_get_transform_extent_from_box(struct pixman_box32 *box,
                                      struct pixman_transform *transform)
 {
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index 8f63088..66e5012 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -660,12 +660,6 @@ void glamor_composite(CARD8 op,
 void glamor_composite_rects(CARD8 op,
                             PicturePtr pDst,
                             xRenderColor *color, int nRect, xRectangle *rects);
-PicturePtr glamor_convert_gradient_picture(ScreenPtr screen,
-                                           PicturePtr source,
-                                           int x_source,
-                                           int y_source, int width, int height);
-
-void *glamor_setup_composite_vbo(ScreenPtr screen, int n_verts);
 
 /* glamor_trapezoid.c */
 void glamor_trapezoids(CARD8 op,
@@ -741,14 +735,6 @@ glamor_compute_clipped_regions_ext(PixmapPtr pixmap,
                                    int inner_block_w, int inner_block_h,
                                    int reverse, int upsidedown);
 
-glamor_pixmap_clipped_regions *
-glamor_compute_transform_clipped_regions(PixmapPtr pixmap,
-                                         struct pixman_transform *transform,
-                                         RegionPtr region,
-                                         int *n_region, int dx, int dy,
-                                         int repeat_type, int reverse,
-                                         int upsidedown);
-
 Bool glamor_composite_largepixmap_region(CARD8 op,
                                          PicturePtr source,
                                          PicturePtr mask,
@@ -764,14 +750,6 @@ Bool glamor_composite_largepixmap_region(CARD8 op,
                                          INT16 x_dest, INT16 y_dest,
                                          CARD16 width, CARD16 height);
 
-Bool glamor_get_transform_block_size(struct pixman_transform *transform,
-                                     int block_w, int block_h,
-                                     int *transformed_block_w,
-                                     int *transformed_block_h);
-
-void glamor_get_transform_extent_from_box(struct pixman_box32 *temp_box,
-                                          struct pixman_transform *transform);
-
 /**
  * Upload a picture to gl texture. Similar to the
  * glamor_upload_pixmap_to_texture. Used in rendering.
diff --git a/glamor/glamor_render.c b/glamor/glamor_render.c
index 4a82534..509ebb8 100644
--- a/glamor/glamor_render.c
+++ b/glamor/glamor_render.c
@@ -604,7 +604,7 @@ glamor_composite_with_copy(CARD8 op,
     return ret;
 }
 
-void *
+static void *
 glamor_setup_composite_vbo(ScreenPtr screen, int n_verts)
 {
     glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
@@ -1238,7 +1238,7 @@ glamor_composite_with_shader(CARD8 op,
     return ret;
 }
 
-PicturePtr
+static PicturePtr
 glamor_convert_gradient_picture(ScreenPtr screen,
                                 PicturePtr source,
                                 int x_source,
commit a8e84e8c3b2047775fe2da9371329290eee23655
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Jun 30 14:45:43 2015 -0700

    glamor: Drop dead glamor_es2_pixmap_read_prepare().
    
    It's been unused since I killed glamor_download_pixmap_to_cpu().
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>

diff --git a/glamor/glamor_pixmap.c b/glamor/glamor_pixmap.c
index 0e51550..9a14527 100644
--- a/glamor/glamor_pixmap.c
+++ b/glamor/glamor_pixmap.c
@@ -1059,73 +1059,3 @@ glamor_upload_pixmap_to_texture(PixmapPtr pixmap)
 
     return ret;
 }
-
-/*
- * as gles2 only support a very small set of color format and
- * type when do glReadPixel,
- * Before we use glReadPixels to get back a textured pixmap,
- * Use shader to convert it to a supported format and thus
- * get a new temporary pixmap returned.
- * */
-
-glamor_pixmap_fbo *
-glamor_es2_pixmap_read_prepare(PixmapPtr source, int x, int y, int w, int h,
-                               GLenum format, GLenum type, int no_alpha,
-                               int revert, int swap_rb)
-{
-    glamor_pixmap_private *source_priv;
-    glamor_screen_private *glamor_priv;
-    ScreenPtr screen;
-    glamor_pixmap_fbo *temp_fbo;
-    float temp_xscale, temp_yscale, source_xscale, source_yscale;
-    static float vertices[8];
-    static float texcoords[8];
-
-    screen = source->drawable.pScreen;
-
-    glamor_priv = glamor_get_screen_private(screen);
-    source_priv = glamor_get_pixmap_private(source);
-    temp_fbo = glamor_create_fbo(glamor_priv, w, h, format, 0);
-    if (temp_fbo == NULL)
-        return NULL;
-
-    glamor_make_current(glamor_priv);
-    temp_xscale = 1.0 / w;
-    temp_yscale = 1.0 / h;
-
-    glamor_set_normalize_vcoords((struct glamor_pixmap_private *) NULL,
-                                 temp_xscale, temp_yscale, 0, 0, w, h,
-                                 vertices);
-
-    glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, GL_FALSE,
-                          2 * sizeof(float), vertices);
-    glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
-
-    pixmap_priv_get_scale(source_priv, &source_xscale, &source_yscale);
-    glamor_set_normalize_tcoords(source_priv, source_xscale,
-                                 source_yscale,
-                                 x, y,
-                                 x + w, y + h,
-                                 texcoords);
-
-    glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, GL_FLOAT, GL_FALSE,
-                          2 * sizeof(float), texcoords);
-    glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
-
-    glActiveTexture(GL_TEXTURE0);
-    glBindTexture(GL_TEXTURE_2D, source_priv->fbo->tex);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-
-    glamor_set_destination_pixmap_fbo(glamor_priv, temp_fbo, 0, 0, w, h);
-    glamor_set_alu(screen, GXcopy);
-    glUseProgram(glamor_priv->finish_access_prog[no_alpha]);
-    glUniform1i(glamor_priv->finish_access_revert[no_alpha], revert);
-    glUniform1i(glamor_priv->finish_access_swap_rb[no_alpha], swap_rb);
-
-    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
-
-    glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
-    glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
-    return temp_fbo;
-}
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index a8732c0..8f63088 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -626,12 +626,6 @@ void glamor_set_destination_pixmap_fbo(glamor_screen_private *glamor_priv, glamo
  * */
 void glamor_set_destination_pixmap_priv_nc(glamor_screen_private *glamor_priv, PixmapPtr pixmap, glamor_pixmap_private *pixmap_priv);
 
-glamor_pixmap_fbo *glamor_es2_pixmap_read_prepare(PixmapPtr source, int x,
-                                                  int y, int w, int h,
-                                                  GLenum format, GLenum type,
-                                                  int no_alpha, int revert,
-                                                  int swap_rb);
-
 Bool glamor_set_alu(ScreenPtr screen, unsigned char alu);
 Bool glamor_set_planemask(int depth, unsigned long planemask);
 RegionPtr glamor_bitmap_to_region(PixmapPtr pixmap);
commit cad56dc62dbf2ba097cc0fa61217897ba40d8d66
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Jun 30 14:41:27 2015 -0700

    glamor: Restore the hook to glamor_composite_rectangles().
    
    It was apparently accidentally dropped in keithp's removal of _nf
    functions in 90d326fcc687e6d6d4b308f6272ededcf8145a17.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>

diff --git a/glamor/glamor.c b/glamor/glamor.c
index 525249c..702efd1 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -616,7 +616,7 @@ glamor_init(ScreenPtr screen, unsigned int flags)
     ps->AddTraps = glamor_add_traps;
 
     glamor_priv->saved_procs.composite_rects = ps->CompositeRects;
-    ps->CompositeRects = miCompositeRects;
+    ps->CompositeRects = glamor_composite_rectangles;
 
     glamor_priv->saved_procs.glyphs = ps->Glyphs;
     ps->Glyphs = glamor_composite_glyphs;
commit 7adb38a0d18de2e8b0762d9dd82b851883ad75fe
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Jun 30 14:25:16 2015 -0700

    glamor: Fix up some weird formatting in _glamor_create_fbo_array().
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>

diff --git a/glamor/glamor_fbo.c b/glamor/glamor_fbo.c
index 9da4f45..84f3b22 100644
--- a/glamor/glamor_fbo.c
+++ b/glamor/glamor_fbo.c
@@ -424,8 +424,8 @@ glamor_create_fbo_array(glamor_screen_private *glamor_priv,
 
  cleanup:
     for (i = 0; i < block_wcnt * block_hcnt; i++)
-        if ((fbo_array)[i])
-            glamor_destroy_fbo(glamor_priv, (fbo_array)[i]);
+        if (fbo_array[i])
+            glamor_destroy_fbo(glamor_priv, fbo_array[i]);
     free(box_array);
     free(fbo_array);
     return NULL;
commit 835067a4095e5e48703aa6561fea3ee95923e832
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Jun 30 14:14:50 2015 -0700

    glamor: Drop a redundant check.
    
    Above, we've already checked for ->fbo && ->fbo->fb and returned.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>

diff --git a/glamor/glamor_pixmap.c b/glamor/glamor_pixmap.c
index f2bf223..0e51550 100644
--- a/glamor/glamor_pixmap.c
+++ b/glamor/glamor_pixmap.c
@@ -897,8 +897,7 @@ glamor_pixmap_upload_prepare(PixmapPtr pixmap, GLenum format, int no_alpha,
     }
 
     if ((flag == GLAMOR_CREATE_FBO_NO_FBO
-         && pixmap_priv->fbo && pixmap_priv->fbo->tex)
-        || (flag == 0 && pixmap_priv->fbo && pixmap_priv->fbo->fb))
+         && pixmap_priv->fbo && pixmap_priv->fbo->tex))
         return 0;
 
     if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP)
commit 47b868492c7ff0909ff71e3ee1aaa79daaade513
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Feb 5 12:34:41 2015 -0800

    glamor: Simplify some temp pixmap extents calculations.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

diff --git a/glamor/glamor_largepixmap.c b/glamor/glamor_largepixmap.c
index da3fb61..cbfd033 100644
--- a/glamor/glamor_largepixmap.c
+++ b/glamor/glamor_largepixmap.c
@@ -755,7 +755,6 @@ glamor_merge_clipped_regions(PixmapPtr pixmap,
                              glamor_pixmap_clipped_regions *clipped_regions,
                              int *n_regions, int *need_clean_fbo)
 {
-    BoxPtr temp_extent;
     BoxRec temp_box, copy_box;
     RegionPtr temp_region;
     glamor_pixmap_private *temp_priv;
@@ -779,9 +778,8 @@ glamor_merge_clipped_regions(PixmapPtr pixmap,
     RegionValidate(temp_region, &overlap);
     DEBUGF("temp region: \n");
     DEBUGRegionPrint(temp_region);
-    temp_extent = RegionExtents(temp_region);
 
-    temp_box = *temp_extent;
+    temp_box = *RegionExtents(temp_region);
 
     DEBUGF("need copy region: \n");
     DEBUGF("%d %d %d %d \n", temp_box.x1, temp_box.y1, temp_box.x2,
@@ -801,16 +799,16 @@ glamor_merge_clipped_regions(PixmapPtr pixmap,
     assert(glamor_pixmap_priv_is_small(temp_priv));
 
     priv->box = temp_box;
-    if (temp_extent->x1 >= 0 && temp_extent->x2 <= pixmap_width
-        && temp_extent->y1 >= 0 && temp_extent->y2 <= pixmap_height) {
+    if (temp_box.x1 >= 0 && temp_box.x2 <= pixmap_width
+        && temp_box.y1 >= 0 && temp_box.y2 <= pixmap_height) {
         int dx, dy;
 
         copy_box.x1 = 0;
         copy_box.y1 = 0;
-        copy_box.x2 = temp_extent->x2 - temp_extent->x1;
-        copy_box.y2 = temp_extent->y2 - temp_extent->y1;
-        dx = temp_extent->x1;
-        dy = temp_extent->y1;
+        copy_box.x2 = temp_box.x2 - temp_box.x1;
+        copy_box.y2 = temp_box.y2 - temp_box.y1;
+        dx = temp_box.x1;
+        dy = temp_box.y1;
         glamor_copy(&pixmap->drawable,
                     &temp_pixmap->drawable,
                     NULL, &copy_box, 1, dx, dy, 0, 0, 0, NULL);
commit bfb6a290afabe492d93ec8024fac6b28f672d7d0
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Feb 5 11:46:32 2015 -0800

    glamor: Drop a dead flag to glamor_create_fbo_array().
    
    v2: Don't forget to set priv->block_w/block_h like the wrapper used
        to.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org> (v1)

diff --git a/glamor/glamor_fbo.c b/glamor/glamor_fbo.c
index e4aa4c6..9da4f45 100644
--- a/glamor/glamor_fbo.c
+++ b/glamor/glamor_fbo.c
@@ -358,20 +358,24 @@ glamor_create_fbo(glamor_screen_private *glamor_priv,
     return fbo;
 }
 
-static glamor_pixmap_fbo *
-_glamor_create_fbo_array(glamor_screen_private *glamor_priv,
+/**
+ * Create storage for the w * h region, using FBOs of the GL's maximum
+ * supported size.
+ */
+glamor_pixmap_fbo *
+glamor_create_fbo_array(glamor_screen_private *glamor_priv,
                          int w, int h, GLenum format, int flag,
                          int block_w, int block_h,
-                         glamor_pixmap_private *pixmap_priv, int has_fbo)
+                         glamor_pixmap_private *priv)
 {
     int block_wcnt;
     int block_hcnt;
     glamor_pixmap_fbo **fbo_array;
     BoxPtr box_array;
     int i, j;
-    glamor_pixmap_private *priv;
 
-    priv = pixmap_priv;
+    priv->block_w = block_w;
+    priv->block_h = block_h;
 
     block_wcnt = (w + block_w - 1) / block_w;
     block_hcnt = (h + block_h - 1) / block_h;
@@ -402,13 +406,10 @@ _glamor_create_fbo_array(glamor_screen_private *glamor_priv,
             fbo_w =
                 box_array[i * block_wcnt + j].x2 - box_array[i * block_wcnt +
                                                              j].x1;
-            if (!has_fbo)
-                fbo_array[i * block_wcnt + j] = glamor_create_fbo(glamor_priv,
-                                                                  fbo_w, fbo_h,
-                                                                  format,
-                                                                  GLAMOR_CREATE_PIXMAP_FIXUP);
-            else
-                fbo_array[i * block_wcnt + j] = priv->fbo;
+            fbo_array[i * block_wcnt + j] = glamor_create_fbo(glamor_priv,
+                                                              fbo_w, fbo_h,
+                                                              format,
+                                                              GLAMOR_CREATE_PIXMAP_FIXUP);
             if (fbo_array[i * block_wcnt + j] == NULL)
                 goto cleanup;
         }
@@ -430,20 +431,6 @@ _glamor_create_fbo_array(glamor_screen_private *glamor_priv,
     return NULL;
 }
 
-/* Create a fbo array to cover the w*h region, by using block_w*block_h
- * block.*/
-glamor_pixmap_fbo *
-glamor_create_fbo_array(glamor_screen_private *glamor_priv,
-                        int w, int h, GLenum format, int flag,
-                        int block_w, int block_h,
-                        glamor_pixmap_private *pixmap_priv)
-{
-    pixmap_priv->block_w = block_w;
-    pixmap_priv->block_h = block_h;
-    return _glamor_create_fbo_array(glamor_priv, w, h, format, flag,
-                                    block_w, block_h, pixmap_priv, 0);
-}
-
 glamor_pixmap_fbo *
 glamor_pixmap_detach_fbo(glamor_pixmap_private *pixmap_priv)
 {
commit fe3fedf280596c2c2e69dddd30bb9ff17dbe611e
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Feb 5 11:33:54 2015 -0800

    glamor: Drop dead GLAMOR_FBO_DOWNLOADED flag.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index a9b94f6..a8732c0 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -314,11 +314,6 @@ enum glamor_fbo_state {
      * point at anything.
      */
     GLAMOR_FBO_NORMAL,
-    /**
-     * The FBO is present and can be accessed as a linear memory
-     * mapping through devPrivate.ptr.
-     */
-    GLAMOR_FBO_DOWNLOADED,
 };
 
 typedef struct glamor_pixmap_fbo {
diff --git a/glamor/glamor_utils.h b/glamor/glamor_utils.h
index 66c3492..cef62c5 100644
--- a/glamor/glamor_utils.h
+++ b/glamor/glamor_utils.h
@@ -758,7 +758,6 @@ glamor_translate_boxes(BoxPtr boxes, int nbox, int dx, int dy)
 
 #define GLAMOR_PIXMAP_PRIV_IS_PICTURE(pixmap_priv) (pixmap_priv && pixmap_priv->is_picture == 1)
 #define GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv)    (pixmap_priv && pixmap_priv->gl_fbo == GLAMOR_FBO_NORMAL)
-#define GLAMOR_PIXMAP_PRIV_HAS_FBO_DOWNLOADED(pixmap_priv)    (pixmap_priv && (pixmap_priv->gl_fbo == GLAMOR_FBO_DOWNLOADED))
 
 /**
  * Borrow from uxa.
commit 447274094147f31025700a2ff6f94e3b0c96fa17
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Feb 5 11:20:50 2015 -0800

    glamor: Move doxygen for private structs into the structs.
    
    This should hopefully keep the comments more up to date with the
    structure comments.  While I'm here, I've reworded a few of them to be
    more accurate, and dropped a bunch of stale comments.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index 57aa445..a9b94f6 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -321,96 +321,26 @@ enum glamor_fbo_state {
     GLAMOR_FBO_DOWNLOADED,
 };
 
-/* glamor_pixmap_fbo:
- * @list:    to be used to link to the cache pool list.
- * @expire:  when push to cache pool list, set a expire count.
- * 	     will be freed when glamor_priv->tick is equal or
- * 	     larger than this expire count in block handler.
- * @tex:     attached texture.
- * @fb:      attached fbo.
- * @width:   width of this fbo.
- * @height:  height of this fbo.
- * @external set when the texture was not created by glamor
- * @format:  internal format of this fbo's texture.
- * @type:    internal type of this fbo's texture.
- * @glamor_priv: point to glamor private data.
- */
 typedef struct glamor_pixmap_fbo {
-    struct xorg_list list;
+    struct xorg_list list; /**< linked list pointers when in the fbo cache */
+    /** glamor_priv->tick number when this FBO will be expired from the cache. */
     unsigned int expire;
-    GLuint tex;
-    GLuint fb;
-    int width;
-    int height;
+    GLuint tex; /**< GL texture name */
+    GLuint fb; /**< GL FBO name */
+    int width; /**< width in pixels */
+    int height; /**< height in pixels */
+    /**
+     * Flag for when texture contents might be shared with a
+     * non-glamor user.
+     *
+     * This is used to avoid putting textures used by other clients
+     * into the FBO cache.
+     */
     Bool external;
-    GLenum format;
-    GLenum type;
+    GLenum format; /**< GL format used to create the texture. */
+    GLenum type; /**< GL type used to create the texture. */
 } glamor_pixmap_fbo;
 
-/*
- * glamor_pixmap_private - glamor pixmap's private structure.
- * @is_picture: The drawable is attached to a picture.
- * @pict_format: the corresponding picture's format.
- * @pixmap: The corresponding pixmap's pointer.
- * @box: current fbo's coords in the whole pixmap.
- * @block_w: block width of this large pixmap.
- * @block_h: block height of this large pixmap.
- * @block_wcnt: block count in one block row.
- * @block_hcnt: block count in one block column.
- * @nbox: total block count.
- * @box_array: contains each block's corresponding box.
- * @fbo_array: contains each block's fbo pointer.
- *
- * For GLAMOR_TEXTURE_LARGE, nbox should larger than 1.
- * And the box and fbo will both have nbox elements.
- * and box[i] store the relatively coords in this pixmap
- * of the fbo[i]. The reason why use boxes not region to
- * represent this structure is we may need to use overlapped
- * boxes for one pixmap for some special reason.
- *
- * pixmap
- * ******************
- * *  fbo0 * fbo1   *
- * *       *        *
- * ******************
- * *  fbo2 * fbo3   *
- * *       *        *
- * ******************
- *
- * Let's assume the texture has size of 1024x1024
- * box[0] = {0,0,1024,1024}
- * box[1] = {1024,0,2048,2048}
- * ...
- *
- * For GLAMOR_TEXTURE_ATLAS nbox should be 1. And box
- * and fbo both has one elements, and the box store
- * the relatively coords in the fbo of this pixmap:
- *
- * fbo
- * ******************
- * *   pixmap       *
- * *   *********    *
- * *   *       *    *
- * *   *********    *
- * *                *
- * ******************
- *
- * Assume the pixmap is at the (100,100) relatively to
- * the fbo's origin.
- * box[0]={100, 100, 1124, 1124};
- *
- * Considering large pixmap is not a normal case, to keep
- * it simple, I designe it as the following way.
- * When deal with a large pixmap, it split the working
- * rectangle into serval boxes, and each box fit into a
- * corresponding fbo. And then the rendering function will
- * loop from the left-top box to the right-bottom box,
- * each time, we will set current box and current fbo
- * to the box and fbo elements. Thus the inner routines
- * can handle it as normal, only the coords calculation need
- * to aware of it's large pixmap.
- **/
-
 typedef struct glamor_pixmap_clipped_regions {
     int block_idx;
     RegionPtr region;
@@ -425,8 +355,10 @@ typedef struct glamor_pixmap_private {
      * that data on glamor_finish_access().
      */
     glamor_access_t map_access;
+    /** Set if the pixmap is currenty attached to a Picture. */
     unsigned char is_picture:1;
     glamor_pixmap_fbo *fbo;
+    /** current fbo's coords in the whole pixmap. */
     BoxRec box;
     int drm_stride;
     PicturePtr picture;
@@ -436,11 +368,40 @@ typedef struct glamor_pixmap_private {
 #if GLAMOR_HAS_GBM
     EGLImageKHR image;
 #endif
+    /** block width of this large pixmap. */
     int block_w;
+    /** block height of this large pixmap. */
     int block_h;
+
+    /** block_wcnt: block count in one block row. */
     int block_wcnt;
+    /** block_hcnt: block count in one block column. */
     int block_hcnt;
+
+    /**
+     * The list of boxes for the bounds of the FBOs making up the
+     * pixmap.
+     *
+     * For a 2048x2048 pixmap with GL FBO size limits of 1024x1024:
+     *
+     * ******************
+     * *  fbo0 * fbo1   *
+     * *       *        *
+     * ******************
+     * *  fbo2 * fbo3   *
+     * *       *        *
+     * ******************
+     *
+     * box[0] = {0,0,1024,1024}
+     * box[1] = {1024,0,2048,2048}
+     * ...
+     */
     BoxPtr box_array;
+
+    /**
+     * Array of fbo structs containing the actual GL texture/fbo
+     * names.
+     */
     glamor_pixmap_fbo **fbo_array;
 } glamor_pixmap_private;
 
@@ -561,19 +522,19 @@ glamor_pixmap_hcnt(glamor_pixmap_private *priv)
     for (y = 0; y < glamor_pixmap_hcnt(priv); y++)      \
         for (x = 0; x < glamor_pixmap_wcnt(priv); x++)
 
-/*
- * Pixmap dynamic status, used by dynamic upload feature.
- *
- * GLAMOR_NONE:  initial status, don't need to do anything.
- * GLAMOR_UPLOAD_PENDING: marked as need to be uploaded to gl texture.
- * GLAMOR_UPLOAD_DONE: the pixmap has been uploaded successfully.
- * GLAMOR_UPLOAD_FAILED: fail to upload the pixmap.
- *
- * */
+/**
+ * Pixmap upload status, used by glamor_render.c's support for
+ * temporarily uploading pixmaps to GL textures to get a Composite
+ * operation done.
+ */
 typedef enum glamor_pixmap_status {
+    /** initial status, don't need to do anything. */
     GLAMOR_NONE,
+    /** marked as need to be uploaded to gl texture. */
     GLAMOR_UPLOAD_PENDING,
+    /** the pixmap has been uploaded successfully. */
     GLAMOR_UPLOAD_DONE,
+    /** fail to upload the pixmap. */
     GLAMOR_UPLOAD_FAILED
 } glamor_pixmap_status_t;
 
commit 33d6384b29db1b28a9d1a035dc7cc82da8f33c99
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Feb 5 11:18:24 2015 -0800

    glamor: Drop the dead "PBO" field in an FBO cache struct.
    
    PBOs are only used at the whole pixmap level.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

diff --git a/glamor/glamor_fbo.c b/glamor/glamor_fbo.c
index abb7284..e4aa4c6 100644
--- a/glamor/glamor_fbo.c
+++ b/glamor/glamor_fbo.c
@@ -121,8 +121,6 @@ glamor_purge_fbo(glamor_screen_private *glamor_priv,
         glDeleteFramebuffers(1, &fbo->fb);
     if (fbo->tex)
         glDeleteTextures(1, &fbo->tex);
-    if (fbo->pbo)
-        glDeleteBuffers(1, &fbo->pbo);
 
     free(fbo);
 }
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index d72c9bc..57aa445 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -328,7 +328,6 @@ enum glamor_fbo_state {
  * 	     larger than this expire count in block handler.
  * @tex:     attached texture.
  * @fb:      attached fbo.
- * @pbo:     attached pbo.
  * @width:   width of this fbo.
  * @height:  height of this fbo.
  * @external set when the texture was not created by glamor
@@ -341,7 +340,6 @@ typedef struct glamor_pixmap_fbo {
     unsigned int expire;
     GLuint tex;
     GLuint fb;
-    GLuint pbo;
     int width;
     int height;
     Bool external;
commit 1734aa285663d83070e6313bb976f976aa2bea4c
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Feb 4 18:07:06 2015 -0800

    glamor: Remove dead gl_tex flag in the fbo struct.
    
    This used to be used in the old copy_area path.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

diff --git a/glamor/glamor_fbo.c b/glamor/glamor_fbo.c
index 6017f5e..abb7284 100644
--- a/glamor/glamor_fbo.c
+++ b/glamor/glamor_fbo.c
@@ -479,12 +479,6 @@ glamor_pixmap_attach_fbo(PixmapPtr pixmap, glamor_pixmap_fbo *fbo)
     case GLAMOR_TEXTURE_ONLY:
     case GLAMOR_TEXTURE_DRM:
         pixmap_priv->gl_fbo = GLAMOR_FBO_NORMAL;
-        if (fbo->tex != 0)
-            pixmap_priv->gl_tex = 1;
-        else {
-            /* XXX For the Xephyr only, may be broken now. */
-            pixmap_priv->gl_tex = 0;
-        }
         pixmap->devPrivate.ptr = NULL;
     default:
         break;
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index 90489a2..d72c9bc 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -351,7 +351,6 @@ typedef struct glamor_pixmap_fbo {
 
 /*
  * glamor_pixmap_private - glamor pixmap's private structure.
- * @gl_tex:  The pixmap is in a gl texture originally.
  * @is_picture: The drawable is attached to a picture.
  * @pict_format: the corresponding picture's format.
  * @pixmap: The corresponding pixmap's pointer.
@@ -429,7 +428,6 @@ typedef struct glamor_pixmap_private {
      */
     glamor_access_t map_access;
     unsigned char is_picture:1;
-    unsigned char gl_tex:1;
     glamor_pixmap_fbo *fbo;
     BoxRec box;
     int drm_stride;
commit 82d23fc7290a2986efbc2982eeaa0de0ad5ad0d1
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Feb 4 18:02:34 2015 -0800

    glamor: Propagate the fact that pbo_valid is never set.
    
    The code to set it was deleted in keithp's big rewrite.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

diff --git a/glamor/glamor_pixmap.c b/glamor/glamor_pixmap.c
index 4e87371..f2bf223 100644
--- a/glamor/glamor_pixmap.c
+++ b/glamor/glamor_pixmap.c
@@ -1047,27 +1047,13 @@ glamor_upload_sub_pixmap_to_texture(PixmapPtr pixmap, int x, int y, int w,
 enum glamor_pixmap_status
 glamor_upload_pixmap_to_texture(PixmapPtr pixmap)
 {
-    glamor_pixmap_private *pixmap_priv;
-    void *data;
-    int pbo;
     int ret;
 
-    pixmap_priv = glamor_get_pixmap_private(pixmap);
-
-    if ((pixmap_priv->fbo)
-        && (pixmap_priv->fbo->pbo_valid)) {
-        data = NULL;
-        pbo = pixmap_priv->fbo->pbo;
-    }
-    else {
-        data = pixmap->devPrivate.ptr;
-        pbo = 0;
-    }
-
     if (glamor_upload_sub_pixmap_to_texture(pixmap, 0, 0,
                                             pixmap->drawable.width,
                                             pixmap->drawable.height,
-                                            pixmap->devKind, data, pbo))
+                                            pixmap->devKind,
+                                            pixmap->devPrivate.ptr, 0))
         ret = GLAMOR_UPLOAD_DONE;
     else
         ret = GLAMOR_UPLOAD_FAILED;
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index 3e666b4..90489a2 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -326,7 +326,6 @@ enum glamor_fbo_state {
  * @expire:  when push to cache pool list, set a expire count.
  * 	     will be freed when glamor_priv->tick is equal or
  * 	     larger than this expire count in block handler.
- * @pbo_valid: The pbo has a valid copy of the pixmap's data.
  * @tex:     attached texture.
  * @fb:      attached fbo.
  * @pbo:     attached pbo.
@@ -340,7 +339,6 @@ enum glamor_fbo_state {
 typedef struct glamor_pixmap_fbo {
     struct xorg_list list;
     unsigned int expire;
-    unsigned char pbo_valid;
     GLuint tex;
     GLuint fb;
     GLuint pbo;
commit 0e3f1252dacdc3194a99a2d090b5c13f070f8799
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Jun 19 18:40:47 2015 -0700

    glamor: Avoid using GL_QUADS on VC4.
    
    Improves text rendering from about 284k glyphs per second to 320k
    glyphs per second.  There's no GL extension for probing this, because
    of the philosophy of "Don't expose whether things are really in
    hardware or not."
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/glamor/glamor.c b/glamor/glamor.c
index fbb1d85..525249c 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -531,6 +531,15 @@ glamor_init(ScreenPtr screen, unsigned int flags)
         epoxy_gl_version() >= 30 ||
         epoxy_has_gl_extension("GL_NV_pack_subimage");
 
+    glamor_priv->use_quads = (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP);
+    /* Driver-specific hack: Avoid using GL_QUADS on VC4, where
+     * they'll be emulated more expensively than we can with our
+     * cached IB.
+     */
+    if (strstr((char *)glGetString(GL_VENDOR), "Broadcom") &&
+        strstr((char *)glGetString(GL_RENDERER), "VC4"))
+        glamor_priv->use_quads = FALSE;
+
     glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &glamor_priv->max_fbo_size);
     glGetIntegerv(GL_MAX_TEXTURE_SIZE, &glamor_priv->max_fbo_size);
     glGetIntegerv(GL_MAX_VIEWPORT_DIMS, max_viewport_size);
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index 681895f..3e666b4 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -203,6 +203,7 @@ typedef struct glamor_screen_private {
     Bool has_pack_subimage;
     Bool has_unpack_subimage;
     Bool has_rw_pbo;
+    Bool use_quads;
     int max_fbo_size;
 
     struct xorg_list
diff --git a/glamor/glamor_utils.h b/glamor/glamor_utils.h
index 73cda9c..66c3492 100644
--- a/glamor/glamor_utils.h
+++ b/glamor/glamor_utils.h
@@ -1400,7 +1400,7 @@ glamor_make_current(glamor_screen_private *glamor_priv)
 static inline void
 glamor_glDrawArrays_GL_QUADS(glamor_screen_private *glamor_priv, unsigned count)
 {
-    if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
+    if (glamor_priv->use_quads) {
         glDrawArrays(GL_QUADS, 0, count * 4);
     } else {
         glamor_gldrawarrays_quads_using_indices(glamor_priv, count);
commit f47e3f539568d19e22d10d7dd4ec09c7d570e716
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Jun 19 18:36:28 2015 -0700

    glamor: Use proper Bools for some boolean values.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index 17f8253..681895f 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -194,16 +194,16 @@ typedef struct glamor_screen_private {
     unsigned int tick;
     enum glamor_gl_flavor gl_flavor;
     int glsl_version;
-    int has_pack_invert;
-    int has_fbo_blit;
-    int has_map_buffer_range;
-    int has_buffer_storage;
-    int has_khr_debug;
-    int has_nv_texture_barrier;
-    int has_pack_subimage;
-    int has_unpack_subimage;
+    Bool has_pack_invert;
+    Bool has_fbo_blit;
+    Bool has_map_buffer_range;
+    Bool has_buffer_storage;
+    Bool has_khr_debug;
+    Bool has_nv_texture_barrier;
+    Bool has_pack_subimage;
+    Bool has_unpack_subimage;
+    Bool has_rw_pbo;
     int max_fbo_size;
-    int has_rw_pbo;
 
     struct xorg_list
         fbo_cache[CACHE_FORMAT_COUNT][CACHE_BUCKET_WCOUNT][CACHE_BUCKET_HCOUNT];
commit 4001a7465e6fb27fc82fa20ea5a65283d33a5e2e
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Jun 19 16:56:35 2015 -0700

    glamor: Provide a fallback path for using an index buffer to do quads.
    
    Improves x11perf -aa10text performance by 1377.59% +/- 23.8198% (n=93)
    on Intel with GLES2.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/glamor/glamor.c b/glamor/glamor.c
index 935fb74..fbb1d85 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -274,6 +274,68 @@ glamor_set_debug_level(int *debug_level)
 
 int glamor_debug_level;
 
+void
+glamor_gldrawarrays_quads_using_indices(glamor_screen_private *glamor_priv,
+                                        unsigned count)
+{
+    unsigned i;
+
+    /* For a single quad, don't bother with an index buffer. */
+    if (count ==  1)
+        goto fallback;
+
+    if (glamor_priv->ib_size < count) {
+        /* Basic GLES2 doesn't have any way to map buffer objects for
+         * writing, but it's long past time for drivers to have
+         * MapBufferRange.
+         */
+        if (!glamor_priv->has_map_buffer_range)
+            goto fallback;
+
+        /* Lazy create the buffer name, and only bind it once since
+         * none of the glamor code binds it to anything else.
+         */
+        if (!glamor_priv->ib) {
+            glGenBuffers(1, &glamor_priv->ib);
+            glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glamor_priv->ib);
+        }
+
+        /* For now, only support GL_UNSIGNED_SHORTs. */
+        if (count > ((1 << 16) - 1) / 4) {
+            goto fallback;
+        } else {
+            uint16_t *data;
+            size_t size = count * 6 * sizeof(GLushort);
+
+            glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, NULL, GL_STATIC_DRAW);
+            data = glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER,
+                                    0, size,
+                                    GL_MAP_WRITE_BIT |
+                                    GL_MAP_INVALIDATE_BUFFER_BIT);
+            for (i = 0; i < count; i++) {
+                data[i * 6 + 0] = i * 4 + 0;
+                data[i * 6 + 1] = i * 4 + 1;
+                data[i * 6 + 2] = i * 4 + 2;
+                data[i * 6 + 3] = i * 4 + 0;
+                data[i * 6 + 4] = i * 4 + 2;
+                data[i * 6 + 5] = i * 4 + 3;
+            }
+            glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
+
+            glamor_priv->ib_size = count;
+            glamor_priv->ib_type = GL_UNSIGNED_SHORT;
+        }
+    }
+
+    glDrawElements(GL_TRIANGLES, count * 6, glamor_priv->ib_type, NULL);
+    return;
+
+fallback:
+    for (i = 0; i < count; i++)
+        glDrawArrays(GL_TRIANGLE_FAN, i * 4, 4);
+}
+
+
 /**
  * Creates any pixmaps used internally by glamor, since those can't be
  * allocated at ScreenInit time.
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index c80df22..17f8253 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -261,6 +261,14 @@ typedef struct glamor_screen_private {
      */
     char *vb;
     int vb_stride;
+
+    /** Cached index buffer for translating GL_QUADS to triangles. */
+    GLuint ib;
+    /** Index buffer type: GL_UNSIGNED_SHORT or GL_UNSIGNED_INT */
+    GLenum ib_type;
+    /** Number of quads the index buffer has indices for. */
+    unsigned ib_size;
+
     Bool has_source_coords, has_mask_coords;
     int render_nr_quads;
     glamor_composite_shader composite_shader[SHADER_SOURCE_COUNT]
@@ -643,6 +651,9 @@ glamor_pixmap_fbo *glamor_create_fbo_array(glamor_screen_private *glamor_priv,
                                            int flag, int block_w, int block_h,
                                            glamor_pixmap_private *);
 
+void glamor_gldrawarrays_quads_using_indices(glamor_screen_private *glamor_priv,
+                                             unsigned count);
+
 /* glamor_core.c */
 void glamor_init_finish_access_shaders(ScreenPtr screen);
 
diff --git a/glamor/glamor_utils.h b/glamor/glamor_utils.h
index 0927ffb..73cda9c 100644
--- a/glamor/glamor_utils.h
+++ b/glamor/glamor_utils.h
@@ -1403,9 +1403,7 @@ glamor_glDrawArrays_GL_QUADS(glamor_screen_private *glamor_priv, unsigned count)
     if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
         glDrawArrays(GL_QUADS, 0, count * 4);
     } else {
-        unsigned i;
-        for (i = 0; i < count; i++)
-            glDrawArrays(GL_TRIANGLE_FAN, i * 4, 4);
+        glamor_gldrawarrays_quads_using_indices(glamor_priv, count);
     }
 }
 
commit e8fc929d4a140666420a64d592371f5d3eb10cca
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Jun 19 17:26:46 2015 -0700

    glamor: Use GL_EXT_map_buffer_range if present.
    
    We were only looking for the desktop GL version of the extension, so
    GLES2 missed out.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/glamor/glamor.c b/glamor/glamor.c
index 0378388..935fb74 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -454,7 +454,8 @@ glamor_init(ScreenPtr screen, unsigned int flags)
     glamor_priv->has_fbo_blit =
         epoxy_has_gl_extension("GL_EXT_framebuffer_blit");
     glamor_priv->has_map_buffer_range =
-        epoxy_has_gl_extension("GL_ARB_map_buffer_range");
+        epoxy_has_gl_extension("GL_ARB_map_buffer_range") ||
+        epoxy_has_gl_extension("GL_EXT_map_buffer_range");
     glamor_priv->has_buffer_storage =
         epoxy_has_gl_extension("GL_ARB_buffer_storage");
     glamor_priv->has_nv_texture_barrier =
commit 4fc4cde0ce7d1a35bab3b3bbd787d688cd415d78
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Jun 19 16:34:55 2015 -0700

    glamor: Use the normal GL_QUADS drawing helper in the render code.
    
    We use this for all of our other performance-sensitive rendering, too.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/glamor/glamor.c b/glamor/glamor.c
index a951cec..0378388 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -554,7 +554,6 @@ glamor_init(ScreenPtr screen, unsigned int flags)
 
     glamor_priv->saved_procs.destroy_picture = ps->DestroyPicture;
     ps->DestroyPicture = glamor_destroy_picture;
-    glamor_init_composite_shaders(screen);
 
     glamor_priv->saved_procs.set_window_pixmap = screen->SetWindowPixmap;
     screen->SetWindowPixmap = glamor_set_window_pixmap;
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index 438d1e9..c80df22 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -248,8 +248,8 @@ typedef struct glamor_screen_private {
     int                         glyph_max_dim;
     char                        *glyph_defines;
 
-    /* vertext/elment_index buffer object for render */
-    GLuint vbo, ebo;
+    /** Vertex buffer for all GPU rendering. */
+    GLuint vbo;
     /** Next offset within the VBO that glamor_get_vbo_space() will use. */
     int vbo_offset;
     int vbo_size;
@@ -262,7 +262,7 @@ typedef struct glamor_screen_private {
     char *vb;
     int vb_stride;
     Bool has_source_coords, has_mask_coords;
-    int render_nr_verts;
+    int render_nr_quads;
     glamor_composite_shader composite_shader[SHADER_SOURCE_COUNT]
         [SHADER_MASK_COUNT]
         [SHADER_IN_COUNT];
@@ -701,7 +701,6 @@ void glamor_composite(CARD8 op,
                       INT16 yMask,
                       INT16 xDst, INT16 yDst, CARD16 width, CARD16 height);
 
-void glamor_init_composite_shaders(ScreenPtr screen);
 void glamor_composite_rects(CARD8 op,
                             PicturePtr pDst,
                             xRenderColor *color, int nRect, xRectangle *rects);
diff --git a/glamor/glamor_render.c b/glamor/glamor_render.c
index 1849cce..4a82534 100644
--- a/glamor/glamor_render.c
+++ b/glamor/glamor_render.c
@@ -379,41 +379,6 @@ glamor_lookup_composite_shader(ScreenPtr screen, struct
     return shader;
 }
 
-static void
-glamor_init_eb(unsigned short *eb, int vert_cnt)
-{
-    int i, j;
-
-    for (i = 0, j = 0; j < vert_cnt; i += 6, j += 4) {
-        eb[i] = j;
-        eb[i + 1] = j + 1;
-        eb[i + 2] = j + 2;
-        eb[i + 3] = j;
-        eb[i + 4] = j + 2;
-        eb[i + 5] = j + 3;
-    }
-}
-
-void
-glamor_init_composite_shaders(ScreenPtr screen)
-{
-    glamor_screen_private *glamor_priv;
-    unsigned short *eb;
-    int eb_size;
-
-    glamor_priv = glamor_get_screen_private(screen);
-    glamor_make_current(glamor_priv);
-    glGenBuffers(1, &glamor_priv->ebo);
-    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glamor_priv->ebo);
-
-    eb_size = GLAMOR_COMPOSITE_VBO_VERT_CNT * sizeof(short) * 2;
-
-    eb = XNFalloc(eb_size);
-    glamor_init_eb(eb, GLAMOR_COMPOSITE_VBO_VERT_CNT);
-    glBufferData(GL_ELEMENT_ARRAY_BUFFER, eb_size, eb, GL_STATIC_DRAW);
-    free(eb);
-}
-
 static Bool
 glamor_set_composite_op(ScreenPtr screen,
                         CARD8 op, struct blendinfo *op_info_result,
@@ -647,7 +612,7 @@ glamor_setup_composite_vbo(ScreenPtr screen, int n_verts)
     char *vbo_offset;
     float *vb;
 
-    glamor_priv->render_nr_verts = 0;
+    glamor_priv->render_nr_quads = 0;
     glamor_priv->vb_stride = 2 * sizeof(float);
     if (glamor_priv->has_source_coords)
         glamor_priv->vb_stride += 2 * sizeof(float);
@@ -689,17 +654,10 @@ glamor_flush_composite_rects(ScreenPtr screen)
 
     glamor_make_current(glamor_priv);
 
-    if (!glamor_priv->render_nr_verts)
+    if (!glamor_priv->render_nr_quads)
         return;
 
-    if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
-        glDrawRangeElements(GL_TRIANGLES, 0, glamor_priv->render_nr_verts,
-                            (glamor_priv->render_nr_verts * 3) / 2,
-                            GL_UNSIGNED_SHORT, NULL);
-    } else {
-        glDrawElements(GL_TRIANGLES, (glamor_priv->render_nr_verts * 3) / 2,
-                       GL_UNSIGNED_SHORT, NULL);
-    }
+    glamor_glDrawArrays_GL_QUADS(glamor_priv, glamor_priv->render_nr_quads);
 }
 
 int pict_format_combine_tab[][3] = {
@@ -1249,7 +1207,7 @@ glamor_composite_with_shader(CARD8 op,
                                                      vertices, vb_stride);
                 vertices += 2;
             }
-            glamor_priv->render_nr_verts += 4;
+            glamor_priv->render_nr_quads++;
             rects++;
 
             /* We've incremented by one of our 4 verts, now do the other 3. */
commit c5e6fffbdd88ad714454b9de1ac1c3eb9f6bf196
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Jun 19 17:05:28 2015 -0700

    glamor: Drop CloseScreen-time GL resource cleanup code.
    
    These will all be freed when the context is freed.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/glamor/glamor.c b/glamor/glamor.c
index 71ca4f4..a951cec 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -585,13 +585,8 @@ glamor_release_screen_priv(ScreenPtr screen)
     glamor_screen_private *glamor_priv;
 
     glamor_priv = glamor_get_screen_private(screen);
-    glamor_fini_composite_shaders(screen);
     glamor_fini_vbo(screen);
     glamor_fini_pixmap_fbo(screen);
-    glamor_fini_finish_access_shaders(screen);
-#ifdef GLAMOR_GRADIENT_SHADER
-    glamor_fini_gradient_shader(screen);
-#endif
     glamor_pixmap_fini(screen);
     free(glamor_priv);
 
diff --git a/glamor/glamor_core.c b/glamor/glamor_core.c
index 965024e..4f3526c 100644
--- a/glamor/glamor_core.c
+++ b/glamor/glamor_core.c
@@ -283,17 +283,6 @@ glamor_init_finish_access_shaders(ScreenPtr screen)
     glUniform1i(glamor_priv->finish_access_swap_rb[1], 0);
 }
 
-void
-glamor_fini_finish_access_shaders(ScreenPtr screen)
-{
-    glamor_screen_private *glamor_priv;
-
-    glamor_priv = glamor_get_screen_private(screen);
-    glamor_make_current(glamor_priv);
-    glDeleteProgram(glamor_priv->finish_access_prog[0]);
-    glDeleteProgram(glamor_priv->finish_access_prog[1]);
-}
-
 GCOps glamor_gc_ops = {
     .FillSpans = glamor_fill_spans,
     .SetSpans = glamor_set_spans,
diff --git a/glamor/glamor_gradient.c b/glamor/glamor_gradient.c
index d34131d..30c29f6 100644
--- a/glamor/glamor_gradient.c
+++ b/glamor/glamor_gradient.c
@@ -582,27 +582,6 @@ glamor_init_gradient_shader(ScreenPtr screen)
     _glamor_create_radial_gradient_program(screen, RADIAL_LARGE_STOPS, 0);
 }
 
-void
-glamor_fini_gradient_shader(ScreenPtr screen)
-{
-    glamor_screen_private *glamor_priv;
-    int i = 0;
-
-    glamor_priv = glamor_get_screen_private(screen);
-    glamor_make_current(glamor_priv);
-
-    for (i = 0; i < 3; i++) {
-        /* Linear Gradient */
-        if (glamor_priv->gradient_prog[SHADER_GRADIENT_LINEAR][i])
-            glDeleteProgram(glamor_priv->gradient_prog
-                            [SHADER_GRADIENT_LINEAR][i]);
-
-        if (glamor_priv->gradient_prog[SHADER_GRADIENT_RADIAL][i])
-            glDeleteProgram(glamor_priv->gradient_prog
-                            [SHADER_GRADIENT_RADIAL][i]);
-    }
-}
-
 static void
 _glamor_gradient_convert_trans_matrix(PictTransform *from, float to[3][3],
                                       int width, int height, int normalize)
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index 480d13b..438d1e9 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -645,7 +645,6 @@ glamor_pixmap_fbo *glamor_create_fbo_array(glamor_screen_private *glamor_priv,
 
 /* glamor_core.c */
 void glamor_init_finish_access_shaders(ScreenPtr screen);
-void glamor_fini_finish_access_shaders(ScreenPtr screen);
 
 Bool glamor_get_drawable_location(const DrawablePtr drawable);
 void glamor_get_drawable_deltas(DrawablePtr drawable, PixmapPtr pixmap,
@@ -703,7 +702,6 @@ void glamor_composite(CARD8 op,
                       INT16 xDst, INT16 yDst, CARD16 width, CARD16 height);
 
 void glamor_init_composite_shaders(ScreenPtr screen);
-void glamor_fini_composite_shaders(ScreenPtr screen);
 void glamor_composite_rects(CARD8 op,
                             PicturePtr pDst,
                             xRenderColor *color, int nRect, xRectangle *rects);
@@ -722,7 +720,6 @@ void glamor_trapezoids(CARD8 op,
 
 /* glamor_gradient.c */
 void glamor_init_gradient_shader(ScreenPtr screen);
-void glamor_fini_gradient_shader(ScreenPtr screen);
 PicturePtr glamor_generate_linear_gradient_picture(ScreenPtr screen,
                                                    PicturePtr src_picture,
                                                    int x_source, int y_source,
diff --git a/glamor/glamor_render.c b/glamor/glamor_render.c
index 05eee91..1849cce 100644
--- a/glamor/glamor_render.c
+++ b/glamor/glamor_render.c
@@ -414,27 +414,6 @@ glamor_init_composite_shaders(ScreenPtr screen)
     free(eb);
 }
 
-void
-glamor_fini_composite_shaders(ScreenPtr screen)
-{
-    glamor_screen_private *glamor_priv;
-    glamor_composite_shader *shader;
-    int i, j, k;
-
-    glamor_priv = glamor_get_screen_private(screen);
-    glamor_make_current(glamor_priv);
-    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
-    glDeleteBuffers(1, &glamor_priv->ebo);
-
-    for (i = 0; i < SHADER_SOURCE_COUNT; i++)
-        for (j = 0; j < SHADER_MASK_COUNT; j++)
-            for (k = 0; k < SHADER_IN_COUNT; k++) {
-                shader = &glamor_priv->composite_shader[i][j][k];
-                if (shader->prog)
-                    glDeleteProgram(shader->prog);
-            }
-}
-
 static Bool
 glamor_set_composite_op(ScreenPtr screen,
                         CARD8 op, struct blendinfo *op_info_result,
diff --git a/glamor/glamor_vbo.c b/glamor/glamor_vbo.c
index e906101..d74a005 100644
--- a/glamor/glamor_vbo.c
+++ b/glamor/glamor_vbo.c
@@ -171,7 +171,6 @@ glamor_fini_vbo(ScreenPtr screen)
 
     glamor_make_current(glamor_priv);
 
-    glDeleteBuffers(1, &glamor_priv->vbo);
     if (!glamor_priv->has_map_buffer_range)
         free(glamor_priv->vb);
 }
commit 3d6dcad00d67bff407385ad37c7efde7b73ba719
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Jun 19 19:04:16 2015 -0700

    glamor: Fix text rendering on GLES2.
    
    The GL_QUADS helper takes a number of quads, not a number of vertices.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/glamor/glamor_composite_glyphs.c b/glamor/glamor_composite_glyphs.c
index 1f0d75e..e92f1d9 100644
--- a/glamor/glamor_composite_glyphs.c
+++ b/glamor/glamor_composite_glyphs.c
@@ -256,7 +256,7 @@ glamor_glyphs_flush(CARD8 op, PicturePtr src, PicturePtr dst,
                 if (glamor_glyph_use_130(glamor_priv))
                     glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, nglyph);
                 else
-                    glamor_glDrawArrays_GL_QUADS(glamor_priv, nglyph * 4);
+                    glamor_glDrawArrays_GL_QUADS(glamor_priv, nglyph);
             }
         }
         if (prog->alpha != glamor_program_alpha_ca_first)
commit b4061cf5f76241157b2dc81dec053012075311c0
Author: Peter Harris <pharris at opentext.com>
Date:   Tue May 12 14:19:15 2015 -0400

    Fix border tile origin when background is ParentRelative
    
    According to
    http://www.x.org/releases/X11R7.7/doc/xproto/x11protocol.html#requests:CreateWindow
    "The border tile origin is always the same as the background tile
    origin."
    
    ChangeWindowAttributes goes to some effort to make sure it repaints
    the border tile whenever the background origin may have changed, but
    miPaintWindow was ignoring the background origin.
    
    Found by xts XChangeWindowAttributes-3
    
    Signed-off-by: Peter Harris <pharris at opentext.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/mi/miexpose.c b/mi/miexpose.c
index c4118f1..4124d67 100644
--- a/mi/miexpose.c
+++ b/mi/miexpose.c
@@ -478,14 +478,21 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
     else {
         PixmapPtr pixmap;
 
-        tile_x_off = drawable->x;
-        tile_y_off = drawable->y;
+        fill = pWin->border;
+        solid = pWin->borderIsPixel;
 
         /* servers without pixmaps draw their own borders */
         if (!pScreen->GetWindowPixmap)
             return;
         pixmap = (*pScreen->GetWindowPixmap) ((WindowPtr) drawable);
         drawable = &pixmap->drawable;
+
+        while (pWin->backgroundState == ParentRelative)
+            pWin = pWin->parent;
+
+        tile_x_off = pWin->drawable.x;
+        tile_y_off = pWin->drawable.y;
+
 #ifdef COMPOSITE
         draw_x_off = pixmap->screen_x;
         draw_y_off = pixmap->screen_y;
@@ -495,8 +502,6 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
         draw_x_off = 0;
         draw_y_off = 0;
 #endif
-        fill = pWin->border;
-        solid = pWin->borderIsPixel;
     }
 
     gcval[0].val = GXcopy;
commit 8a8d51358cea782147bb9b5b2e0902b1e47fcf4a
Merge: b22534d 13c7d53
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Jun 29 21:04:53 2015 -0700

    Merge remote-tracking branch 'airlied/for-keithp'

commit b22534d8e653575196180970292eaade33c090a8
Merge: 0a625ad 780a69a
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Jun 29 21:04:11 2015 -0700

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

commit 0a625adeec465d6c7dcdb8622c53157b4e932bb0
Merge: 84128c1 790311c
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Jun 29 21:01:34 2015 -0700

    Merge remote-tracking branch 'anholt/glamor-next'

commit 84128c10bb6d34f78f7a4148b3c640748efe58e1
Merge: 9003a3e 8c86dd5
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Jun 29 20:59:31 2015 -0700

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

commit 13c7d53df8dac45ea2a685826cd45a39bcb51657
Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Mon Jan 26 21:29:23 2015 -0800

    modesetting: Implement page flipping support for Present.
    
    Based on code by Keith Packard, Eric Anholt, and Jason Ekstrand.
    
    v2:
    - Fix double free and flip_count underrun (caught by Mario Kleiner).
    - Don't leak flip_vblank_event on the error_out path (Mario).
    - Use the updated ms_flush_drm_events API (Mario, Ken).
    
    v3: Hack around DPMS shenanigans.  If all monitors are DPMS off, then
        there is no active framebuffer; attempting to pageflip will hit the
        error_undo paths, causing us to drmModeRmFB with no framebuffer,
        which confuses the kernel into doing full modesets and generally
        breaks things.  To avoid this, make ms_present_check_flip check that
        some CRTCs are enabled and DPMS on.  This is an ugly hack that would
        get better with atomic modesetting, or some core Present work.
    
    v4:
    - Don't do pageflipping if CRTCs are rotated (caught by Jason Ekstrand).
    - Make pageflipping optional (Option "PageFlip" in xorg.conf.d), but
      enabled by default.
    
    v5: Initialize num_crtcs_on to 0 (caught by Michel Dänzer).
    
    [airlied: took over]
    v6: merge async flip support from Mario Kleiner
    free sequence after failed vblank queue
    handle unflip while DPMS'ed off (Michel)
    move flip tracking into its own structure, and
    fix up reference counting issues, and add comments.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    Acked-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index ae562a1..8603338 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -123,6 +123,7 @@ typedef enum {
     OPTION_DEVICE_PATH,
     OPTION_SHADOW_FB,
     OPTION_ACCEL_METHOD,
+    OPTION_PAGEFLIP,
 } modesettingOpts;
 
 static const OptionInfoRec Options[] = {
@@ -130,6 +131,7 @@ static const OptionInfoRec Options[] = {
     {OPTION_DEVICE_PATH, "kmsdev", OPTV_STRING, {0}, FALSE},
     {OPTION_SHADOW_FB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE},
     {OPTION_ACCEL_METHOD, "AccelMethod", OPTV_STRING, {0}, FALSE},
+    {OPTION_PAGEFLIP, "PageFlip", OPTV_BOOLEAN, {0}, FALSE},
     {-1, NULL, OPTV_NONE, {0}, FALSE}
 };
 
@@ -820,6 +822,8 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     try_enable_glamor(pScrn);
 
     if (ms->drmmode.glamor) {
+        ms->drmmode.pageflip =
+            xf86ReturnOptValBool(ms->Options, OPTION_PAGEFLIP, TRUE);
     } else {
         Bool prefer_shadow = TRUE;
 
@@ -836,6 +840,8 @@ PreInit(ScrnInfoPtr pScrn, int flags)
                    "ShadowFB: preferred %s, enabled %s\n",
                    prefer_shadow ? "YES" : "NO",
                    ms->drmmode.shadow_enable ? "YES" : "NO");
+
+        ms->drmmode.pageflip = FALSE;
     }
 
     if (drmmode_pre_init(pScrn, &ms->drmmode, pScrn->bitsPerPixel / 8) == FALSE) {
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index 843a105..9ae4966 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -101,6 +101,12 @@ typedef struct _modesettingRec {
 
     drmEventContext event_context;
 
+    /**
+     * Page flipping stuff.
+     *  @{
+     */
+    /** @} */
+
     DamagePtr damage;
     Bool dirty_enabled;
 
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 506ea24..8dbac07 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -51,7 +51,8 @@
 #include "driver.h"
 
 static Bool drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height);
-static int
+
+int
 drmmode_bo_destroy(drmmode_ptr drmmode, drmmode_bo *bo)
 {
     int ret;
@@ -72,7 +73,7 @@ drmmode_bo_destroy(drmmode_ptr drmmode, drmmode_bo *bo)
     return 0;
 }
 
-static uint32_t
+uint32_t
 drmmode_bo_get_pitch(drmmode_bo *bo)
 {
 #ifdef GLAMOR_HAS_GBM
@@ -143,6 +144,35 @@ drmmode_create_bo(drmmode_ptr drmmode, drmmode_bo *bo,
 }
 
 Bool
+drmmode_bo_for_pixmap(drmmode_ptr drmmode, drmmode_bo *bo, PixmapPtr pixmap)
+{
+    ScreenPtr screen = xf86ScrnToScreen(drmmode->scrn);
+    uint16_t pitch;
+    uint32_t size;
+    int fd;
+
+#ifdef GLAMOR_HAS_GBM
+    if (drmmode->glamor) {
+        bo->gbm = glamor_gbm_bo_from_pixmap(screen, pixmap);
+        bo->dumb = NULL;
+        return bo->gbm != NULL;
+    }
+#endif
+
+    fd = glamor_fd_from_pixmap(screen, pixmap, &pitch, &size);
+    if (fd < 0) {
+        xf86DrvMsg(drmmode->scrn->scrnIndex, X_ERROR,
+                   "Failed to get fd for flip to new front.\n");
+        return FALSE;
+    }
+
+    bo->dumb = dumb_get_bo_from_fd(drmmode->fd, fd, pitch, size);
+    close(fd);
+
+    return bo->dumb != NULL;
+}
+
+Bool
 drmmode_SetSlaveBO(PixmapPtr ppix,
                    drmmode_ptr drmmode, int fd_handle, int pitch, int size)
 {
@@ -368,6 +398,7 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
         if (crtc->scrn->pScreen)
             xf86CrtcSetScreenSubpixelOrder(crtc->scrn->pScreen);
 
+        drmmode_crtc->need_modeset = FALSE;
         crtc->funcs->dpms(crtc, DPMSModeOn);
 
         /* go through all the outputs and force DPMS them back on? */
@@ -1003,6 +1034,7 @@ static void
 drmmode_output_dpms(xf86OutputPtr output, int mode)
 {
     drmmode_output_private_ptr drmmode_output = output->driver_private;
+    xf86CrtcPtr crtc = output->crtc;
     drmModeConnectorPtr koutput = drmmode_output->mode_output;
     drmmode_ptr drmmode = drmmode_output->drmmode;
 
@@ -1011,6 +1043,13 @@ drmmode_output_dpms(xf86OutputPtr output, int mode)
 
     drmModeConnectorSetProperty(drmmode->fd, koutput->connector_id,
                                 drmmode_output->dpms_enum_id, mode);
+
+    if (mode == DPMSModeOn && crtc) {
+        drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+        if (drmmode_crtc->need_modeset)
+            drmmode_set_mode_major(crtc, &crtc->mode, crtc->rotation,
+                                   crtc->x, crtc->y);
+    }
     return;
 }
 
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index 85a0ec4..fe363c5 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -46,7 +46,6 @@ typedef struct {
 typedef struct {
     int fd;
     unsigned fb_id;
-    unsigned old_fb_id;
     drmModeFBPtr mode_fb;
     int cpp;
     ScrnInfoPtr scrn;
@@ -63,6 +62,8 @@ typedef struct {
 
     Bool glamor;
     Bool shadow_enable;
+    /** Is Option "PageFlip" enabled? */
+    Bool pageflip;
     void *shadow_fb;
 
     /**
@@ -107,6 +108,8 @@ typedef struct {
     uint32_t msc_prev;
     uint64_t msc_high;
     /** @} */
+
+    Bool need_modeset;
 } drmmode_crtc_private_rec, *drmmode_crtc_private_ptr;
 
 typedef struct {
@@ -141,6 +144,9 @@ extern DevPrivateKeyRec msPixmapPrivateKeyRec;
 
 #define msGetPixmapPriv(drmmode, p) ((msPixmapPrivPtr)dixGetPrivateAddr(&(p)->devPrivates, &(drmmode)->pixmapPrivateKeyRec))
 
+Bool drmmode_bo_for_pixmap(drmmode_ptr drmmode, drmmode_bo *bo, PixmapPtr pixmap);
+int drmmode_bo_destroy(drmmode_ptr drmmode, drmmode_bo *bo);
+uint32_t drmmode_bo_get_pitch(drmmode_bo *bo);
 uint32_t drmmode_bo_get_handle(drmmode_bo *bo);
 Bool drmmode_glamor_handle_new_screen_pixmap(drmmode_ptr drmmode);
 void *drmmode_map_slave_bo(drmmode_ptr drmmode, msPixmapPrivPtr ppriv);
diff --git a/hw/xfree86/drivers/modesetting/present.c b/hw/xfree86/drivers/modesetting/present.c
index 43df148..0905398 100644
--- a/hw/xfree86/drivers/modesetting/present.c
+++ b/hw/xfree86/drivers/modesetting/present.c
@@ -44,6 +44,7 @@
 #include <present.h>
 
 #include "driver.h"
+#include "drmmode_display.h"
 
 #if 0
 #define DebugPresent(x) ErrorF x
@@ -174,8 +175,10 @@ ms_present_queue_vblank(RRCrtcPtr crtc,
         /* If we hit EBUSY, then try to flush events.  If we can't, then
          * this is an error.
          */
-        if (errno != EBUSY || ms_flush_drm_events(screen) < 0)
+        if (errno != EBUSY || ms_flush_drm_events(screen) < 0) {
+	    ms_drm_abort_seq(scrn, seq);
             return BadAlloc;
+        }
     }
     DebugPresent(("\t\tmq %lld seq %u msc %llu (hw msc %u)\n",
                  (long long) event_id, seq, (long long) msc,
@@ -221,6 +224,413 @@ ms_present_flush(WindowPtr window)
 #endif
 }
 
+#ifdef GLAMOR
+
+/*
+ * Event data for an in progress flip.
+ * This contains a pointer to the vblank event,
+ * and information about the flip in progress.
+ * a reference to this is stored in the per-crtc
+ * flips.
+ */
+struct ms_flipdata {
+    ScreenPtr screen;
+    struct ms_present_vblank_event *event;
+    /* number of CRTC events referencing this */
+    int flip_count;
+    uint64_t fe_msc;
+    uint64_t fe_usec;
+    uint32_t old_fb_id;
+};
+
+/*
+ * Per crtc pageflipping infomation,
+ * These are submitted to the queuing code
+ * one of them per crtc per flip.
+ */
+struct ms_crtc_pageflip {
+    Bool on_reference_crtc;
+    /* reference to the ms_flipdata */
+    struct ms_flipdata *flipdata;
+};
+
+/**
+ * Free an ms_crtc_pageflip.
+ *
+ * Drops the reference count on the flipdata.
+ */
+static void
+ms_present_flip_free(struct ms_crtc_pageflip *flip)
+{
+    struct ms_flipdata *flipdata = flip->flipdata;
+
+    free(flip);
+    if (--flipdata->flip_count > 0)
+        return;
+    free(flipdata);
+}
+
+/**
+ * Callback for the DRM event queue when a single flip has completed
+ *
+ * Once the flip has been completed on all pipes, notify the
+ * extension code telling it when that happened
+ */
+static void
+ms_flip_handler(uint64_t msc, uint64_t ust, void *data)
+{
+    struct ms_crtc_pageflip *flip = data;
+    ScreenPtr screen = flip->flipdata->screen;
+    ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+    modesettingPtr ms = modesettingPTR(scrn);
+    struct ms_flipdata *flipdata = flip->flipdata;
+
+    DebugPresent(("\t\tms:fh %lld c %d msc %llu ust %llu\n",
+                  (long long) flipdata->event->event_id,
+                  flipdata->flip_count,
+                  (long long) msc, (long long) ust));
+
+    if (flip->on_reference_crtc) {
+        flipdata->fe_msc = msc;
+        flipdata->fe_usec = ust;
+    }
+
+    if (flipdata->flip_count == 1) {
+        DebugPresent(("\t\tms:fc %lld c %d msc %llu ust %llu\n",
+                      (long long) flipdata->event->event_id,
+                      flipdata->flip_count,
+                      (long long) flipdata->fe_msc, (long long) flipdata->fe_usec));
+
+
+        ms_present_vblank_handler(flipdata->fe_msc,
+                                  flipdata->fe_usec,
+                                  flipdata->event);
+
+        drmModeRmFB(ms->fd, flipdata->old_fb_id);
+    }
+    ms_present_flip_free(flip);
+}
+
+/*
+ * Callback for the DRM queue abort code.  A flip has been aborted.
+ */
+static void
+ms_present_flip_abort(void *data)
+{
+    struct ms_crtc_pageflip *flip = data;
+    struct ms_flipdata *flipdata = flip->flipdata;
+
+    DebugPresent(("\t\tms:fa %lld c %d\n", (long long) flipdata->event->event_id, flipdata->flip_count));
+
+    if (flipdata->flip_count == 1)
+        free(flipdata->event);
+
+    ms_present_flip_free(flip);
+}
+
+static Bool
+queue_flip_on_crtc(ScreenPtr screen, xf86CrtcPtr crtc,
+                   struct ms_flipdata *flipdata,
+                   int ref_crtc_vblank_pipe, uint32_t flags)
+{
+    ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+    modesettingPtr ms = modesettingPTR(scrn);
+    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+    struct ms_crtc_pageflip *flip;
+    uint32_t seq;
+    int err;
+
+    flip = calloc(1, sizeof(struct ms_crtc_pageflip));
+    if (flip == NULL) {
+        xf86DrvMsg(scrn->scrnIndex, X_WARNING,
+                   "flip queue: carrier alloc failed.\n");
+        return FALSE;
+    }
+
+    /* Only the reference crtc will finally deliver its page flip
+     * completion event. All other crtc's events will be discarded.
+     */
+    flip->on_reference_crtc = (drmmode_crtc->vblank_pipe == ref_crtc_vblank_pipe);
+    flip->flipdata = flipdata;
+
+    seq = ms_drm_queue_alloc(crtc, flip, ms_flip_handler, ms_present_flip_abort);
+    if (!seq) {
+        free(flip);
+        return FALSE;
+    }
+
+    DebugPresent(("\t\tms:fq %lld c %d -> %d seq %llu\n",
+                  (long long) flipdata->event->event_id,
+                  flipdata->flip_count, flipdata->flip_count + 1,
+                  (long long) seq));
+
+    /* take a reference on flipdata for use in flip */
+    flipdata->flip_count++;
+
+    while (drmModePageFlip(ms->fd, drmmode_crtc->mode_crtc->crtc_id,
+                           ms->drmmode.fb_id, flags, (void *) (uintptr_t) seq)) {
+        err = errno;
+        /* We may have failed because the event queue was full.  Flush it
+         * and retry.  If there was nothing to flush, then we failed for
+         * some other reason and should just return an error.
+         */
+        if (ms_flush_drm_events(screen) <= 0) {
+            xf86DrvMsg(scrn->scrnIndex, X_WARNING,
+                       "flip queue failed: %s\n", strerror(err));
+            /* Aborting will also decrement flip_count and free(flip). */
+            ms_drm_abort_seq(scrn, seq);
+            return FALSE;
+        }
+
+        /* We flushed some events, so try again. */
+        xf86DrvMsg(scrn->scrnIndex, X_WARNING, "flip queue retry\n");
+    }
+
+    /* The page flip succeded. */
+    return TRUE;
+}
+
+
+static Bool
+ms_do_pageflip(ScreenPtr screen,
+               PixmapPtr new_front,
+               struct ms_present_vblank_event *event,
+               int ref_crtc_vblank_pipe,
+               Bool async)
+{
+    ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+    modesettingPtr ms = modesettingPTR(scrn);
+    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn);
+    drmmode_bo new_front_bo;
+    uint32_t flags;
+    int i;
+    struct ms_flipdata *flipdata;
+    glamor_block_handler(screen);
+
+    new_front_bo.gbm = glamor_gbm_bo_from_pixmap(screen, new_front);
+    new_front_bo.dumb = NULL;
+    if (!new_front_bo.gbm) {
+        xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                   "Failed to get GBM bo for flip to new front.\n");
+        return FALSE;
+    }
+
+    flipdata = calloc(1, sizeof(struct ms_flipdata));
+    if (!flipdata) {
+        drmmode_bo_destroy(&ms->drmmode, &new_front_bo);
+        xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                   "Failed to allocate flipdata.\n");
+        return FALSE;
+    }
+
+    flipdata->event = event;
+    flipdata->screen = screen;
+
+    /*
+     * Take a local reference on flipdata.
+     * if the first flip fails, the sequence abort
+     * code will free the crtc flip data, and drop
+     * it's reference which would cause this to be
+     * freed when we still required it.
+     */
+    flipdata->flip_count++;
+
+    /* Create a new handle for the back buffer */
+    flipdata->old_fb_id = ms->drmmode.fb_id;
+    if (drmModeAddFB(ms->fd, scrn->virtualX, scrn->virtualY,
+                     scrn->depth, scrn->bitsPerPixel,
+                     drmmode_bo_get_pitch(&new_front_bo),
+                     drmmode_bo_get_handle(&new_front_bo), &ms->drmmode.fb_id)) {
+        goto error_out;
+    }
+
+    drmmode_bo_destroy(&ms->drmmode, &new_front_bo);
+
+    flags = DRM_MODE_PAGE_FLIP_EVENT;
+    if (async)
+        flags |= DRM_MODE_PAGE_FLIP_ASYNC;
+
+    /* Queue flips on all enabled CRTCs.
+     *
+     * Note that if/when we get per-CRTC buffers, we'll have to update this.
+     * Right now it assumes a single shared fb across all CRTCs, with the
+     * kernel fixing up the offset of each CRTC as necessary.
+     *
+     * Also, flips queued on disabled or incorrectly configured displays
+     * may never complete; this is a configuration error.
+     */
+    for (i = 0; i < config->num_crtc; i++) {
+        xf86CrtcPtr crtc = config->crtc[i];
+
+        if (!ms_crtc_on(crtc))
+            continue;
+
+        if (!queue_flip_on_crtc(screen, crtc, flipdata,
+                                ref_crtc_vblank_pipe,
+                                flags)) {
+            goto error_undo;
+        }
+    }
+
+    /*
+     * Do we have more than our local reference,
+     * if so and no errors, then drop our local
+     * reference and return now.
+     */
+    if (flipdata->flip_count > 1) {
+        flipdata->flip_count--;
+        return TRUE;
+    }
+
+error_undo:
+
+    /*
+     * Have we just got the local reference?
+     * free the framebuffer if so since nobody successfully
+     * submitted anything
+     */
+    if (flipdata->flip_count == 1) {
+        drmModeRmFB(ms->fd, ms->drmmode.fb_id);
+        ms->drmmode.fb_id = flipdata->old_fb_id;
+    }
+
+error_out:
+    xf86DrvMsg(scrn->scrnIndex, X_WARNING, "Page flip failed: %s\n",
+               strerror(errno));
+    /* if only the local reference - free the structure,
+     * else drop the local reference and return */
+    if (flipdata->flip_count == 1)
+        free(flipdata);
+    else
+        flipdata->flip_count--;
+
+    return FALSE;
+}
+
+/*
+ * Test to see if page flipping is possible on the target crtc
+ */
+static Bool
+ms_present_check_flip(RRCrtcPtr crtc,
+                      WindowPtr window,
+                      PixmapPtr pixmap,
+                      Bool sync_flip)
+{
+    ScreenPtr screen = window->drawable.pScreen;
+    ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+    modesettingPtr ms = modesettingPTR(scrn);
+    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn);
+    int num_crtcs_on = 0;
+    int i;
+
+    if (!ms->drmmode.pageflip)
+        return FALSE;
+
+    if (!scrn->vtSema)
+        return FALSE;
+
+    for (i = 0; i < config->num_crtc; i++) {
+        drmmode_crtc_private_ptr drmmode_crtc = config->crtc[i]->driver_private;
+
+        /* Don't do pageflipping if CRTCs are rotated. */
+        if (drmmode_crtc->rotate_bo.gbm)
+            return FALSE;
+
+        if (ms_crtc_on(config->crtc[i]))
+            num_crtcs_on++;
+    }
+
+    /* We can't do pageflipping if all the CRTCs are off. */
+    if (num_crtcs_on == 0)
+        return FALSE;
+
+    /* Check stride, can't change that on flip */
+    if (pixmap->devKind != drmmode_bo_get_pitch(&ms->drmmode.front_bo))
+        return FALSE;
+
+    /* Make sure there's a bo we can get to */
+    /* XXX: actually do this.  also...is it sufficient?
+     * if (!glamor_get_pixmap_private(pixmap))
+     *     return FALSE;
+     */
+
+    return TRUE;
+}
+
+/*
+ * Queue a flip on 'crtc' to 'pixmap' at 'target_msc'. If 'sync_flip' is true,
+ * then wait for vblank. Otherwise, flip immediately
+ */
+static Bool
+ms_present_flip(RRCrtcPtr crtc,
+                uint64_t event_id,
+                uint64_t target_msc,
+                PixmapPtr pixmap,
+                Bool sync_flip)
+{
+    ScreenPtr screen = crtc->pScreen;
+    ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+    xf86CrtcPtr xf86_crtc = crtc->devPrivate;
+    drmmode_crtc_private_ptr drmmode_crtc = xf86_crtc->driver_private;
+    Bool ret;
+    struct ms_present_vblank_event *event;
+
+    if (!ms_present_check_flip(crtc, screen->root, pixmap, sync_flip))
+        return FALSE;
+
+    event = calloc(1, sizeof(struct ms_present_vblank_event));
+    if (!event)
+        return FALSE;
+
+    event->event_id = event_id;
+    ret = ms_do_pageflip(screen, pixmap, event, drmmode_crtc->vblank_pipe, !sync_flip);
+    if (!ret)
+        xf86DrvMsg(scrn->scrnIndex, X_ERROR, "present flip failed\n");
+
+    return ret;
+}
+
+/*
+ * Queue a flip back to the normal frame buffer
+ */
+static void
+ms_present_unflip(ScreenPtr screen, uint64_t event_id)
+{
+    ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+    PixmapPtr pixmap = screen->GetScreenPixmap(screen);
+    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn);
+    int i;
+    struct ms_present_vblank_event *event;
+
+    event = calloc(1, sizeof(struct ms_present_vblank_event));
+    if (!event)
+        return;
+
+    event->event_id = event_id;
+
+    if (ms_present_check_flip(NULL, screen->root, pixmap, TRUE) &&
+        ms_do_pageflip(screen, pixmap, event, -1, FALSE)) {
+        return;
+    }
+
+    for (i = 0; i < config->num_crtc; i++) {
+        xf86CrtcPtr crtc = config->crtc[i];
+	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+
+	if (!crtc->enabled)
+	    continue;
+
+	if (drmmode_crtc->dpms_mode == DPMSModeOn)
+	    crtc->funcs->set_mode_major(crtc, &crtc->mode, crtc->rotation,
+					crtc->x, crtc->y);
+	else
+	    drmmode_crtc->need_modeset = TRUE;
+    }
+
+    present_event_notify(event_id, 0, 0);
+}
+#endif
+
 static present_screen_info_rec ms_present_screen_info = {
     .version = PRESENT_SCREEN_INFO_VERSION,
 
@@ -231,13 +641,24 @@ static present_screen_info_rec ms_present_screen_info = {
     .flush = ms_present_flush,
 
     .capabilities = PresentCapabilityNone,
-    .check_flip = 0,
-    .flip = 0,
-    .unflip = 0,
+    .check_flip = ms_present_check_flip,
+#ifdef GLAMOR
+    .flip = ms_present_flip,
+    .unflip = ms_present_unflip,
+#endif
 };
 
 Bool
 ms_present_screen_init(ScreenPtr screen)
 {
+    ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+    modesettingPtr ms = modesettingPTR(scrn);
+    uint64_t value;
+    int ret;
+
+    ret = drmGetCap(ms->fd, DRM_CAP_ASYNC_PAGE_FLIP, &value);
+    if (ret == 0 && value == 1)
+        ms_present_screen_info.capabilities |= PresentCapabilityAsync;
+
     return present_screen_init(screen, &ms_present_screen_info);
 }
commit 4342369e843ca2c6ca0a8c42475893cffb077a54
Author: Dave Airlie <airlied at redhat.com>
Date:   Fri Jun 26 09:20:13 2015 +1000

    modesetting: don't try and load dri2
    
    Since we are shipped with the server and the server has it built-in,
    don't bother trying to load it.
    
    Don't remove or invert the if statement on purpose as a later
    patch adds stuff in here.
    
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index f421668..ae562a1 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -820,7 +820,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     try_enable_glamor(pScrn);
 
     if (ms->drmmode.glamor) {
-        xf86LoadSubModule(pScrn, "dri2");
     } else {
         Bool prefer_shadow = TRUE;
 
commit edec6394a47be590f3133f6a90186356afd00829
Author: Dave Airlie <airlied at redhat.com>
Date:   Fri Jun 26 09:19:37 2015 +1000

    modesetting: drop unused struct in vblank.c
    
    this isn't used anywhere here.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/vblank.c b/hw/xfree86/drivers/modesetting/vblank.c
index 776dcef..0b7bf9d 100644
--- a/hw/xfree86/drivers/modesetting/vblank.c
+++ b/hw/xfree86/drivers/modesetting/vblank.c
@@ -50,11 +50,6 @@
 static struct xorg_list ms_drm_queue;
 static uint32_t ms_drm_seq;
 
-struct ms_pageflip {
-    ScreenPtr screen;
-    Bool crtc_for_msc_ust;
-};
-
 static void ms_box_intersect(BoxPtr dest, BoxPtr a, BoxPtr b)
 {
     dest->x1 = a->x1 > b->x1 ? a->x1 : b->x1;
commit bf262b43007050180d336defd48251de80894801
Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Mon Jan 26 21:25:58 2015 -0800

    modesetting: Implement an ms_drm_abort_seq() function.
    
    This is a specialization of ms_drm_abort that matches based on the drm
    event queue's sequence number.
    
    Based on code by Keith Packard.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>

diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index 4b6ae87..843a105 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -117,6 +117,7 @@ uint32_t ms_drm_queue_alloc(xf86CrtcPtr crtc,
 void ms_drm_abort(ScrnInfoPtr scrn,
                   Bool (*match)(void *data, void *match_data),
                   void *match_data);
+void ms_drm_abort_seq(ScrnInfoPtr scrn, uint32_t seq);
 
 Bool ms_crtc_on(xf86CrtcPtr crtc);
 
diff --git a/hw/xfree86/drivers/modesetting/vblank.c b/hw/xfree86/drivers/modesetting/vblank.c
index 91cfcf2..776dcef 100644
--- a/hw/xfree86/drivers/modesetting/vblank.c
+++ b/hw/xfree86/drivers/modesetting/vblank.c
@@ -323,6 +323,22 @@ ms_drm_abort_scrn(ScrnInfoPtr scrn)
     }
 }
 
+/**
+ * Abort by drm queue sequence number.
+ */
+void
+ms_drm_abort_seq(ScrnInfoPtr scrn, uint32_t seq)
+{
+    struct ms_drm_queue *q, *tmp;
+
+    xorg_list_for_each_entry_safe(q, tmp, &ms_drm_queue, list) {
+        if (q->seq == seq) {
+            ms_drm_abort_one(q);
+            break;
+        }
+    }
+}
+
 /*
  * Externally usable abort function that uses a callback to match a single
  * queued entry to abort
commit b8ccc5d36b0436bac57f07969ff3eb8d479a8511
Author: Jason Ekstrand <jason.ekstrand at intel.com>
Date:   Tue Jan 13 17:00:28 2015 -0800

    glamor: Add a new glamor_gbm_bo_from_pixmap() function.
    
    v2: Rebase on commit e0788a03144 (drop "base").
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/glamor/glamor.h b/glamor/glamor.h
index f402d7d..0931bbc 100644
--- a/glamor/glamor.h
+++ b/glamor/glamor.h
@@ -198,6 +198,21 @@ extern _X_EXPORT int glamor_fd_from_pixmap(ScreenPtr screen,
 extern _X_EXPORT int glamor_name_from_pixmap(PixmapPtr pixmap,
                                              CARD16 *stride, CARD32 *size);
 
+/* @glamor_gbm_bo_from_pixmap: Get a GBM bo from a pixmap.
+ *
+ * @screen: Current screen pointer.
+ * @pixmap: The pixmap from which we want the fd.
+ * @stride, @size: Pointers to fill the stride and size of the
+ * 		   buffer associated to the fd.
+ *
+ * the pixmap and the buffer represented by the gbm_bo will share the same
+ * content.
+ *
+ * Returns the gbm_bo on success, NULL on error.
+ * */
+extern _X_EXPORT void *glamor_gbm_bo_from_pixmap(ScreenPtr screen,
+                                                 PixmapPtr pixmap);
+
 /* @glamor_pixmap_from_fd: Creates a pixmap to wrap a dma-buf fd.
  *
  * @screen: Current screen pointer.
diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
index 25a9fbe..e01f723 100644
--- a/glamor/glamor_egl.c
+++ b/glamor/glamor_egl.c
@@ -395,13 +395,10 @@ glamor_get_name_from_bo(int gbm_fd, struct gbm_bo *bo, int *name)
 }
 #endif
 
-int
-glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen,
-                                 PixmapPtr pixmap,
-                                 unsigned int tex,
-                                 Bool want_name, CARD16 *stride, CARD32 *size)
-{
 #ifdef GLAMOR_HAS_GBM
+static void *
+_get_gbm_bo_from_pixmap(ScreenPtr screen, PixmapPtr pixmap, unsigned int tex)
+{
     ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
     struct glamor_pixmap_private *pixmap_priv =
         glamor_get_pixmap_private(pixmap);
@@ -410,7 +407,6 @@ glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen,
     struct glamor_egl_screen_private *glamor_egl;
     EGLImageKHR image;
     struct gbm_bo *bo;
-    int fd = -1;
 
     EGLint attribs[] = {
         EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
@@ -430,7 +426,7 @@ glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen,
                                   (EGLClientBuffer) (uintptr_t)
                                   tex, attribs);
         if (image == EGL_NO_IMAGE_KHR)
-            goto failure;
+            return NULL;
 
         glamor_set_pixmap_type(pixmap, GLAMOR_TEXTURE_DRM);
         glamor_egl_set_pixmap_image(pixmap, image);
@@ -438,6 +434,57 @@ glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen,
 
     bo = gbm_bo_import(glamor_egl->gbm, GBM_BO_IMPORT_EGL_IMAGE, image, 0);
     if (!bo)
+        return NULL;
+
+    pixmap->devKind = gbm_bo_get_stride(bo);
+
+    return bo;
+}
+#endif
+
+void *
+glamor_gbm_bo_from_pixmap(ScreenPtr screen, PixmapPtr pixmap)
+{
+#ifdef GLAMOR_HAS_GBM
+    glamor_screen_private *glamor_priv =
+        glamor_get_screen_private(pixmap->drawable.pScreen);
+    glamor_pixmap_private *pixmap_priv =
+        glamor_get_pixmap_private(pixmap);
+
+    pixmap_priv = glamor_get_pixmap_private(pixmap);
+    if (pixmap_priv == NULL || !glamor_priv->dri3_enabled)
+        return NULL;
+    switch (pixmap_priv->type) {
+    case GLAMOR_TEXTURE_DRM:
+    case GLAMOR_TEXTURE_ONLY:
+        if (!glamor_pixmap_ensure_fbo(pixmap, GL_RGBA, 0))
+            return NULL;
+        return _get_gbm_bo_from_pixmap(screen, pixmap,
+                                       pixmap_priv->fbo->tex);
+    default:
+        break;
+    }
+    return NULL;
+#else
+    return NULL;
+#endif
+}
+
+int
+glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen,
+                                 PixmapPtr pixmap,
+                                 unsigned int tex,
+                                 Bool want_name, CARD16 *stride, CARD32 *size)
+{
+#ifdef GLAMOR_HAS_GBM
+    struct glamor_egl_screen_private *glamor_egl;
+    struct gbm_bo *bo;
+    int fd = -1;
+
+    glamor_egl = glamor_egl_get_screen_private(xf86ScreenToScrn(screen));
+
+    bo = _get_gbm_bo_from_pixmap(screen, pixmap, tex);
+    if (!bo)
         goto failure;
 
     pixmap->devKind = gbm_bo_get_stride(bo);
commit f2171d0a20d3b3858a282c51c1561432de1b29ef
Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Tue Jan 6 21:02:44 2015 -0800

    modesetting: Make ms_crtc_on non-static.
    
    I want to use this in present.c.
    
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>

diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index 3decc3e..4b6ae87 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -118,6 +118,8 @@ void ms_drm_abort(ScrnInfoPtr scrn,
                   Bool (*match)(void *data, void *match_data),
                   void *match_data);
 
+Bool ms_crtc_on(xf86CrtcPtr crtc);
+
 xf86CrtcPtr ms_dri2_crtc_covering_drawable(DrawablePtr pDraw);
 xf86CrtcPtr ms_covering_crtc(ScrnInfoPtr scrn, BoxPtr box,
                              xf86CrtcPtr desired, BoxPtr crtc_box_ret);
diff --git a/hw/xfree86/drivers/modesetting/vblank.c b/hw/xfree86/drivers/modesetting/vblank.c
index a342662..91cfcf2 100644
--- a/hw/xfree86/drivers/modesetting/vblank.c
+++ b/hw/xfree86/drivers/modesetting/vblank.c
@@ -88,7 +88,7 @@ static int ms_box_area(BoxPtr box)
     return (int)(box->x2 - box->x1) * (int)(box->y2 - box->y1);
 }
 
-static Bool
+Bool
 ms_crtc_on(xf86CrtcPtr crtc)
 {
     drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
commit f6853baebaec6a68078fa7f90486e9547d59dcbd
Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Sun Feb 8 17:21:58 2015 -0800

    modesetting: Improve the ms_flush_drm_events() API.
    
    Previously, ms_flush_drm_events() returned a boolean value, and it was
    very easy to interpret the meaning incorrectly.  Now, we return an
    integer value.
    
    The possible outcomes of this call are:
    - poll() raised an error (formerly TRUE, now -1 - poll's return value)
    - poll() said there are no events (formerly TRUE, now 0).
    - drmHandleEvent() raised an error (formerly FALSE, now the negative
      value returned by drmHandleEvent).
    - An event was successfully handled (formerly TRUE, now 1).
    
    The nice part is that this allows you to distinguish errors (< 0),
    nothing to do (= 0), and success (1).  We no longer conflate errors
    with success.
    
    v2: Change ms_present_queue_vblank to < 0 instead of <= 0, fixing an
        unintentional behavior change.  libdrm may return EBUSY if it's
        received EINTR for more than a second straight; just keep retrying
        in that case.  Suggested by Jasper St. Pierre.
    
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>

diff --git a/hw/xfree86/drivers/modesetting/present.c b/hw/xfree86/drivers/modesetting/present.c
index 359e113..43df148 100644
--- a/hw/xfree86/drivers/modesetting/present.c
+++ b/hw/xfree86/drivers/modesetting/present.c
@@ -72,8 +72,11 @@ ms_present_get_ust_msc(RRCrtcPtr crtc, CARD64 *ust, CARD64 *msc)
 
 /*
  * Flush the DRM event queue when full; makes space for new events.
+ *
+ * Returns a negative value on error, 0 if there was nothing to process,
+ * or 1 if we handled any events.
  */
-static Bool
+static int
 ms_flush_drm_events(ScreenPtr screen)
 {
     ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
@@ -86,10 +89,19 @@ ms_flush_drm_events(ScreenPtr screen)
             r = poll(&p, 1, 0);
     } while (r == -1 && (errno == EINTR || errno == EAGAIN));
 
+    /* If there was an error, r will be < 0.  Return that.  If there was
+     * nothing to process, r == 0.  Return that.
+     */
     if (r <= 0)
-        return TRUE;
+        return r;
+
+    /* Try to handle the event.  If there was an error, return it. */
+    r = drmHandleEvent(ms->fd, &ms->event_context);
+    if (r < 0)
+        return r;
 
-    return drmHandleEvent(ms->fd, &ms->event_context) >= 0;
+    /* Otherwise return 1 to indicate that we handled an event. */
+    return 1;
 }
 
 /*
@@ -159,7 +171,10 @@ ms_present_queue_vblank(RRCrtcPtr crtc,
         ret = drmWaitVBlank(ms->fd, &vbl);
         if (!ret)
             break;
-        if (errno != EBUSY || !ms_flush_drm_events(screen))
+        /* If we hit EBUSY, then try to flush events.  If we can't, then
+         * this is an error.
+         */
+        if (errno != EBUSY || ms_flush_drm_events(screen) < 0)
             return BadAlloc;
     }
     DebugPresent(("\t\tmq %lld seq %u msc %llu (hw msc %u)\n",
commit 7328fb3f2b468048faf4ed4c29db720b5bf00b05
Author: Dave Airlie <airlied at gmail.com>
Date:   Wed Jun 10 13:41:02 2015 +1000

    modesetting: reverse prime support (v1.1)
    
    This adds support for reverse prime to the modesetting driver.
    
    Reverse prime is where we have two GPUs in the display chain,
    but the second GPU can't scanout from the shared pixmap, so needs
    an extra copy to the on screen pixmap.
    
    This allows modesetting to support this scenario while still
    supporting the USB offload one.
    
    v1.1:
    fix comment + ret = bits (Eric)
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 092cc53..f421668 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -572,7 +572,7 @@ msBlockHandler(ScreenPtr pScreen, void *pTimeout, void *pReadmask)
     pScreen->BlockHandler(pScreen, pTimeout, pReadmask);
     ms->BlockHandler = pScreen->BlockHandler;
     pScreen->BlockHandler = msBlockHandler;
-    if (pScreen->isGPU)
+    if (pScreen->isGPU && !ms->drmmode.reverse_prime_offload_mode)
         dispatch_slave_dirty(pScreen);
     else if (ms->dirty_enabled)
         dispatch_dirty(pScreen);
@@ -999,10 +999,18 @@ msSetSharedPixmapBacking(PixmapPtr ppix, void *fd_handle)
     ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
     modesettingPtr ms = modesettingPTR(scrn);
     Bool ret;
-    int size = ppix->devKind * ppix->drawable.height;
     int ihandle = (int) (long) fd_handle;
 
-    ret = drmmode_SetSlaveBO(ppix, &ms->drmmode, ihandle, ppix->devKind, size);
+    if (ms->drmmode.reverse_prime_offload_mode) {
+        ret = glamor_back_pixmap_from_fd(ppix, ihandle,
+                                         ppix->drawable.width,
+                                         ppix->drawable.height,
+                                         ppix->devKind, ppix->drawable.depth,
+                                         ppix->drawable.bitsPerPixel);
+    } else {
+        int size = ppix->devKind * ppix->drawable.height;
+        ret = drmmode_SetSlaveBO(ppix, &ms->drmmode, ihandle, ppix->devKind, size);
+    }
     if (ret == FALSE)
         return ret;
 
@@ -1190,6 +1198,9 @@ ScreenInit(ScreenPtr pScreen, int argc, char **argv)
             xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
                        "Failed to initialize the Present extension.\n");
         }
+        /* enable reverse prime if we are a GPU screen, and accelerated */
+        if (pScreen->isGPU)
+            ms->drmmode.reverse_prime_offload_mode = TRUE;
     }
 #endif
 
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index f3c9909..506ea24 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -50,6 +50,7 @@
 
 #include "driver.h"
 
+static Bool drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height);
 static int
 drmmode_bo_destroy(drmmode_ptr drmmode, drmmode_bo *bo)
 {
@@ -343,10 +344,14 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
 
         fb_id = drmmode->fb_id;
         if (crtc->randr_crtc->scanout_pixmap) {
-            msPixmapPrivPtr ppriv =
-                msGetPixmapPriv(drmmode, crtc->randr_crtc->scanout_pixmap);
-            fb_id = ppriv->fb_id;
-            x = y = 0;
+            if (!drmmode->reverse_prime_offload_mode) {
+                msPixmapPrivPtr ppriv =
+                    msGetPixmapPriv(drmmode, crtc->randr_crtc->scanout_pixmap);
+                fb_id = ppriv->fb_id;
+                x = 0;
+            } else
+                x = drmmode_crtc->prime_pixmap_x;
+            y = 0;
         }
         else if (drmmode_crtc->rotate_fb_id) {
             fb_id = drmmode_crtc->rotate_fb_id;
@@ -502,7 +507,54 @@ drmmode_crtc_gamma_set(xf86CrtcPtr crtc, uint16_t * red, uint16_t * green,
 }
 
 static Bool
-drmmode_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix)
+drmmode_set_scanout_pixmap_gpu(xf86CrtcPtr crtc, PixmapPtr ppix)
+{
+    ScreenPtr screen = xf86ScrnToScreen(crtc->scrn);
+    PixmapPtr screenpix = screen->GetScreenPixmap(screen);
+    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
+    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+    int c, total_width = 0, max_height = 0, this_x = 0;
+
+    if (!ppix) {
+        if (crtc->randr_crtc->scanout_pixmap)
+            PixmapStopDirtyTracking(crtc->randr_crtc->scanout_pixmap, screenpix);
+        drmmode_crtc->prime_pixmap_x = 0;
+        return TRUE;
+    }
+    /* iterate over all the attached crtcs to work out the bounding box */
+    for (c = 0; c < xf86_config->num_crtc; c++) {
+        xf86CrtcPtr iter = xf86_config->crtc[c];
+        if (!iter->enabled && iter != crtc)
+            continue;
+        if (iter == crtc) {
+            this_x = total_width;
+            total_width += ppix->drawable.width;
+            if (max_height < ppix->drawable.height)
+                max_height = ppix->drawable.height;
+        } else {
+            total_width += iter->mode.HDisplay;
+            if (max_height < iter->mode.VDisplay)
+                max_height = iter->mode.VDisplay;
+        }
+    }
+
+    if (total_width != screenpix->drawable.width ||
+        max_height != screenpix->drawable.height) {
+
+        if (!drmmode_xf86crtc_resize(crtc->scrn, total_width, max_height))
+            return FALSE;
+
+        screenpix = screen->GetScreenPixmap(screen);
+        screen->width = screenpix->drawable.width = total_width;
+        screen->height = screenpix->drawable.height = max_height;
+    }
+    drmmode_crtc->prime_pixmap_x = this_x;
+    PixmapStartDirtyTracking2(ppix, screenpix, 0, 0, this_x, 0);
+    return TRUE;
+}
+
+static Bool
+drmmode_set_scanout_pixmap_cpu(xf86CrtcPtr crtc, PixmapPtr ppix)
 {
     drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
     drmmode_ptr drmmode = drmmode_crtc->drmmode;
@@ -543,6 +595,18 @@ drmmode_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix)
     return TRUE;
 }
 
+static Bool
+drmmode_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix)
+{
+    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+    drmmode_ptr drmmode = drmmode_crtc->drmmode;
+
+    if (drmmode->reverse_prime_offload_mode)
+        return drmmode_set_scanout_pixmap_gpu(crtc, ppix);
+    else
+        return drmmode_set_scanout_pixmap_cpu(crtc, ppix);
+}
+
 static void *
 drmmode_shadow_allocate(xf86CrtcPtr crtc, int width, int height)
 {
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index b0e45b6..85a0ec4 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -79,6 +79,8 @@ typedef struct {
     uint32_t triple_buffer_name;
 
     DevPrivateKeyRec pixmapPrivateKeyRec;
+
+    Bool reverse_prime_offload_mode;
 } drmmode_rec, *drmmode_ptr;
 
 typedef struct {
@@ -93,7 +95,7 @@ typedef struct {
 
     drmmode_bo rotate_bo;
     unsigned rotate_fb_id;
-
+    unsigned prime_pixmap_x;
     /**
      * @{ MSC (vblank count) handling for the PRESENT extension.
      *
commit 1f10ee221edb87561900f5d2b1336db1c4a9f05c
Author: Dave Airlie <airlied at gmail.com>
Date:   Wed Jun 10 13:38:39 2015 +1000

    glamor: egl: add function to back a pixmap with a dma-buf. (v1.1)
    
    Rather than create the pixmap, this uses the file descriptor
    to change an existing pixmaps backing store.
    
    This is required for reverse prime slaves, where we create
    the slave pixmap, then set the backing store.
    
    v1.1: use local pScreen (Eric)
    
    Reviewed-by: Eric Anholt <eric at annholt.net>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/glamor/glamor.h b/glamor/glamor.h
index 657354d..f402d7d 100644
--- a/glamor/glamor.h
+++ b/glamor/glamor.h
@@ -218,6 +218,25 @@ extern _X_EXPORT PixmapPtr glamor_pixmap_from_fd(ScreenPtr screen,
                                                  CARD8 depth,
                                                  CARD8 bpp);
 
+/* @glamor_back_pixmap_from_fd: Backs an existing pixmap with a dma-buf fd.
+ *
+ * @pixmap: Pixmap to change backing for
+ * @fd: The dma-buf fd to import.
+ * @width: The width of the buffer.
+ * @height: The height of the buffer.
+ * @stride: The stride of the buffer.
+ * @depth: The depth of the buffer.
+ * @bpp: The number of bpp of the buffer.
+ *
+ * Returns TRUE if successful, FALSE on failure.
+ * */
+extern _X_EXPORT Bool glamor_back_pixmap_from_fd(PixmapPtr pixmap,
+                                                 int fd,
+                                                 CARD16 width,
+                                                 CARD16 height,
+                                                 CARD16 stride,
+                                                 CARD8 depth,
+                                                 CARD8 bpp);
 #ifdef GLAMOR_FOR_XORG
 
 #define GLAMOR_EGL_MODULE_NAME  "glamoregl"
diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
index 4c0db6a..25a9fbe 100644
--- a/glamor/glamor_egl.c
+++ b/glamor/glamor_egl.c
@@ -461,19 +461,19 @@ glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen,
 #endif
 }
 
-_X_EXPORT PixmapPtr
-glamor_pixmap_from_fd(ScreenPtr screen,
-                      int fd,
-                      CARD16 width,
-                      CARD16 height,
-                      CARD16 stride, CARD8 depth, CARD8 bpp)
+_X_EXPORT Bool
+glamor_back_pixmap_from_fd(PixmapPtr pixmap,
+                           int fd,
+                           CARD16 width,
+                           CARD16 height,
+                           CARD16 stride, CARD8 depth, CARD8 bpp)
 {
 #ifdef GLAMOR_HAS_GBM
+    ScreenPtr screen = pixmap->drawable.pScreen;
     ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
     struct glamor_egl_screen_private *glamor_egl;
     struct gbm_bo *bo;
     EGLImageKHR image;
-    PixmapPtr pixmap;
     Bool ret = FALSE;
 
     EGLint attribs[] = {
@@ -489,10 +489,10 @@ glamor_pixmap_from_fd(ScreenPtr screen,
     glamor_egl = glamor_egl_get_screen_private(scrn);
 
     if (!glamor_egl->dri3_capable)
-        return NULL;
+        return FALSE;
 
     if (bpp != 32 || !(depth == 24 || depth == 32) || width == 0 || height == 0)
-        return NULL;
+        return FALSE;
 
     attribs[1] = width;
     attribs[3] = height;
@@ -504,29 +504,48 @@ glamor_pixmap_from_fd(ScreenPtr screen,
                               NULL, attribs);
 
     if (image == EGL_NO_IMAGE_KHR)
-        return NULL;
+        return FALSE;
 
     /* EGL_EXT_image_dma_buf_import can impose restrictions on the
      * usage of the image. Use gbm_bo to bypass the limitations. */
-
     bo = gbm_bo_import(glamor_egl->gbm, GBM_BO_IMPORT_EGL_IMAGE, image, 0);
     eglDestroyImageKHR(glamor_egl->display, image);
 
     if (!bo)
-        return NULL;
+        return FALSE;
 
-    pixmap = screen->CreatePixmap(screen, 0, 0, depth, 0);
     screen->ModifyPixmapHeader(pixmap, width, height, 0, 0, stride, NULL);
 
     ret = glamor_egl_create_textured_pixmap_from_gbm_bo(pixmap, bo);
     gbm_bo_destroy(bo);
 
     if (ret)
-        return pixmap;
-    else {
+        return TRUE;
+    return FALSE;
+#else
+    return FALSE;
+#endif
+}
+
+_X_EXPORT PixmapPtr
+glamor_pixmap_from_fd(ScreenPtr screen,
+                      int fd,
+                      CARD16 width,
+                      CARD16 height,
+                      CARD16 stride, CARD8 depth, CARD8 bpp)
+{
+#ifdef GLAMOR_HAS_GBM
+    PixmapPtr pixmap;
+    Bool ret;
+
+    pixmap = screen->CreatePixmap(screen, 0, 0, depth, 0);
+    ret = glamor_back_pixmap_from_fd(pixmap, fd, width, height,
+                                     stride, depth, bpp);
+    if (ret == FALSE) {
         screen->DestroyPixmap(pixmap);
         return NULL;
     }
+    return pixmap;
 #else
     return NULL;
 #endif
commit a79fbfd707e1d745b670def08287241c87e11c28
Author: Dave Airlie <airlied at gmail.com>
Date:   Tue Jun 9 17:15:44 2015 +1000

    modesetting: add output master support
    
    This allows a glamor enabled master device to have
    slave USB devices attached.
    
    Tested with modesetting on SNB + USB.
    
    It relies on the previous patch to export linear
    buffers from glamor.
    
    Acked-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index e90e4b8..092cc53 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -532,6 +532,38 @@ dispatch_slave_dirty(ScreenPtr pScreen)
 }
 
 static void
+redisplay_dirty(ScreenPtr screen, PixmapDirtyUpdatePtr dirty)
+{
+
+        RegionRec pixregion;
+
+        PixmapRegionInit(&pixregion, dirty->slave_dst);
+        DamageRegionAppend(&dirty->slave_dst->drawable, &pixregion);
+        PixmapSyncDirtyHelper(dirty, &pixregion);
+
+        DamageRegionProcessPending(&dirty->slave_dst->drawable);
+        RegionUninit(&pixregion);
+}
+
+static void
+ms_dirty_update(ScreenPtr screen)
+{
+        RegionPtr region;
+        PixmapDirtyUpdatePtr ent;
+
+        if (xorg_list_is_empty(&screen->pixmap_dirty_list))
+                return;
+
+        xorg_list_for_each_entry(ent, &screen->pixmap_dirty_list, ent) {
+                region = DamageRegion(ent->damage);
+                if (RegionNotEmpty(region)) {
+                        redisplay_dirty(screen, ent);
+                        DamageEmpty(ent->damage);
+                }
+        }
+}
+
+static void
 msBlockHandler(ScreenPtr pScreen, void *pTimeout, void *pReadmask)
 {
     modesettingPtr ms = modesettingPTR(xf86ScreenToScrn(pScreen));
@@ -544,6 +576,8 @@ msBlockHandler(ScreenPtr pScreen, void *pTimeout, void *pReadmask)
         dispatch_slave_dirty(pScreen);
     else if (ms->dirty_enabled)
         dispatch_dirty(pScreen);
+
+    ms_dirty_update(pScreen);
 }
 
 static void
@@ -727,6 +761,10 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     if (ret == 0) {
         if (value & DRM_PRIME_CAP_IMPORT)
             pScrn->capabilities |= RR_Capability_SinkOutput;
+#if GLAMOR_HAS_GBM_LINEAR
+        if (value & DRM_PRIME_CAP_EXPORT)
+            pScrn->capabilities |= RR_Capability_SourceOutput;
+#endif
     }
 #endif
     drmmode_get_default_bpp(pScrn, &ms->drmmode, &defaultdepth, &defaultbpp);
@@ -938,6 +976,23 @@ msShadowInit(ScreenPtr pScreen)
 }
 
 static Bool
+msSharePixmapBacking(PixmapPtr ppix, ScreenPtr screen, void **handle)
+{
+#ifdef GLAMOR_HAS_GBM
+    int ret;
+    CARD16 stride;
+    CARD32 size;
+    ret = glamor_fd_from_pixmap(ppix->drawable.pScreen, ppix, &stride, &size);
+    if (ret == -1)
+        return FALSE;
+
+    *handle = (void *)(long)(ret);
+    return TRUE;
+#endif
+    return FALSE;
+}
+
+static Bool
 msSetSharedPixmapBacking(PixmapPtr ppix, void *fd_handle)
 {
     ScreenPtr screen = ppix->drawable.pScreen;
@@ -1089,7 +1144,10 @@ ScreenInit(ScreenPtr pScreen, int argc, char **argv)
     ms->BlockHandler = pScreen->BlockHandler;
     pScreen->BlockHandler = msBlockHandler;
 
+    pScreen->SharePixmapBacking = msSharePixmapBacking;
     pScreen->SetSharedPixmapBacking = msSetSharedPixmapBacking;
+    pScreen->StartPixmapTracking = PixmapStartDirtyTracking;
+    pScreen->StopPixmapTracking = PixmapStopDirtyTracking;
 
     if (!xf86CrtcScreenInit(pScreen))
         return FALSE;
commit ea0e4d752b778c1f2132f8d29542f7dabc296415
Author: Dave Airlie <airlied at gmail.com>
Date:   Wed Jun 10 14:46:22 2015 +1000

    glamor: add support for allocating linear buffers (v2)
    
    We need this for doing USB offload scenarios using glamor
    and modesetting driver.
    
    unfortunately only gbm in mesa 10.6 has support for the
    linear API.
    
    v1.1: fix bad define
    v2: update the configure.ac test as per amdgpu. (Michel)
    set linear bos to external to avoid cache. (Eric)
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/configure.ac b/configure.ac
index f760730..592e133 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2105,6 +2105,10 @@ if test "x$GLAMOR" = xyes; then
 	if test "x$GBM" = xyes; then
 		AC_DEFINE(GLAMOR_HAS_GBM, 1,
 			  [Build glamor with GBM-based EGL support])
+		AC_CHECK_DECL(GBM_BO_USE_LINEAR,
+			[AC_DEFINE(GLAMOR_HAS_GBM_LINEAR, 1, [Have GBM_BO_USE_LINEAR])], [],
+			[#include <stdlib.h>
+			 #include <gbm.h>])
 	fi
 
 fi
diff --git a/glamor/glamor.h b/glamor/glamor.h
index 0d57fff..657354d 100644
--- a/glamor/glamor.h
+++ b/glamor/glamor.h
@@ -142,7 +142,8 @@ extern _X_EXPORT void glamor_enable_dri3(ScreenPtr screen);
 extern _X_EXPORT unsigned int glamor_egl_create_argb8888_based_texture(ScreenPtr
                                                                        screen,
                                                                        int w,
-                                                                       int h);
+                                                                       int h,
+                                                                       Bool linear);
 extern _X_EXPORT int glamor_egl_dri3_fd_name_from_tex(ScreenPtr, PixmapPtr,
                                                       unsigned int, Bool,
                                                       CARD16 *, CARD32 *);
diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
index dc54561..4c0db6a 100644
--- a/glamor/glamor_egl.c
+++ b/glamor/glamor_egl.c
@@ -187,7 +187,7 @@ glamor_egl_get_gbm_device(ScreenPtr screen)
 }
 
 unsigned int
-glamor_egl_create_argb8888_based_texture(ScreenPtr screen, int w, int h)
+glamor_egl_create_argb8888_based_texture(ScreenPtr screen, int w, int h, Bool linear)
 {
     ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
     struct glamor_egl_screen_private *glamor_egl;
@@ -200,6 +200,9 @@ glamor_egl_create_argb8888_based_texture(ScreenPtr screen, int w, int h)
 
     glamor_egl = glamor_egl_get_screen_private(scrn);
     bo = gbm_bo_create(glamor_egl->gbm, w, h, GBM_FORMAT_ARGB8888,
+#ifdef GLAMOR_HAS_GBM_LINEAR
+                       (linear ? GBM_BO_USE_LINEAR : 0) |
+#endif
                        GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT);
     if (!bo)
         return 0;
diff --git a/glamor/glamor_egl_stubs.c b/glamor/glamor_egl_stubs.c
index a93f62d..c11e6d5 100644
--- a/glamor/glamor_egl_stubs.c
+++ b/glamor/glamor_egl_stubs.c
@@ -50,7 +50,7 @@ glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen,
 }
 
 unsigned int
-glamor_egl_create_argb8888_based_texture(ScreenPtr screen, int w, int h)
+glamor_egl_create_argb8888_based_texture(ScreenPtr screen, int w, int h, Bool linear)
 {
     return 0;
 }
diff --git a/glamor/glamor_fbo.c b/glamor/glamor_fbo.c
index ea0e801..6017f5e 100644
--- a/glamor/glamor_fbo.c
+++ b/glamor/glamor_fbo.c
@@ -228,6 +228,9 @@ glamor_create_fbo_from_tex(glamor_screen_private *glamor_priv,
     fbo->external = FALSE;
     fbo->format = format;
 
+    if (flag == CREATE_PIXMAP_USAGE_SHARED)
+        fbo->external = TRUE;
+
     if (flag != GLAMOR_CREATE_FBO_NO_FBO) {
         if (glamor_pixmap_ensure_fb(glamor_priv, fbo) != 0) {
             glamor_purge_fbo(glamor_priv, fbo);
@@ -313,7 +316,7 @@ glamor_destroy_fbo(glamor_screen_private *glamor_priv,
 
 static int
 _glamor_create_tex(glamor_screen_private *glamor_priv,
-                   int w, int h, GLenum format)
+                   int w, int h, GLenum format, Bool linear)
 {
     unsigned int tex = 0;
 
@@ -323,7 +326,7 @@ _glamor_create_tex(glamor_screen_private *glamor_priv,
      * an ARGB8888 based texture for us. */
     if (glamor_priv->dri3_enabled && format == GL_RGBA) {
         tex = glamor_egl_create_argb8888_based_texture(glamor_priv->screen,
-                                                       w, h);
+                                                       w, h, linear);
     }
     if (!tex) {
         glamor_make_current(glamor_priv);
@@ -344,14 +347,14 @@ glamor_create_fbo(glamor_screen_private *glamor_priv,
     glamor_pixmap_fbo *fbo;
     GLint tex = 0;
 
-    if (flag == GLAMOR_CREATE_FBO_NO_FBO)
+    if (flag == GLAMOR_CREATE_FBO_NO_FBO || flag == CREATE_PIXMAP_USAGE_SHARED)
         goto new_fbo;
 
     fbo = glamor_pixmap_fbo_cache_get(glamor_priv, w, h, format);
     if (fbo)
         return fbo;
  new_fbo:
-    tex = _glamor_create_tex(glamor_priv, w, h, format);
+    tex = _glamor_create_tex(glamor_priv, w, h, format, flag == CREATE_PIXMAP_USAGE_SHARED);
     fbo = glamor_create_fbo_from_tex(glamor_priv, w, h, format, tex, flag);
 
     return fbo;
@@ -531,7 +534,7 @@ glamor_pixmap_ensure_fbo(PixmapPtr pixmap, GLenum format, int flag)
         if (!pixmap_priv->fbo->tex)
             pixmap_priv->fbo->tex =
                 _glamor_create_tex(glamor_priv, pixmap->drawable.width,
-                                   pixmap->drawable.height, format);
+                                   pixmap->drawable.height, format, FALSE);
 
         if (flag != GLAMOR_CREATE_FBO_NO_FBO && pixmap_priv->fbo->fb == 0)
             if (glamor_pixmap_ensure_fb(glamor_priv, pixmap_priv->fbo) != 0)
diff --git a/hw/xwayland/xwayland-glamor.c b/hw/xwayland/xwayland-glamor.c
index 6b6e597..ece7dbe 100644
--- a/hw/xwayland/xwayland-glamor.c
+++ b/hw/xwayland/xwayland-glamor.c
@@ -415,7 +415,7 @@ glamor_egl_dri3_fd_name_from_tex(ScreenPtr screen,
 }
 
 unsigned int
-glamor_egl_create_argb8888_based_texture(ScreenPtr screen, int w, int h)
+glamor_egl_create_argb8888_based_texture(ScreenPtr screen, int w, int h, Bool linear)
 {
     return 0;
 }
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index 76f45f5..c2ba434 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -503,6 +503,9 @@
 /* Build glamor's GBM-based EGL support */
 #undef GLAMOR_HAS_GBM
 
+/* Build glamor/gbm has linear support */
+#undef GLAMOR_HAS_GBM_LINEAR
+
 /* byte order */
 #undef X_BYTE_ORDER
 
commit 5c555605386c76be2f02193d434a4617218b67be
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Jun 11 14:29:48 2015 +1000

    xf86: restrict when we auto add devices as gpu devices.
    
    Michel pointed out I broke Zaphod with the initial auto add
    gpu devices change,
    
    Fix this, by only auto adding GPU devices if we are screen 0
    and there are no other screens in the layout. Anyone who
    wants to assign GPU devices can specify it in the xorg.conf
    for this use case.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    Tested-by: Michel Dänzer <michel.daenzer at amd.com>

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index b8ec8a0..2b4df0c 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -123,7 +123,7 @@ static ModuleDefault ModuleDefaults[] = {
 
 /* Forward declarations */
 static Bool configScreen(confScreenPtr screenp, XF86ConfScreenPtr conf_screen,
-                         int scrnum, MessageType from);
+                         int scrnum, MessageType from, Bool auto_gpu_device);
 static Bool configMonitor(MonPtr monitorp, XF86ConfMonitorPtr conf_monitor);
 static Bool configDevice(GDevPtr devicep, XF86ConfDevicePtr conf_device,
                          Bool active, Bool gpu);
@@ -1524,7 +1524,7 @@ configLayout(serverLayoutPtr servlayoutp, XF86ConfLayoutPtr conf_layout,
         else
             scrnum = adjp->adj_scrnum;
         if (!configScreen(slp[count].screen, adjp->adj_screen, scrnum,
-                          X_CONFIG)) {
+                          X_CONFIG, (scrnum == 0 && !adjp->list.next))) {
             do {
                 free(slp[count].screen);
             } while (count--);
@@ -1574,7 +1574,7 @@ configLayout(serverLayoutPtr servlayoutp, XF86ConfLayoutPtr conf_layout,
         FIND_SUITABLE (XF86ConfScreenPtr, xf86configptr->conf_screen_lst, screen);
         slp[0].screen = xnfcalloc(1, sizeof(confScreenRec));
         if (!configScreen(slp[0].screen, screen,
-                          0, X_CONFIG)) {
+                          0, X_CONFIG, TRUE)) {
             free(slp[0].screen);
             free(slp);
             return FALSE;
@@ -1703,7 +1703,7 @@ configImpliedLayout(serverLayoutPtr servlayoutp, XF86ConfScreenPtr conf_screen,
     slp = xnfcalloc(1, 2 * sizeof(screenLayoutRec));
     slp[0].screen = xnfcalloc(1, sizeof(confScreenRec));
     slp[1].screen = NULL;
-    if (!configScreen(slp[0].screen, conf_screen, 0, from)) {
+    if (!configScreen(slp[0].screen, conf_screen, 0, from, TRUE)) {
         free(slp);
         return FALSE;
     }
@@ -1768,7 +1768,7 @@ configXvAdaptor(confXvAdaptorPtr adaptor, XF86ConfVideoAdaptorPtr conf_adaptor)
 
 static Bool
 configScreen(confScreenPtr screenp, XF86ConfScreenPtr conf_screen, int scrnum,
-             MessageType from)
+             MessageType from, Bool auto_gpu_device)
 {
     int count = 0;
     XF86ConfDisplayPtr dispptr;
@@ -1825,7 +1825,8 @@ configScreen(confScreenPtr screenp, XF86ConfScreenPtr conf_screen, int scrnum,
         screenp->device = NULL;
     }
 
-    if (conf_screen->num_gpu_devices == 0 && xf86configptr->conf_device_lst) {
+    if (auto_gpu_device && conf_screen->num_gpu_devices == 0 &&
+        xf86configptr->conf_device_lst) {
         XF86ConfDevicePtr sdevice = xf86configptr->conf_device_lst->list.next;
 
         for (i = 0; i < MAX_GPUDEVICES; i++) {
commit 5064ee276fe0f6cebc33ea08e57f1de91f092d88
Author: Dave Airlie <airlied at redhat.com>
Date:   Fri Jun 12 15:13:47 2015 +1000

    xf86Rotate: remove unused macros.
    
    These macros aren't used anywhere.
    
    v1.1: drop comment (Aaron)
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/modes/xf86Rotate.c b/hw/xfree86/modes/xf86Rotate.c
index 9c00a44..bc1ea21 100644
--- a/hw/xfree86/modes/xf86Rotate.c
+++ b/hw/xfree86/modes/xf86Rotate.c
@@ -43,12 +43,6 @@
 #include "X11/extensions/dpmsconst.h"
 #include "X11/Xatom.h"
 
-/* borrowed from composite extension, move to Render and publish? */
-
-#define F(x)	IntToxFixed(x)
-
-#define toF(x)	((float) (x) / 65536.0f)
-
 static void
 xf86RotateCrtcRedisplay(xf86CrtcPtr crtc, RegionPtr region)
 {
commit 8218dadd30eb0c87efbac6db5d8e3862a236b6a4
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue Jun 9 15:30:22 2015 +1000

    cursor: drop ARGB_CURSOR
    
    I doubt anyone builds with this turned off or has done for a long
    time.
    
    It helps my eyes bleed slightly less when reading the code, I've left
    the define in place as some drivers use it.
    
    Reviewed-by: Aaron Plattner <aplattner at nvidia.com>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/dix/cursor.c b/dix/cursor.c
index 1525857..e459456 100644
--- a/dix/cursor.c
+++ b/dix/cursor.c
@@ -80,9 +80,7 @@ FreeCursorBits(CursorBitsPtr bits)
         return;
     free(bits->source);
     free(bits->mask);
-#ifdef ARGB_CURSOR
     free(bits->argb);
-#endif
     dixFiniPrivates(bits, PRIVATE_CURSOR_BITS);
     if (bits->refcnt == 0) {
         GlyphSharePtr *prev, this;
@@ -165,7 +163,6 @@ CheckForEmptyMask(CursorBitsPtr bits)
     while (n--)
         if (*(msk++) != 0)
             return;
-#ifdef ARGB_CURSOR
     if (bits->argb) {
         CARD32 *argb = bits->argb;
 
@@ -174,7 +171,6 @@ CheckForEmptyMask(CursorBitsPtr bits)
             if (*argb++ & 0xff000000)
                 return;
     }
-#endif
     bits->emptyMask = TRUE;
 }
 
@@ -259,9 +255,7 @@ AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits,
     dixInitPrivates(bits, bits + 1, PRIVATE_CURSOR_BITS)
         bits->source = psrcbits;
     bits->mask = pmaskbits;
-#ifdef ARGB_CURSOR
     bits->argb = argb;
-#endif
     bits->width = cm->width;
     bits->height = cm->height;
     bits->xhot = cm->xhot;
@@ -400,9 +394,7 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
         dixInitPrivates(bits, bits + 1, PRIVATE_CURSOR_BITS);
         bits->source = srcbits;
         bits->mask = mskbits;
-#ifdef ARGB_CURSOR
         bits->argb = 0;
-#endif
         bits->width = cm.width;
         bits->height = cm.height;
         bits->xhot = cm.xhot;
diff --git a/hw/kdrive/ephyr/ephyrcursor.c b/hw/kdrive/ephyr/ephyrcursor.c
index 852be33..808b3c7 100644
--- a/hw/kdrive/ephyr/ephyrcursor.c
+++ b/hw/kdrive/ephyr/ephyrcursor.c
@@ -100,7 +100,6 @@ ephyrRealizeCoreCursor(EphyrScrPriv *scr, CursorPtr cursor)
     xcb_free_pixmap(conn, mask);
 }
 
-#ifdef ARGB_CURSOR
 static xcb_render_pictformat_t
 get_argb_format(void)
 {
@@ -170,7 +169,6 @@ can_argb_cursor(void)
 
     return v->major_version == 0 && v->minor_version >= 5;
 }
-#endif
 
 static Bool
 ephyrRealizeCursor(DeviceIntPtr dev, ScreenPtr screen, CursorPtr cursor)
@@ -179,11 +177,9 @@ ephyrRealizeCursor(DeviceIntPtr dev, ScreenPtr screen, CursorPtr cursor)
     KdScreenInfo *kscr = pScreenPriv->screen;
     EphyrScrPriv *scr = kscr->driver;
 
-#ifdef ARGB_CURSOR
     if (cursor->bits->argb && can_argb_cursor())
         ephyrRealizeARGBCursor(scr, cursor);
     else
-#endif
     {
         ephyrRealizeCoreCursor(scr, cursor);
     }
diff --git a/hw/xfree86/modes/xf86Cursors.c b/hw/xfree86/modes/xf86Cursors.c
index 379a27a..321cde7 100644
--- a/hw/xfree86/modes/xf86Cursors.c
+++ b/hw/xfree86/modes/xf86Cursors.c
@@ -258,9 +258,7 @@ xf86_crtc_convert_cursor_to_argb(xf86CrtcPtr crtc, unsigned char *src)
     CARD32 bits;
     const Rotation rotation = xf86_crtc_cursor_rotation(crtc);
 
-#ifdef ARGB_CURSOR
     crtc->cursor_argb = FALSE;
-#endif
 
     for (y = 0; y < cursor_info->MaxHeight; y++)
         for (x = 0; x < cursor_info->MaxWidth; x++) {
@@ -458,9 +456,7 @@ xf86_crtc_load_cursor_image(xf86CrtcPtr crtc, CARD8 *src)
     CARD8 *cursor_image;
     const Rotation rotation = xf86_crtc_cursor_rotation(crtc);
 
-#ifdef ARGB_CURSOR
     crtc->cursor_argb = FALSE;
-#endif
 
     if (rotation == RR_Rotate_0)
         cursor_image = src;
@@ -632,12 +628,10 @@ xf86_cursors_init(ScreenPtr screen, int max_width, int max_height, int flags)
     cursor_info->HideCursor = xf86_hide_cursors;
     cursor_info->ShowCursor = xf86_show_cursors;
     cursor_info->UseHWCursor = xf86_use_hw_cursor;
-#ifdef ARGB_CURSOR
     if (flags & HARDWARE_CURSOR_ARGB) {
         cursor_info->UseHWCursorARGB = xf86_use_hw_cursor_argb;
         cursor_info->LoadCursorARGBCheck = xf86_load_cursor_argb;
     }
-#endif
 
     xf86_config->cursor = NULL;
     xf86_hide_cursors(scrn);
@@ -691,11 +685,9 @@ xf86_reload_cursors(ScreenPtr screen)
         void *src =
             dixLookupScreenPrivate(&cursor->devPrivates, CursorScreenKey,
                                    screen);
-#ifdef ARGB_CURSOR
         if (cursor->bits->argb && xf86DriverHasLoadCursorARGB(cursor_info))
             xf86DriverLoadCursorARGB(cursor_info, cursor);
         else if (src)
-#endif
             xf86DriverLoadCursorImage(cursor_info, src);
 
         x += scrn->frameX0 + cursor_screen_priv->HotX;
diff --git a/hw/xfree86/ramdac/xf86Cursor.c b/hw/xfree86/ramdac/xf86Cursor.c
index 04496d5..2a54571 100644
--- a/hw/xfree86/ramdac/xf86Cursor.c
+++ b/hw/xfree86/ramdac/xf86Cursor.c
@@ -340,12 +340,10 @@ xf86CursorSetCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCurs,
         if (infoPtr->pScrn->vtSema && xorg_list_is_empty(&pScreen->pixmap_dirty_list) &&
             (ScreenPriv->ForceHWCursorCount ||
              ((
-#ifdef ARGB_CURSOR
                cursor->bits->argb &&
                infoPtr->UseHWCursorARGB &&
                (*infoPtr->UseHWCursorARGB)(pScreen, cursor)) ||
               (cursor->bits->argb == 0 &&
-#endif
                (cursor->bits->height <= infoPtr->MaxHeight) &&
                (cursor->bits->width <= infoPtr->MaxWidth) &&
                (!infoPtr->UseHWCursor || (*infoPtr->UseHWCursor) (pScreen, cursor)))))) {
diff --git a/hw/xfree86/ramdac/xf86Cursor.h b/hw/xfree86/ramdac/xf86Cursor.h
index a389a99..8c98bb1 100644
--- a/hw/xfree86/ramdac/xf86Cursor.h
+++ b/hw/xfree86/ramdac/xf86Cursor.h
@@ -19,11 +19,9 @@ typedef struct _xf86CursorInfoRec {
     unsigned char *(*RealizeCursor) (struct _xf86CursorInfoRec *, CursorPtr);
     Bool (*UseHWCursor) (ScreenPtr, CursorPtr);
 
-#ifdef ARGB_CURSOR
     Bool (*UseHWCursorARGB) (ScreenPtr, CursorPtr);
     void (*LoadCursorARGB) (ScrnInfoPtr, CursorPtr);
     Bool (*LoadCursorARGBCheck) (ScrnInfoPtr, CursorPtr);
-#endif
 
 } xf86CursorInfoRec, *xf86CursorInfoPtr;
 
@@ -77,8 +75,6 @@ extern _X_EXPORT void xf86ForceHWCursor(ScreenPtr pScreen, Bool on);
 #define HARDWARE_CURSOR_NIBBLE_SWAPPED			0x00000800
 #define HARDWARE_CURSOR_SHOW_TRANSPARENT		0x00001000
 #define HARDWARE_CURSOR_UPDATE_UNHIDDEN			0x00002000
-#ifdef ARGB_CURSOR
 #define HARDWARE_CURSOR_ARGB				0x00004000
-#endif
 
 #endif                          /* _XF86CURSOR_H */
diff --git a/hw/xfree86/ramdac/xf86HWCurs.c b/hw/xfree86/ramdac/xf86HWCurs.c
index be7154e..84febe0 100644
--- a/hw/xfree86/ramdac/xf86HWCurs.c
+++ b/hw/xfree86/ramdac/xf86HWCurs.c
@@ -139,9 +139,7 @@ xf86SetCursor(ScreenPtr pScreen, CursorPtr pCurs, int x, int y)
     x -= infoPtr->pScrn->frameX0 + ScreenPriv->HotX;
     y -= infoPtr->pScrn->frameY0 + ScreenPriv->HotY;
 
-#ifdef ARGB_CURSOR
     if (!pCurs->bits->argb || !xf86DriverHasLoadCursorARGB(infoPtr))
-#endif
         if (!bits) {
             bits = (*infoPtr->RealizeCursor) (infoPtr, pCurs);
             dixSetScreenPrivate(&pCurs->devPrivates, CursorScreenKey, pScreen,
@@ -151,12 +149,10 @@ xf86SetCursor(ScreenPtr pScreen, CursorPtr pCurs, int x, int y)
     if (!(infoPtr->Flags & HARDWARE_CURSOR_UPDATE_UNHIDDEN))
         (*infoPtr->HideCursor) (infoPtr->pScrn);
 
-#ifdef ARGB_CURSOR
     if (pCurs->bits->argb && xf86DriverHasLoadCursorARGB(infoPtr)) {
         if (!xf86DriverLoadCursorARGB (infoPtr, pCurs))
             return FALSE;
     } else
-#endif
     if (bits)
         if (!xf86DriverLoadCursorImage (infoPtr, bits))
             return FALSE;
@@ -213,12 +209,10 @@ xf86RecolorCursor(ScreenPtr pScreen, CursorPtr pCurs, Bool displayed)
                                                xf86CursorScreenKey);
     xf86CursorInfoPtr infoPtr = ScreenPriv->CursorInfoPtr;
 
-#ifdef ARGB_CURSOR
     /* recoloring isn't applicable to ARGB cursors and drivers
        shouldn't have to ignore SetCursorColors requests */
     if (pCurs->bits->argb)
         return;
-#endif
 
     if (ScreenPriv->PalettedCursor) {
         xColorItem sourceColor, maskColor;
diff --git a/hw/xquartz/xpr/xprCursor.c b/hw/xquartz/xpr/xprCursor.c
index 4168f7c..5e89348 100644
--- a/hw/xquartz/xpr/xprCursor.c
+++ b/hw/xquartz/xpr/xprCursor.c
@@ -85,7 +85,6 @@ load_cursor(CursorPtr src, int screen)
     hot_x = src->bits->xhot;
     hot_y = src->bits->yhot;
 
-#ifdef ARGB_CURSOR
     if (src->bits->argb != NULL) {
 #if BITMAP_BIT_ORDER == MSBFirst
         rowbytes = src->bits->width * sizeof(CARD32);
@@ -104,7 +103,6 @@ load_cursor(CursorPtr src, int screen)
 #endif
     }
     else
-#endif
     {
         fg_color = 0xFF00 | (src->foreRed >> 8);
         fg_color <<= 16;
diff --git a/include/cursorstr.h b/include/cursorstr.h
index 221cd70..3f306a4 100644
--- a/include/cursorstr.h
+++ b/include/cursorstr.h
@@ -64,9 +64,7 @@ typedef struct _CursorBits {
     unsigned short width, height, xhot, yhot;   /* metrics */
     int refcnt;                 /* can be shared */
     PrivateRec *devPrivates;    /* set by pScr->RealizeCursor */
-#ifdef ARGB_CURSOR
     CARD32 *argb;               /* full-color alpha blended */
-#endif
 } CursorBits, *CursorBitsPtr;
 
 #define CURSOR_BITS_SIZE (sizeof(CursorBits) + dixPrivatesSize(PRIVATE_CURSOR_BITS))
diff --git a/mi/midispcur.c b/mi/midispcur.c
index 50f0dd2..d1da0fd 100644
--- a/mi/midispcur.c
+++ b/mi/midispcur.c
@@ -46,9 +46,7 @@ in this Software without prior written authorization from The Open Group.
 #include   "misprite.h"
 #include   "gcstruct.h"
 
-#ifdef ARGB_CURSOR
 #include   "picturestr.h"
-#endif
 
 #include "inputstr.h"
 
@@ -68,9 +66,7 @@ typedef struct {
     GCPtr pSourceGC, pMaskGC;
     GCPtr pSaveGC, pRestoreGC;
     PixmapPtr pSave;
-#ifdef ARGB_CURSOR
     PicturePtr pRootPicture;
-#endif
 } miDCBufferRec, *miDCBufferPtr;
 
 #define miGetDCDevice(dev, screen) \
@@ -86,9 +82,7 @@ typedef struct {
     CloseScreenProcPtr CloseScreen;
     PixmapPtr sourceBits;       /* source bits */
     PixmapPtr maskBits;         /* mask bits */
-#ifdef ARGB_CURSOR
     PicturePtr pPicture;
-#endif
     CursorPtr pCursor;
 } miDCScreenRec, *miDCScreenPtr;
 
@@ -133,11 +127,9 @@ miDCSwitchScreenCursor(ScreenPtr pScreen, CursorPtr pCursor, PixmapPtr sourceBit
         (*pScreen->DestroyPixmap)(pScreenPriv->maskBits);
     pScreenPriv->maskBits = maskBits;
 
-#ifdef ARGB_CURSOR
     if (pScreenPriv->pPicture)
         FreePicture(pScreenPriv->pPicture, 0);
     pScreenPriv->pPicture = pPicture;
-#endif
 
     pScreenPriv->pCursor = pCursor;
 }
@@ -162,7 +154,6 @@ miDCRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
     return TRUE;
 }
 
-#ifdef ARGB_CURSOR
 #define EnsurePicture(picture,draw,win) (picture || miDCMakePicture(&picture,draw,win))
 
 static PicturePtr
@@ -182,7 +173,6 @@ miDCMakePicture(PicturePtr * ppPicture, DrawablePtr pDraw, WindowPtr pWin)
     *ppPicture = pPicture;
     return pPicture;
 }
-#endif
 
 static Bool
 miDCRealize(ScreenPtr pScreen, CursorPtr pCursor)
@@ -195,8 +185,6 @@ miDCRealize(ScreenPtr pScreen, CursorPtr pCursor)
     if (pScreenPriv->pCursor == pCursor)
         return TRUE;
 
-#ifdef ARGB_CURSOR
-
     if (pCursor->bits->argb) {
         PixmapPtr pPixmap;
         PictFormatPtr pFormat;
@@ -233,7 +221,7 @@ miDCRealize(ScreenPtr pScreen, CursorPtr pCursor)
         miDCSwitchScreenCursor(pScreen, pCursor, NULL, NULL, pPicture);
         return TRUE;
     }
-#endif
+
     sourceBits = (*pScreen->CreatePixmap) (pScreen, pCursor->bits->width,
                                            pCursor->bits->height, 1, 0);
     if (!sourceBits)
@@ -373,7 +361,6 @@ miDCPutUpCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor,
     pWin = pScreen->root;
     pBuffer = miGetDCDevice(pDev, pScreen);
 
-#ifdef ARGB_CURSOR
     if (pScreenPriv->pPicture) {
         if (!EnsurePicture(pBuffer->pRootPicture, &pWin->drawable, pWin))
             return FALSE;
@@ -385,7 +372,6 @@ miDCPutUpCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor,
                          x, y, pCursor->bits->width, pCursor->bits->height);
     }
     else
-#endif
     {
         miDCPutBits((DrawablePtr) pWin,
                     pBuffer->pSourceGC, pBuffer->pMaskGC,
@@ -486,9 +472,7 @@ miDCDeviceInitialize(DeviceIntPtr pDev, ScreenPtr pScreen)
         if (!pBuffer->pRestoreGC)
             goto failure;
 
-#ifdef ARGB_CURSOR
         pBuffer->pRootPicture = NULL;
-#endif
 
         /* (re)allocated lazily depending on the cursor size */
         pBuffer->pSave = NULL;
@@ -525,11 +509,9 @@ miDCDeviceCleanup(DeviceIntPtr pDev, ScreenPtr pScreen)
                 if (pBuffer->pRestoreGC)
                     FreeGC(pBuffer->pRestoreGC, (GContext) 0);
 
-#ifdef ARGB_CURSOR
                 /* If a pRootPicture was allocated for a root window, it
                  * is freed when that root window is destroyed, so don't
                  * free it again here. */
-#endif
 
                 if (pBuffer->pSave)
                     (*pScreen->DestroyPixmap) (pBuffer->pSave);
diff --git a/xfixes/cursor.c b/xfixes/cursor.c
index 94d24a8..5619aad 100644
--- a/xfixes/cursor.c
+++ b/xfixes/cursor.c
@@ -306,11 +306,9 @@ CopyCursorToImage(CursorPtr pCursor, CARD32 *image)
     int height = pCursor->bits->height;
     int npixels = width * height;
 
-#ifdef ARGB_CURSOR
     if (pCursor->bits->argb)
         memcpy(image, pCursor->bits->argb, npixels * sizeof(CARD32));
     else
-#endif
     {
         unsigned char *srcLine = pCursor->bits->source;
         unsigned char *mskLine = pCursor->bits->mask;
commit 3c859112d38860764bcdb205ab461d00db502f45
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Tue Jun 23 15:05:31 2015 +0200

    xwayland: keep temp files out of the client mask
    
    Xwayland opens anonymous files for its sharing buffers, move these
    file descriptors out of the range of the client select mask to avoid
    reaching the maximum number of clients prematurely.
    
    https://bugs.freedesktop.org/show_bug.cgi?id=91072
    
    Tested-by: Olivier Fourdan <fourdan at gmail.com>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/hw/xwayland/xwayland-shm.c b/hw/xwayland/xwayland-shm.c
index 2d0ce3e..1022c0d 100644
--- a/hw/xwayland/xwayland-shm.c
+++ b/hw/xwayland/xwayland-shm.c
@@ -82,7 +82,7 @@ create_tmpfile_cloexec(char *tmpname)
     }
 #endif
 
-    return fd;
+    return os_move_fd(fd);
 }
 
 /*
commit 8c86dd51606486f4794c503b9c05c6875bdc693a
Author: Laércio de Sousa <laerciosousa at sme-mogidascruzes.sp.gov.br>
Date:   Tue Jun 23 08:41:57 2015 -0300

    configure.ac: fix code misplacing for KDRIVE_{KBD, MOUSE, EVDEV} auto-detection
    
    KDrive input drivers "kbd", "mouse", and "evdev" should be automatically built
    for linux systems. However, due to a code misplacing in configure.ac, the
    auto-detection test is being performed AFTER the corresponding AC_DEFINEs' calls,
    so that the drivers are NOT being built, regardless the test result.
    
    This bug should be affecting previous xorg-server releases. Please consider
    backporting this patch to all maintained ones!
    
    Signed-off-by: Laércio de Sousa <laerciosousa at sme-mogidascruzes.sp.gov.br>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/configure.ac b/configure.ac
index f760730..f187a13 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2337,6 +2337,33 @@ if test "$KDRIVE" = yes; then
         fi
     fi
 
+    case $host_os in
+	*linux*)
+	    KDRIVE_OS_LIB='$(top_builddir)/hw/kdrive/linux/liblinux.la'
+            KDRIVELINUX=yes
+	    if test "x$KDRIVE_EVDEV" = xauto; then
+		KDRIVE_EVDEV=yes
+	    fi
+	    if test "x$KDRIVE_KBD" = xauto; then
+		KDRIVE_KBD=yes
+	    fi
+	    if test "x$KDRIVE_MOUSE" = xauto; then
+		KDRIVE_MOUSE=yes
+	    fi
+	    ;;
+	*)
+	    if test "x$KDRIVE_EVDEV" = xauto; then
+		KDRIVE_EVDEV=no
+	    fi
+	    if test "x$KDRIVE_KBD" = xauto; then
+		KDRIVE_KBD=no
+	    fi
+	    if test "x$KDRIVE_MOUSE" = xauto; then
+		KDRIVE_MOUSE=no
+	    fi
+	    ;;
+    esac
+
     if test "x$KDRIVE_KBD" = xyes; then
        AC_DEFINE(KDRIVE_KBD, 1, [Enable KDrive kbd driver])
     fi
@@ -2378,32 +2405,6 @@ if test "$KDRIVE" = yes; then
 
     KDRIVE_PURE_LIBS="$FB_LIB $MI_LIB $FIXES_LIB $XEXT_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $DRI3_LIB $PRESENT_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $OS_LIB"
     KDRIVE_LIB='$(top_builddir)/hw/kdrive/src/libkdrive.la'
-    case $host_os in
-	*linux*)
-	    KDRIVE_OS_LIB='$(top_builddir)/hw/kdrive/linux/liblinux.la'
-            KDRIVELINUX=yes
-	    if test "x$KDRIVE_EVDEV" = xauto; then
-		KDRIVE_EVDEV=yes
-	    fi
-	    if test "x$KDRIVE_KBD" = xauto; then
-		KDRIVE_KBD=yes
-	    fi
-	    if test "x$KDRIVE_MOUSE" = xauto; then
-		KDRIVE_MOUSE=yes
-	    fi
-	    ;;
-	*)
-	    if test "x$KDRIVE_EVDEV" = xauto; then
-		KDRIVE_EVDEV=no
-	    fi
-	    if test "x$KDRIVE_KBD" = xauto; then
-		KDRIVE_KBD=no
-	    fi
-	    if test "x$KDRIVE_MOUSE" = xauto; then
-		KDRIVE_MOUSE=no
-	    fi
-	    ;;
-    esac
     KDRIVE_MAIN_LIB="$MAIN_LIB"
     KDRIVE_LOCAL_LIBS="$DIX_LIB $KDRIVE_LIB"
     KDRIVE_LOCAL_LIBS="$KDRIVE_LOCAL_LIBS $FB_LIB $MI_LIB $KDRIVE_PURE_LIBS"
commit 780a69aff0ff57ef813179a2f09556eaf488cdfc
Author: David Herrmann <dh.herrmann at gmail.com>
Date:   Mon Jun 22 21:13:05 2015 +0200

    systemd-logind: do not rely on directed signals
    
    Right now, Xorg does not install DBus matches for "PauseDevice" /
    "ResumeDevice". Therefore, it should usually not receive those DBus
    signals from logind. It is just a coincidence that systemd-logind sends
    those signals in a directed manner right now. Therefore, dbus-daemon
    bypasses the broadcast matches.
    
    However, this is not ABI and Xorg should not rely on this. systemd-logind
    is free to send those signals as broadcasts, in which case Xorg will
    freeze the VT. Fix this by always installing those matches.
    
    Cc: Hans de Goede <hdegoede at redhat.com>
    Cc: Keith Packard <keithp at keithp.com>
    Reported-by: Jan Alexander Steffens <jan.steffens at gmail.com>
    Signed-off-by: David Herrmann <dh.herrmann at gmail.com>
    Reviewed-by: Hans de Goede <hdegoede at redhat.com>
    Tested-by: Hans de Goede <hdegoede at redhat.com>
    Signed-off-by: Hans de Goede <hdegoede at redhat.com>

diff --git a/hw/xfree86/os-support/linux/systemd-logind.c b/hw/xfree86/os-support/linux/systemd-logind.c
index 69e2f67..2612d9e 100644
--- a/hw/xfree86/os-support/linux/systemd-logind.c
+++ b/hw/xfree86/os-support/linux/systemd-logind.c
@@ -507,6 +507,24 @@ connect_hook(DBusConnection *connection, void *data)
         goto cleanup;
     }
 
+    dbus_bus_add_match(connection,
+        "type='signal',sender='org.freedesktop.login1',interface='org.freedesktop.login1.Session',member='PauseDevice'",
+        &error);
+    if (dbus_error_is_set(&error)) {
+        LogMessage(X_ERROR, "systemd-logind: could not add match: %s\n",
+                   error.message);
+        goto cleanup;
+    }
+
+    dbus_bus_add_match(connection,
+        "type='signal',sender='org.freedesktop.login1',interface='org.freedesktop.login1.Session',member='ResumeDevice'",
+        &error);
+    if (dbus_error_is_set(&error)) {
+        LogMessage(X_ERROR, "systemd-logind: could not add match: %s\n",
+                   error.message);
+        goto cleanup;
+    }
+
     /*
      * HdG: This is not useful with systemd <= 208 since the signal only
      * contains invalidated property names there, rather than property, val
commit d3352d098724e96be8fb8538a3640ce271d8f8b9
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Mon Jun 22 13:51:21 2015 +0200

    Xorg.wrap.man: Fix spelling mistake in Xorg.wrap.1
    
    This commit fixes a small mistake in Xorg.wrap.1 .
    
    Signed-off-by: Hans de Goede <hdegoede at redhat.com>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/hw/xfree86/man/Xorg.wrap.man b/hw/xfree86/man/Xorg.wrap.man
index 11090f1..f3f30a6 100644
--- a/hw/xfree86/man/Xorg.wrap.man
+++ b/hw/xfree86/man/Xorg.wrap.man
@@ -55,7 +55,7 @@ The default is \fIconsole\fP.
 \fBneeds_root_rights\fP = \fIyes\fP|\fIno\fP|\fIauto\fP
 Configure if the wrapper should drop its elevated (root) rights before starting
 the X server. Use \fIyes\fP to force execution as root, \fIno\fP to force
-execution with all suid rights dropped, and \fIauto\fP to letter the wrapper
+execution with all suid rights dropped, and \fIauto\fP to let the wrapper
 auto-detect. The default is \fIauto\fP.
 .PP
 When auto-detecting the wrapper will drop rights if kms graphics are available
commit 790311cec30ac3d35e580b9f1266236f558033d4
Author: Eric Anholt <eric at anholt.net>
Date:   Sun May 31 16:08:10 2015 -0700

    glamor: Don't try to disable attrib divisors without the extension.
    
    Fixes epoxy assertion failures on vc4.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/glamor/glamor_composite_glyphs.c b/glamor/glamor_composite_glyphs.c
index c30cbed..1f0d75e 100644
--- a/glamor/glamor_composite_glyphs.c
+++ b/glamor/glamor_composite_glyphs.c
@@ -266,9 +266,11 @@ glamor_glyphs_flush(CARD8 op, PicturePtr src, PicturePtr dst,
 
     glDisable(GL_SCISSOR_TEST);
 
-    glVertexAttribDivisor(GLAMOR_VERTEX_SOURCE, 0);
+    if (glamor_glyph_use_130(glamor_priv)) {
+        glVertexAttribDivisor(GLAMOR_VERTEX_SOURCE, 0);
+        glVertexAttribDivisor(GLAMOR_VERTEX_POS, 0);
+    }
     glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
-    glVertexAttribDivisor(GLAMOR_VERTEX_POS, 0);
     glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
     glDisable(GL_BLEND);
 }
commit 9c679d06055cc62aa9209318705e87dc33fba4c8
Author: Eric Anholt <eric at anholt.net>
Date:   Sun May 31 16:07:01 2015 -0700

    glamor: Skip actual FBO setup in our glyph atlas.
    
    VC4 (and many GLES2 renderers) can't render to GL_ALPHA, so our pixmap
    would end up as GLAMOR_MEMORY and our dereference of the FBO would
    setfault.  Instead, tell the pixmap creation that we don't need an FBO
    at all.  Our glyph upload path was already glTexImage for non-a1, and
    a more general software fallback for a1 (since the glyph is also in
    system memory).
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/glamor/glamor_composite_glyphs.c b/glamor/glamor_composite_glyphs.c
index 47bf647..c30cbed 100644
--- a/glamor/glamor_composite_glyphs.c
+++ b/glamor/glamor_composite_glyphs.c
@@ -112,7 +112,8 @@ glamor_glyph_atlas_init(ScreenPtr screen, struct glamor_glyph_atlas *atlas)
     PictFormatPtr               format = atlas->format;
 
     atlas->atlas = glamor_create_pixmap(screen, glamor_priv->glyph_atlas_dim,
-                                        glamor_priv->glyph_atlas_dim, format->depth, 0);
+                                        glamor_priv->glyph_atlas_dim, format->depth,
+                                        GLAMOR_CREATE_FBO_NO_FBO);
     atlas->x = 0;
     atlas->y = 0;
     atlas->row_height = 0;
commit 077bb1bdea0fa9af846c02896df680293cf9e25c
Author: Eric Anholt <eric at anholt.net>
Date:   Sun May 31 15:46:55 2015 -0700

    glamor: Clean up some declarations in glyph rendering.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/glamor/glamor_composite_glyphs.c b/glamor/glamor_composite_glyphs.c
index 39ed854..47bf647 100644
--- a/glamor/glamor_composite_glyphs.c
+++ b/glamor/glamor_composite_glyphs.c
@@ -331,8 +331,6 @@ glamor_composite_glyphs(CARD8 op,
     ScreenPtr screen = drawable->pScreen;
     glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
     glamor_program *prog = NULL;
-    PicturePtr glyph_pict = NULL;
-    DrawablePtr glyph_draw;
     glamor_program_render       *glyphs_program = &glamor_priv->glyphs_program;
     struct glamor_glyph_atlas    *glyph_atlas = NULL;
     int x = 0, y = 0;
@@ -360,11 +358,10 @@ glamor_composite_glyphs(CARD8 op,
             /* Glyph not empty?
              */
             if (glyph->info.width && glyph->info.height) {
-                glamor_pixmap_private *glyph_pix_priv;
-
-                glyph_pict = GlyphPicture(glyph)[screen_num];
-                glyph_draw = glyph_pict->pDrawable;
-                glyph_pix_priv = glamor_get_pixmap_private((PixmapPtr) glyph_draw);
+                PicturePtr glyph_pict = GlyphPicture(glyph)[screen_num];
+                DrawablePtr glyph_draw = glyph_pict->pDrawable;
+                glamor_pixmap_private *glyph_pix_priv =
+                    glamor_get_pixmap_private((PixmapPtr) glyph_draw);
 
                 /* Need to draw with slow path?
                  */
commit bf7a3bcb00d0dce22ff3fe42fe6236beeab4403b
Author: Eric Anholt <eric at anholt.net>
Date:   Sun May 31 15:28:39 2015 -0700

    glamor: Actually allow glyphs of dimension 65 to 128 in the cache.
    
    The cache was trying to allow glyph_max_dim in, but since we were
    putting over 64x64 into HW memory, it would end up in the
    single-glyph-per-render bail_one path.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/glamor/glamor.c b/glamor/glamor.c
index 807f28e..71ca4f4 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -160,7 +160,9 @@ glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth,
         return NullPixmap;
 
     if ((usage == GLAMOR_CREATE_PIXMAP_CPU
-         || (usage == CREATE_PIXMAP_USAGE_GLYPH_PICTURE && w <= 64 && h <= 64)
+         || (usage == CREATE_PIXMAP_USAGE_GLYPH_PICTURE &&
+             w <= glamor_priv->glyph_max_dim &&
+             h <= glamor_priv->glyph_max_dim)
          || (w == 0 && h == 0)
          || !glamor_check_pixmap_fbo_depth(depth))
         || (!GLAMOR_TEXTURED_LARGE_PIXMAP &&
commit f4c3cac010cff0980905eeedd8e8d7baf0aff91b
Author: Alexander Volkov <a.volkov at rusbitech.ru>
Date:   Wed Jun 17 12:41:35 2015 +0300

    Xi: call UpdateDeviceState() even when the client is missing
    
    The client window can be closed in the middle of a touch sequence,
    e.g. Qt 4 closes popup windows on MousePress and Qt 5.5 will do it
    on TouchBegin. In this case the state of mouse buttons will not be
    updated on TouchEnd because ProcessTouchEvent() calls UpdateDeviceState()
    only when the event has been sent to the client. It results in a
    stuck left mouse button.
    
    This patch leads to calling UpdateDeviceState() in case the client
    can't be found.
    
    Signed-off-by: Alexander Volkov <a.volkov at rusbitech.ru>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/exevents.c b/Xi/exevents.c
index cd33f94..e728310 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1590,7 +1590,7 @@ ProcessTouchEvent(InternalEvent *ev, DeviceIntPtr dev)
     if (!ti) {
         DebugF("[Xi] %s: Failed to get event %d for touchpoint %d\n",
                dev->name, type, touchid);
-        return;
+        goto out;
     }
 
     /* if emulate_pointer is set, emulate the motion event right
@@ -1624,6 +1624,7 @@ ProcessTouchEvent(InternalEvent *ev, DeviceIntPtr dev)
     if (ev->any.type == ET_TouchEnd)
         TouchEndTouch(dev, ti);
 
+ out:
     if (emulate_pointer)
         UpdateDeviceState(dev, &ev->device_event);
 }
commit 990cf5b2828f73dc7a07f1e38f608af39acfd81d
Author: Andrew Eikum <aeikum at codeweavers.com>
Date:   Thu Jun 4 13:24:53 2015 -0500

    dix: Send KeyPress and KeyRelease events to the XACE_KEY_AVAIL hook
    
    While it's documented in the XACE spec, the XACE_KEY_AVAIL hook is
    currently never actually invoked by the xserver.
    
    This hook was added in 13c6713c82 (25 Aug 2006), but as the keyboard
    processing was moved into XKB, the hook was forgotten and silently
    dropped. The code calling this hook was removed by 7af53799c (4 Jan
    2009), but it was probably already unused before that.
    
    This patch re-adds support for this hook. The "count" hook parameter is
    unused.
    
    Signed-off-by: Andrew Eikum <aeikum at codeweavers.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/Xi/exevents.c b/Xi/exevents.c
index 1c586d0..cd33f94 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1730,6 +1730,18 @@ ProcessDeviceEvent(InternalEvent *ev, DeviceIntPtr device)
         break;
     }
 
+    /* send KeyPress and KeyRelease events to XACE plugins */
+    if (XaceHookIsSet(XACE_KEY_AVAIL) &&
+            (event->type == ET_KeyPress || event->type == ET_KeyRelease)) {
+        xEvent *core;
+        int count;
+
+        if (EventToCore(ev, &core, &count) == Success && count > 0) {
+            XaceHook(XACE_KEY_AVAIL, core, device, 0);
+            free(core);
+        }
+    }
+
     if (DeviceEventCallback && !syncEvents.playingEvents) {
         DeviceEventInfoRec eventinfo;
         SpritePtr pSprite = device->spriteInfo->sprite;
commit 5dc2a9aae46352f1f35d3ba122da04727789a15d
Author: Andrew Eikum <aeikum at codeweavers.com>
Date:   Thu Jun 4 13:23:19 2015 -0500

    xace: Add XaceHookIsSet helper function
    
    Signed-off-by: Andrew Eikum <aeikum at codeweavers.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/Xext/xace.c b/Xext/xace.c
index d77b312..b3c67f6 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -213,6 +213,21 @@ XaceHook(int hook, ...)
     return prv ? *prv : Success;
 }
 
+/* XaceHookIsSet
+ *
+ * Utility function to determine whether there are any callbacks listening on a
+ * particular XACE hook.
+ *
+ * Returns non-zero if there is a callback, zero otherwise.
+ */
+int
+XaceHookIsSet(int hook)
+{
+    if (hook < 0 || hook >= XACE_NUM_HOOKS)
+        return 0;
+    return XaceHooks[hook] != NULL;
+}
+
 /* XaceCensorImage
  *
  * Called after pScreen->GetImage to prevent pieces or trusted windows from
diff --git a/Xext/xace.h b/Xext/xace.h
index 5e6cb04..3303f76 100644
--- a/Xext/xace.h
+++ b/Xext/xace.h
@@ -65,6 +65,9 @@ extern _X_EXPORT int XaceHook(int /*hook */ ,
                               ...       /*appropriate args for hook */
     );
 
+/* determine whether any callbacks are present for the XACE hook */
+extern _X_EXPORT int XaceHookIsSet(int hook);
+
 /* Special-cased hook functions
  */
 extern _X_EXPORT int XaceHookDispatch(ClientPtr ptr, int major);
commit c88a325899381d1133e63e6c33c29db079e20a87
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Wed Jan 21 10:13:20 2015 +0100

    systemd-logind: Only use systemd-logind integration together with keeptty
    
    systemd-logind integration does not work when starting X on a new tty, as
    that detaches X from the current session and after hat systemd-logind revokes
    all rights any already open fds and refuses to open new fds for X.
    
    This means that currently e.g. "startx -- vt7" breaks, and breaks badly,
    requiring ssh access to the system to kill X.
    
    The fix for this is easy, we must not use systemd-logind integration when
    not using KeepTty, or iow we may only use systemd-logind integration together
    with KeepTty.
    
    Signed-off-by: Hans de Goede <hdegoede at redhat.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Tested-by: Aaron Plattner <aplattner at nvidia.com>

diff --git a/hw/xfree86/man/Xorg.man b/hw/xfree86/man/Xorg.man
index 3ff6aef..ddf1358 100644
--- a/hw/xfree86/man/Xorg.man
+++ b/hw/xfree86/man/Xorg.man
@@ -271,9 +271,9 @@ is ignored if
 is anything other than \(oqPCI\(cq.
 .TP 8
 .B \-keeptty
-Prevent the server from detaching its initial controlling terminal.
-This option is only useful when debugging the server.  Not all platforms
-support (or can use) this option.
+Prevent the server from detaching its initial controlling terminal. If you
+want to use systemd-logind integration you must specify this option.
+Not all platforms support (or can use) this option.
 .TP 8
 .BI \-keyboard " keyboard-name"
 Use the xorg.conf(__filemansuffix__) file
diff --git a/hw/xfree86/os-support/linux/systemd-logind.c b/hw/xfree86/os-support/linux/systemd-logind.c
index 4ad41a3..69e2f67 100644
--- a/hw/xfree86/os-support/linux/systemd-logind.c
+++ b/hw/xfree86/os-support/linux/systemd-logind.c
@@ -34,6 +34,7 @@
 
 #include "os.h"
 #include "dbus-core.h"
+#include "linux.h"
 #include "xf86.h"
 #include "xf86platformBus.h"
 #include "xf86Xinput.h"
@@ -596,6 +597,13 @@ static struct dbus_core_hook core_hook = {
 int
 systemd_logind_init(void)
 {
+    if (linux_parse_vt_settings(TRUE) && !linux_get_keeptty()) {
+        LogMessage(X_INFO,
+            "systemd-logind: logind integration requires -keeptty and "
+            "-keeptty was not provided, disabling logind integration\n");
+        return 1;
+    }
+
     return dbus_core_add_hook(&core_hook);
 }
 
commit 81bcada14e339fe2a2fb3f3a040566d94dc20bad
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Wed May 13 13:17:09 2015 +0200

    linux: Add a may_fail paramter to linux_parse_vt_settings
    
    linux_parse_vt_settings() was split out of xf86OpenConsole so that it can
    be called earlier during systemd-logind init, but it is possible to run
    the xserver in such a way that xf86OpenConsole() is never used.
    
    The FatalError calls in linux_parse_vt_settings() may stop the Xorg xserver
    from working when e.g. no /dev/tty0 is present in such a setup.
    
    This commit adds a may_fail parameter to linux_parse_vt_settings() which
    can be used to make linux_parse_vt_settings() fail silenty with an error
    return in this case, rather then calling FatalError().
    
    Signed-off-by: Hans de Goede <hdegoede at redhat.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/os-support/linux/linux.h b/hw/xfree86/os-support/linux/linux.h
index 8cb8e3d..83506fd 100644
--- a/hw/xfree86/os-support/linux/linux.h
+++ b/hw/xfree86/os-support/linux/linux.h
@@ -26,7 +26,7 @@
 #ifndef XF86_LINUX_H
 #define XF86_LINUX_H
 
-void linux_parse_vt_settings(void);
+int linux_parse_vt_settings(int may_fail);
 int linux_get_keeptty(void);
 
 #endif
diff --git a/hw/xfree86/os-support/linux/lnx_init.c b/hw/xfree86/os-support/linux/lnx_init.c
index 7032825..ec06a05 100644
--- a/hw/xfree86/os-support/linux/lnx_init.c
+++ b/hw/xfree86/os-support/linux/lnx_init.c
@@ -80,8 +80,8 @@ switch_to(int vt, const char *from)
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
 
-void
-linux_parse_vt_settings(void)
+int
+linux_parse_vt_settings(int may_fail)
 {
     int i, fd = -1, ret, current_vt = -1;
     struct vt_stat vts;
@@ -93,7 +93,7 @@ linux_parse_vt_settings(void)
     static int vt_settings_parsed = 0;
 
     if (vt_settings_parsed)
-        return;
+        return 1;
 
     /*
      * setup the virtual terminal manager
@@ -110,24 +110,36 @@ linux_parse_vt_settings(void)
             i++;
         }
 
-        if (fd < 0)
+        if (fd < 0) {
+            if (may_fail)
+                return 0;
             FatalError("parse_vt_settings: Cannot open /dev/tty0 (%s)\n",
                        strerror(errno));
+        }
 
         if (xf86Info.ShareVTs) {
             SYSCALL(ret = ioctl(fd, VT_GETSTATE, &vts));
-            if (ret < 0)
+            if (ret < 0) {
+                if (may_fail)
+                    return 0;
                 FatalError("parse_vt_settings: Cannot find the current"
                            " VT (%s)\n", strerror(errno));
+            }
             xf86Info.vtno = vts.v_active;
         }
         else {
             SYSCALL(ret = ioctl(fd, VT_OPENQRY, &xf86Info.vtno));
-            if (ret < 0)
+            if (ret < 0) {
+                if (may_fail)
+                    return 0;
                 FatalError("parse_vt_settings: Cannot find a free VT: "
                            "%s\n", strerror(errno));
-            if (xf86Info.vtno == -1)
+            }
+            if (xf86Info.vtno == -1) {
+                if (may_fail)
+                    return 0;
                 FatalError("parse_vt_settings: Cannot find a free VT\n");
+            }
         }
         close(fd);
     }
@@ -151,6 +163,7 @@ linux_parse_vt_settings(void)
     }
 
     vt_settings_parsed = 1;
+    return 1;
 }
 
 int
@@ -168,7 +181,7 @@ xf86OpenConsole(void)
     const char *vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL };
 
     if (serverGeneration == 1) {
-        linux_parse_vt_settings();
+        linux_parse_vt_settings(FALSE);
 
         if (!KeepTty) {
             pid_t ppid = getppid();
commit 1dba5a0b194653b0effb01a918bd7338b0c6bcb9
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Wed Jan 21 09:31:39 2015 +0100

    linux: Add linux_parse_vt_settings and linux_get_keeptty helpers
    
    systemd-logind integration does not work when starting X on a new tty, as
    that detaches X from the current session and after hat systemd-logind revokes
    all rights on any already open fds and refuses to open new fds for X.
    
    This means that currently e.g. "startx -- vt7" breaks, and breaks badly,
    requiring ssh access to the system to kill X.
    
    The fix for this is easy, we must not use systemd-logind integration when
    not using KeepTty, or iow we may only use systemd-logind integration together
    with KeepTty.
    
    But the final KeepTty value is not known until the code to chose which vtno to
    run on has been called, which currently happens after intializing
    systemd-logind.
    
    This commit is step 1 in fixing the "startx -- vt7" breakage, it factors out
    the linux xf86OpenConsole bits which set xf86Info.vtno and keepTty so that
    these can be called earlier. Calling this earlier is safe as this code has
    no side effects other than setting xf86Info.vtno and keepTty.
    
    Note this basically only moves a large chunk of xf86OpenConsole() into
    linux_parse_vt_settings() without changing a single line of it, this is
    hard to see in the diff because the identation level has changed.
    
    Signed-off-by: Hans de Goede <hdegoede at redhat.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/os-support/linux/linux.h b/hw/xfree86/os-support/linux/linux.h
new file mode 100644
index 0000000..8cb8e3d
--- /dev/null
+++ b/hw/xfree86/os-support/linux/linux.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright © 2015 Red Hat, Inc.
+ *
+ * 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.
+ *
+ * Author: Hans de Goede <hdegoede at redhat.com>
+ */
+
+#ifndef XF86_LINUX_H
+#define XF86_LINUX_H
+
+void linux_parse_vt_settings(void);
+int linux_get_keeptty(void);
+
+#endif
diff --git a/hw/xfree86/os-support/linux/lnx_init.c b/hw/xfree86/os-support/linux/lnx_init.c
index a0e6782..7032825 100644
--- a/hw/xfree86/os-support/linux/lnx_init.c
+++ b/hw/xfree86/os-support/linux/lnx_init.c
@@ -31,6 +31,7 @@
 #include <X11/Xmd.h>
 
 #include "compiler.h"
+#include "linux.h"
 
 #include "xf86.h"
 #include "xf86Priv.h"
@@ -80,71 +81,94 @@ switch_to(int vt, const char *from)
 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
 
 void
-xf86OpenConsole(void)
+linux_parse_vt_settings(void)
 {
     int i, fd = -1, ret, current_vt = -1;
-    struct vt_mode VT;
     struct vt_stat vts;
     struct stat st;
     MessageType from = X_PROBED;
     const char *tty0[] = { "/dev/tty0", "/dev/vc/0", NULL };
-    const char *vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL };
 
-    if (serverGeneration == 1) {
-        /*
-         * setup the virtual terminal manager
-         */
-        if (xf86Info.vtno != -1) {
-            from = X_CMDLINE;
-        }
-        else {
+    /* Only do this once */
+    static int vt_settings_parsed = 0;
 
-            i = 0;
-            while (tty0[i] != NULL) {
-                if ((fd = open(tty0[i], O_WRONLY, 0)) >= 0)
-                    break;
-                i++;
-            }
+    if (vt_settings_parsed)
+        return;
 
-            if (fd < 0)
-                FatalError("xf86OpenConsole: Cannot open /dev/tty0 (%s)\n",
-                           strerror(errno));
+    /*
+     * setup the virtual terminal manager
+     */
+    if (xf86Info.vtno != -1) {
+        from = X_CMDLINE;
+    }
+    else {
 
-            if (xf86Info.ShareVTs) {
-                SYSCALL(ret = ioctl(fd, VT_GETSTATE, &vts));
-                if (ret < 0)
-                    FatalError("xf86OpenConsole: Cannot find the current"
-                               " VT (%s)\n", strerror(errno));
-                xf86Info.vtno = vts.v_active;
-            }
-            else {
-                SYSCALL(ret = ioctl(fd, VT_OPENQRY, &xf86Info.vtno));
-                if (ret < 0)
-                    FatalError("xf86OpenConsole: Cannot find a free VT: "
-                               "%s\n", strerror(errno));
-                if (xf86Info.vtno == -1)
-                    FatalError("xf86OpenConsole: Cannot find a free VT\n");
-            }
-            close(fd);
+        i = 0;
+        while (tty0[i] != NULL) {
+            if ((fd = open(tty0[i], O_WRONLY, 0)) >= 0)
+                break;
+            i++;
         }
 
-        xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno);
+        if (fd < 0)
+            FatalError("parse_vt_settings: Cannot open /dev/tty0 (%s)\n",
+                       strerror(errno));
 
-        /* Some of stdin / stdout / stderr maybe redirected to a file */
-        for (i = STDIN_FILENO; i <= STDERR_FILENO; i++) {
-            ret = fstat(i, &st);
-            if (ret == 0 && S_ISCHR(st.st_mode) && major(st.st_rdev) == 4) {
-                current_vt = minor(st.st_rdev);
-                break;
-            }
+        if (xf86Info.ShareVTs) {
+            SYSCALL(ret = ioctl(fd, VT_GETSTATE, &vts));
+            if (ret < 0)
+                FatalError("parse_vt_settings: Cannot find the current"
+                           " VT (%s)\n", strerror(errno));
+            xf86Info.vtno = vts.v_active;
         }
+        else {
+            SYSCALL(ret = ioctl(fd, VT_OPENQRY, &xf86Info.vtno));
+            if (ret < 0)
+                FatalError("parse_vt_settings: Cannot find a free VT: "
+                           "%s\n", strerror(errno));
+            if (xf86Info.vtno == -1)
+                FatalError("parse_vt_settings: Cannot find a free VT\n");
+        }
+        close(fd);
+    }
+
+    xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno);
 
-        if (!KeepTty && current_vt == xf86Info.vtno) {
-            xf86Msg(X_PROBED,
-                    "controlling tty is VT number %d, auto-enabling KeepTty\n",
-                    current_vt);
-            KeepTty = TRUE;
+    /* Some of stdin / stdout / stderr maybe redirected to a file */
+    for (i = STDIN_FILENO; i <= STDERR_FILENO; i++) {
+        ret = fstat(i, &st);
+        if (ret == 0 && S_ISCHR(st.st_mode) && major(st.st_rdev) == 4) {
+            current_vt = minor(st.st_rdev);
+            break;
         }
+    }
+
+    if (!KeepTty && current_vt == xf86Info.vtno) {
+        xf86Msg(X_PROBED,
+                "controlling tty is VT number %d, auto-enabling KeepTty\n",
+                current_vt);
+        KeepTty = TRUE;
+    }
+
+    vt_settings_parsed = 1;
+}
+
+int
+linux_get_keeptty(void)
+{
+    return KeepTty;
+}
+
+void
+xf86OpenConsole(void)
+{
+    int i, ret;
+    struct vt_stat vts;
+    struct vt_mode VT;
+    const char *vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL };
+
+    if (serverGeneration == 1) {
+        linux_parse_vt_settings();
 
         if (!KeepTty) {
             pid_t ppid = getppid();


More information about the Xquartz-changes mailing list