[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

xorg-server: Changes to 'upstream-experimental'



Rebased ref, commits from common ancestor:
commit fc1c358b955258ce675e49490de7c3b8ddee2b76
Author: Keith Packard <keithp@keithp.com>
Date:   Mon Sep 19 09:02:57 2016 -0700

    Bump to 1.18.99.901 (1.19 RC1)
    
    Signed-off-by: Keith Packard <keithp@keithp.com>

diff --git a/configure.ac b/configure.ac
index 190e473..c09b854 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.18.99.2, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
-RELEASE_DATE="2016-09-16"
-RELEASE_NAME="Marionberry Pie"
+AC_INIT([xorg-server], 1.18.99.901, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
+RELEASE_DATE="2016-09-19"
+RELEASE_NAME="Brown Turkey Fig"
 AC_CONFIG_SRCDIR([Makefile.am])
 AC_CONFIG_MACRO_DIR([m4])
 AM_INIT_AUTOMAKE([foreign dist-bzip2])

commit 5998da7855750dd947288349a0b14e65db1e3c8c
Author: Jonas Ådahl <jadahl@gmail.com>
Date:   Tue Sep 13 15:16:56 2016 +0800

    dix: Incroduce CursorConfinedTo vfunc in Screen
    
    This function will be called when a pointer is grabbed non-root window
    set as the 'confineTo'. This will enable the ddx to handle the
    confinement their own way.
    
    Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
    Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
    Signed-off-by: Keith Packard <keithp@keithp.com>

diff --git a/dix/events.c b/dix/events.c
index 87f080e..cc26ba5 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -882,6 +882,8 @@ ConfineCursorToWindow(DeviceIntPtr pDev, WindowPtr pWin, Bool generateEvents,
         SyntheticMotion(pDev, pSprite->hot.x, pSprite->hot.y);
     }
     else {
+        ScreenPtr pScreen = pWin->drawable.pScreen;
+
 #ifdef PANORAMIX
         if (!noPanoramiXExtension) {
             XineramaConfineCursorToWindow(pDev, pWin, generateEvents);
@@ -893,6 +895,9 @@ ConfineCursorToWindow(DeviceIntPtr pDev, WindowPtr pWin, Bool generateEvents,
             : NullRegion;
         CheckPhysLimits(pDev, pSprite->current, generateEvents,
                         confineToScreen, pWin->drawable.pScreen);
+
+        if (*pScreen->CursorConfinedTo)
+            (*pScreen->CursorConfinedTo) (pDev, pScreen, pWin);
     }
 }
 
diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index faf9f8d..f898392 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -241,6 +241,10 @@ typedef void (*CursorWarpedToProcPtr) (DeviceIntPtr /* pDev */ ,
                                        int /*x */ ,
                                        int /*y */ );
 
+typedef void (*CurserConfinedToProcPtr) (DeviceIntPtr /* pDev */ ,
+                                         ScreenPtr /*pScreen */ ,
+                                         WindowPtr /*pWindow */ );
+
 typedef Bool (*CreateGCProcPtr) (GCPtr /*pGC */ );
 
 typedef Bool (*CreateColormapProcPtr) (ColormapPtr /*pColormap */ );
@@ -563,6 +567,7 @@ typedef struct _Screen {
     RecolorCursorProcPtr RecolorCursor;
     SetCursorPositionProcPtr SetCursorPosition;
     CursorWarpedToProcPtr CursorWarpedTo;
+    CurserConfinedToProcPtr CursorConfinedTo;
 
     /* GC procedures */
 

commit daf48a3aba7d5c42d7156f0d0e2b1d8aae423303
Author: Jonas Ådahl <jadahl@gmail.com>
Date:   Tue Sep 13 15:16:55 2016 +0800

    dix: Introduce CursorWarpedTo vfunc in Screen
    
    This new vfunc will be called, if set, after a client has issued a
    WarpPointer request. This is necessary for implementing pointer warp
    emulation in Xwayland.
    
    Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
    Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
    Signed-off-by: Keith Packard <keithp@keithp.com>

diff --git a/dix/events.c b/dix/events.c
index 6610b91..87f080e 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -3609,6 +3609,9 @@ ProcWarpPointer(ClientPtr client)
     else if (!PointerConfinedToScreen(dev)) {
         NewCurrentScreen(dev, newScreen, x, y);
     }
+    if (*newScreen->CursorWarpedTo)
+        (*newScreen->CursorWarpedTo) (dev, newScreen, client,
+                                      dest, pSprite, x, y);
     return Success;
 }
 
diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index 52e8382..faf9f8d 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -233,6 +233,14 @@ typedef Bool (*SetCursorPositionProcPtr) (DeviceIntPtr /* pDev */ ,
                                           int /*y */ ,
                                           Bool /*generateEvent */ );
 
+typedef void (*CursorWarpedToProcPtr) (DeviceIntPtr /* pDev */ ,
+                                       ScreenPtr /*pScreen */ ,
+                                       ClientPtr /*pClient */ ,
+                                       WindowPtr /*pWindow */ ,
+                                       SpritePtr /*pSprite */ ,
+                                       int /*x */ ,
+                                       int /*y */ );
+
 typedef Bool (*CreateGCProcPtr) (GCPtr /*pGC */ );
 
 typedef Bool (*CreateColormapProcPtr) (ColormapPtr /*pColormap */ );
@@ -554,6 +562,7 @@ typedef struct _Screen {
     UnrealizeCursorProcPtr UnrealizeCursor;
     RecolorCursorProcPtr RecolorCursor;
     SetCursorPositionProcPtr SetCursorPosition;
+    CursorWarpedToProcPtr CursorWarpedTo;
 
     /* GC procedures */
 

commit 3ef51c5c74297937002668b0c507fa88550db67e
Author: Keith Packard <keithp@keithp.com>
Date:   Fri Sep 16 10:03:49 2016 -0700

    Bump version to 1.18.99.2
    
    Prepare for 1.19 RC1
    
    Signed-off-by: Keith Packard <keithp@keithp.com>

diff --git a/configure.ac b/configure.ac
index 4b2b4f6..190e473 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.18.99.1, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
-RELEASE_DATE="2015-11-09"
-RELEASE_NAME="Ouzo"
+AC_INIT([xorg-server], 1.18.99.2, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
+RELEASE_DATE="2016-09-16"
+RELEASE_NAME="Marionberry Pie"
 AC_CONFIG_SRCDIR([Makefile.am])
 AC_CONFIG_MACRO_DIR([m4])
 AM_INIT_AUTOMAKE([foreign dist-bzip2])

commit 86038dfd42d6f6da9646ef2f87b2ab8ccba98e02
Author: Keith Packard <keithp@keithp.com>
Date:   Fri Sep 16 10:56:15 2016 -0700

    os: Add 'ospoll.h' to Makefile.am
    
    Distribute this source file.
    
    Signed-off-by: Keith Packard <keithp@keithp.com>

diff --git a/os/Makefile.am b/os/Makefile.am
index d97ba30..b5fb9d0 100644
--- a/os/Makefile.am
+++ b/os/Makefile.am
@@ -23,6 +23,7 @@ libos_la_SOURCES = 	\
 	osdep.h		\
 	osinit.c	\
 	ospoll.c	\
+	ospoll.h	\
 	utils.c		\
 	xdmauth.c	\
 	xsha1.c		\

commit 56972d007dcde93693cb9e39931978b744942e5b
Author: Keith Packard <keithp@keithp.com>
Date:   Fri Sep 16 10:55:27 2016 -0700

    include: Add 'xserver_poll.h' to Makefile.am
    
    Make sure this file is included in the tarball.
    
    Signed-off-by: Keith Packard <keithp@keithp.com>

diff --git a/include/Makefile.am b/include/Makefile.am
index 05f8d24..cbc4a7c 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -60,6 +60,7 @@ sdk_HEADERS =		\
 	xkbsrv.h	\
 	xkbstr.h        \
 	xkbrules.h      \
+	xserver_poll.h	\
 	xserver-properties.h
 
 nodist_sdk_HEADERS = xorg-server.h

commit 61b159f5a79130a9661064d3f0143e5d6107985a
Author: Keith Packard <keithp@keithp.com>
Date:   Fri Sep 16 10:54:37 2016 -0700

    hw/xwin: Add 'dri' to DIST_SUBDIRS
    
    This creates the needed Makefile.in files during 'make dist' or 'make
    distcheck'
    
    Signed-off-by: Keith Packard <keithp@keithp.com>

diff --git a/hw/xwin/Makefile.am b/hw/xwin/Makefile.am
index 50b4d9f..0846230 100644
--- a/hw/xwin/Makefile.am
+++ b/hw/xwin/Makefile.am
@@ -197,4 +197,4 @@ relink:
 	$(AM_V_at)rm -f XWin$(EXEEXT) && $(MAKE) XWin$(EXEEXT)
 
 SUBDIRS = man $(GLX_DIR) winclipboard .
-DIST_SUBDIRS = man glx winclipboard .
+DIST_SUBDIRS = man dri glx winclipboard .

commit 93f474e49b24abc673cb9cf5ea16fac296dce312
Author: Keith Packard <keithp@keithp.com>
Date:   Fri Sep 16 10:43:09 2016 -0700

    Remove 'dixfontstubs.h' from include EXTRA_DIST
    
    This file was removed when moving to the new libXfont API, but
    accidentally left in EXTRA_DIST.
    
    Signed-off-by: Keith Packard <keithp@keithp.com>

diff --git a/include/Makefile.am b/include/Makefile.am
index b9cf584..05f8d24 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -70,7 +70,7 @@ AM_CFLAGS = $(DIX_CFLAGS)
 EXTRA_DIST = 	\
 	busfault.h dbus-core.h \
 	dix-config-apple-verbatim.h \
-	dixfontstubs.h eventconvert.h eventstr.h inpututils.h \
+	eventconvert.h eventstr.h inpututils.h \
 	probes.h \
 	protocol-versions.h \
 	swaprep.h \

commit 5b9f3ea2501a886fb74e5248e82a95e76443f1e8
Author: Michel Dänzer <michel.daenzer@amd.com>
Date:   Thu Jan 14 18:09:44 2016 +0900

    xfree86/modes: Set RandR primary output from CreateScreenResources
    
    Fixes XRRGetOutputPrimary and xrandr not reporting a primary output after
    startup. This was especially confusing when an output was explicitly
    marked as primary using Option "Primary" in Section "Monitor".
    
    Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
    Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
    Signed-off-by: Keith Packard <keithp@keithp.com>

diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index b136123..d34bce2 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -1748,6 +1748,7 @@ xf86RandR12CreateScreenResources12(ScreenPtr pScreen)
 {
     int c;
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
+    rrScrPrivPtr rp = rrGetScrPriv(pScreen);
     xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
 
     if (xf86RandR12Key == NULL)
@@ -1760,6 +1761,13 @@ xf86RandR12CreateScreenResources12(ScreenPtr pScreen)
                          config->maxWidth, config->maxHeight);
 
     xf86RandR12CreateMonitors(pScreen);
+
+    if (!pScreen->isGPU) {
+        rp->primaryOutput = config->output[0]->randr_output;
+        RROutputChanged(rp->primaryOutput, FALSE);
+        rp->layoutChanged = TRUE;
+    }
+
     return TRUE;
 }
 

commit bd8ecd9be1568b59258b6d2f78530ede345b7c7a
Author: Michel Dänzer <michel.daenzer@amd.com>
Date:   Fri Sep 16 09:51:31 2016 -0700

    Add SyncSharedPixmap ScreenRec hook
    
    Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
    Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
    Signed-off-by: Keith Packard <keithp@keithp.com>

diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index 5330714..52e8382 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -347,6 +347,24 @@ typedef Bool (*SharePixmapBackingProcPtr)(PixmapPtr, ScreenPtr, void **);
 
 typedef Bool (*SetSharedPixmapBackingProcPtr)(PixmapPtr, void *);
 
+#define HAS_SYNC_SHARED_PIXMAP 1
+/* The SyncSharedPixmap hook has two purposes:
+ *
+ * 1. If the master driver has it, the slave driver can use it to
+ * synchronize the shared pixmap contents with the screen pixmap.
+ * 2. If the slave driver has it, the master driver can expect the slave
+ * driver to call the master screen's SyncSharedPixmap hook, so the master
+ * driver doesn't have to synchronize the shared pixmap contents itself,
+ * e.g. from the BlockHandler.
+ *
+ * A driver must only set the hook if it handles both cases correctly.
+ *
+ * The argument is the slave screen's pixmap_dirty_list entry, the hook is
+ * responsible for finding the corresponding entry in the master screen's
+ * pixmap_dirty_list.
+ */
+typedef void (*SyncSharedPixmapProcPtr)(PixmapDirtyUpdatePtr);
+
 typedef Bool (*StartPixmapTrackingProcPtr)(PixmapPtr, PixmapPtr,
                                            int x, int y,
                                            int dst_x, int dst_y,
@@ -616,6 +634,7 @@ typedef struct _Screen {
 
     StartPixmapTrackingProcPtr StartPixmapTracking;
     StopPixmapTrackingProcPtr StopPixmapTracking;
+    SyncSharedPixmapProcPtr SyncSharedPixmap;
 
     SharedPixmapNotifyDamageProcPtr SharedPixmapNotifyDamage;
     RequestSharedPixmapNotifyDamageProcPtr RequestSharedPixmapNotifyDamage;

commit 7f6fa4e449f5a7215bbf60ce8c874e163a7453a9
Author: Qiang Yu <Qiang.Yu@amd.com>
Date:   Mon Sep 5 18:05:42 2016 +0800

    modesetting: fix compile error when --disable-glamor
    
    Move ms_flush_drm_events out of GLAMOR ifdef.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=97586
    Signed-off-by: Qiang Yu <Qiang.Yu@amd.com>
    Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
    Signed-off-by: Keith Packard <keithp@keithp.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index aa00d05..eee96e5 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -161,8 +161,6 @@ typedef void (*ms_pageflip_handler_proc)(modesettingPtr ms,
 
 typedef void (*ms_pageflip_abort_proc)(modesettingPtr ms, void *data);
 
-int ms_flush_drm_events(ScreenPtr screen);
-
 Bool ms_do_pageflip(ScreenPtr screen,
                     PixmapPtr new_front,
                     void *event,
@@ -172,3 +170,5 @@ Bool ms_do_pageflip(ScreenPtr screen,
                     ms_pageflip_abort_proc pageflip_abort);
 
 #endif
+
+int ms_flush_drm_events(ScreenPtr screen);
diff --git a/hw/xfree86/drivers/modesetting/pageflip.c b/hw/xfree86/drivers/modesetting/pageflip.c
index a82e0d6..4dc05ec 100644
--- a/hw/xfree86/drivers/modesetting/pageflip.c
+++ b/hw/xfree86/drivers/modesetting/pageflip.c
@@ -29,6 +29,40 @@
 
 #include "driver.h"
 
+/*
+ * 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.
+ */
+int
+ms_flush_drm_events(ScreenPtr screen)
+{
+    ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+    modesettingPtr ms = modesettingPTR(scrn);
+
+    struct pollfd p = { .fd = ms->fd, .events = POLLIN };
+    int r;
+
+    do {
+            r = xserver_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 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;
+
+    /* Otherwise return 1 to indicate that we handled an event. */
+    return 1;
+}
+
 #ifdef GLAMOR
 
 /*
@@ -125,40 +159,6 @@ ms_pageflip_abort(void *data)
     ms_pageflip_free(flip);
 }
 
-/*
- * 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.
- */
-int
-ms_flush_drm_events(ScreenPtr screen)
-{
-    ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
-    modesettingPtr ms = modesettingPTR(scrn);
-
-    struct pollfd p = { .fd = ms->fd, .events = POLLIN };
-    int r;
-
-    do {
-            r = xserver_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 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;
-
-    /* Otherwise return 1 to indicate that we handled an event. */
-    return 1;
-}
-
 static Bool
 queue_flip_on_crtc(ScreenPtr screen, xf86CrtcPtr crtc,
                    struct ms_flipdata *flipdata,

commit d81f9ce12aa4ac54b9c2b8c74c2f827c1f3e739a
Author: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
Date:   Sun Sep 11 03:07:44 2016 -0700

    dix/dispatch: Fix SmartScheduleClient interval adjustment to use best rather than pClient
    
    pClient does not contain a live value after the transition to lists
    
    https://bugs.freedesktop.org/show_bug.cgi?id=97765
    
    Application Specific Information:
    X.Org X Server 1.18.99.1 Build Date: 20160910
    =================================================================
    ==16921==ERROR: AddressSanitizer: global-buffer-overflow on address 0x000108ce3834 at pc 0x000108880766 bp 0x7000045f76c0 sp 0x7000045f76b8
    READ of size 4 at 0x000108ce3834 thread T6
        #0 0x108880765 in SmartScheduleClient dispatch.c:365
        #1 0x10887ecc5 in Dispatch dispatch.c:422
        #2 0x1088c05f1 in dix_main main.c:301
        #3 0x1082aabba in server_thread quartzStartup.c:66
        #4 0x7fffc5f16aaa in _pthread_body (libsystem_pthread.dylib+0x3aaa)
        #5 0x7fffc5f169f6 in _pthread_start (libsystem_pthread.dylib+0x39f6)
        #6 0x7fffc5f161fc in thread_start (libsystem_pthread.dylib+0x31fc)
    
    Regressed-in: 8f1edf4bd3a1f050ce9eeb5eac45dd1a8f7a6d5e
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
    Reviewed-by: Keith Packard <keithp@keithp.com>
    Signed-off-by: Keith Packard <keithp@keithp.com>

diff --git a/dix/dispatch.c b/dix/dispatch.c
index 0edcfee..26a461b 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -362,7 +362,7 @@ SmartScheduleClient(void)
          * has run, bump the slice up to get maximal
          * performance from a single client
          */
-        if ((now - pClient->smart_start_tick) > 1000 &&
+        if ((now - best->smart_start_tick) > 1000 &&
             SmartScheduleSlice < SmartScheduleMaxSlice) {
             SmartScheduleSlice += SmartScheduleInterval;
         }

commit 3caf671ed2a8a79856409a109355fc0f393d7aed
Author: Keith Packard <keithp@keithp.com>
Date:   Wed Sep 14 22:40:32 2016 -0700

    config/dbus: Initialize dbus fd to -1 so teardown doesn't use fd 0
    
    The dbus teardown code is called when the server fatal errors even if
    that is before dbus has ever been initialized.  By statically
    initializing the value of bus_info.fd, we avoid calling RemoveNotifyFd
    on stdin.
    
    Signed-off-by: Keith Packard <keithp@keithp.com>
    Reviewed-by: Julien Cristau <jcristau@debian.org>
    Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>

diff --git a/config/dbus-core.c b/config/dbus-core.c
index 3c85ad7..6d9a3f9 100644
--- a/config/dbus-core.c
+++ b/config/dbus-core.c
@@ -43,7 +43,7 @@ struct dbus_core_info {
     OsTimerPtr timer;
     struct dbus_core_hook *hooks;
 };
-static struct dbus_core_info bus_info;
+static struct dbus_core_info bus_info = { .fd = -1 };
 
 static CARD32 reconnect_timer(OsTimerPtr timer, CARD32 time, void *arg);
 

commit f5f4d32ac7c250cfbfb94883ce7d7e46151e89f0
Author: Jon Turney <jon.turney@dronecode.org.uk>
Date:   Thu Jul 24 12:29:41 2014 +0100

    Add Windows-DRI extension
    
    If windowsdriproto headers are available, build a Windows-DRI extension,
    which supports requests to enable local clients to directly render GL to a
    Windows drawable:
    
    - a query to check if WGL is being used on a screen
    - a query to map a fbconfigID to a native pixelformatindex
    - a query to map a drawable to a native handle
    
    Windows-DRI can only be useful if we are using WGL, so make an note if WGL
    is active on a screen.
    
    Make validGlxDrawable() public
    
    Adjust glxWinSetPixelFormat() so it doesn't require a context, just a
    screen and config.
    
    That enables factoring out the deferred drawable creation code as
    glxWinDeferredCreateDrawable()
    
    Enhance glxWinDeferredCreateDrawable(), so that pixmaps are placed into a
    file mapping, so they exist in memory which can be shared with the direct
    rendering process.
    
    Currently, this file mapping is accessed by a name generated from the XID.
    This will not be unique across multiple server instances. It would perhaps
    be better, although more complicated, to use an anonymous file mapping, and
    then duplicate the handle for the direct rendering process.
    
    Use glxWinDeferredCreateDrawable() to ensure the native handle exists for
    the Windows-DRI query to map a drawable to native handle.
    
    v2:
    Various printf format warning fixes
    
    v3:
    Fix format warnings on x86
    Move some uninteresting windows-dri output to debug log level
    
    v4:
    check for windowsdriproto when  --enable-windowsdri
    use windowsdriproto_CFLAGS
    
    Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
    Reviewed-by: Colin Harrison <colin.harrison@virgin.net>

diff --git a/configure.ac b/configure.ac
index 4ff317f..4b2b4f6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -637,6 +637,7 @@ AC_ARG_ENABLE(vgahw,          AS_HELP_STRING([--enable-vgahw], [Build Xorg with
 AC_ARG_ENABLE(vbe,            AS_HELP_STRING([--enable-vbe], [Build Xorg with VBE module (default: enabled)]), [VBE=$enableval], [VBE=yes])
 AC_ARG_ENABLE(int10-module,     AS_HELP_STRING([--enable-int10-module], [Build Xorg with int10 module (default: enabled)]), [INT10MODULE=$enableval], [INT10MODULE=yes])
 AC_ARG_ENABLE(windowswm,      AS_HELP_STRING([--enable-windowswm], [Build XWin with WindowsWM extension (default: no)]), [WINDOWSWM=$enableval], [WINDOWSWM=no])
+AC_ARG_ENABLE(windowsdri,     AS_HELP_STRING([--enable-windowsdri], [Build XWin with WindowsDRI extension (default: auto)]), [WINDOWSDRI=$enableval], [WINDOWSDRI=auto])
 AC_ARG_ENABLE(libdrm,         AS_HELP_STRING([--enable-libdrm], [Build Xorg with libdrm support (default: enabled)]), [DRM=$enableval],[DRM=yes])
 AC_ARG_ENABLE(clientids,      AS_HELP_STRING([--disable-clientids], [Build Xorg with client ID tracking (default: enabled)]), [CLIENTIDS=$enableval], [CLIENTIDS=yes])
 AC_ARG_ENABLE(pciaccess, AS_HELP_STRING([--enable-pciaccess], [Build Xorg with pciaccess library (default: enabled)]), [PCI=$enableval], [PCI=yes])
@@ -2230,6 +2231,13 @@ if test "x$XWIN" = xyes; then
 		AC_DEFINE(ROOTLESS,1,[Build Rootless code])
 	fi
 
+	if test "x$WINDOWSDRI" = xauto; then
+		PKG_CHECK_EXISTS([windowsdriproto], [WINDOWSDRI=yes], [WINDOWSDRI=no])
+	fi
+	if test "x$WINDOWSDRI" = xyes ; then
+		PKG_CHECK_MODULES(WINDOWSDRI, [windowsdriproto])
+	fi
+
 	case $host_os in
 		cygwin*)
 			XWIN_SERVER_NAME=XWin
@@ -2283,6 +2291,7 @@ AM_CONDITIONAL(XWIN_MULTIWINDOW, [test "x$XWIN" = xyes])
 AM_CONDITIONAL(XWIN_MULTIWINDOWEXTWM, [test "x$XWIN" = xyes && test "x$WINDOWSWM" = xyes])
 AM_CONDITIONAL(XWIN_CLIPBOARD, [test "x$XWIN" = xyes])
 AM_CONDITIONAL(XWIN_GLX_WINDOWS, [test "x$XWIN" = xyes && test "x$AIGLX" = xyes])
+AM_CONDITIONAL(XWIN_WINDOWS_DRI, [test "x$XWIN" = xyes && test "x$WINDOWSDRI" = xyes])
 AM_CONDITIONAL(XWIN_RANDR, [test "x$XWIN" = xyes])
 AM_CONDITIONAL(XWIN_XV, [test "x$XWIN" = xyes && test "x$XV" = xyes])
 
@@ -2685,6 +2694,7 @@ hw/vfb/man/Makefile
 hw/xnest/Makefile
 hw/xnest/man/Makefile
 hw/xwin/Makefile
+hw/xwin/dri/Makefile
 hw/xwin/glx/Makefile
 hw/xwin/man/Makefile
 hw/xwin/winclipboard/Makefile
diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index 481dfb9..5873cb4 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -146,7 +146,7 @@ validGlxContext(ClientPtr client, XID id, int access_mode,
     return TRUE;
 }
 
-static int
+int
 validGlxDrawable(ClientPtr client, XID id, int type, int access_mode,
                  __GLXdrawable ** drawable, int *err)
 {
diff --git a/glx/glxdrawable.h b/glx/glxdrawable.h
index 0076589..441d72d 100644
--- a/glx/glxdrawable.h
+++ b/glx/glxdrawable.h
@@ -74,4 +74,7 @@ struct __GLXdrawable {
     unsigned long eventMask;
 };
 
+extern int validGlxDrawable(ClientPtr client, XID id, int type, int access_mode,
+                            __GLXdrawable **drawable, int *err);
+
 #endif                          /* !__GLX_drawable_h__ */
diff --git a/hw/xwin/InitOutput.c b/hw/xwin/InitOutput.c
index 4621012..edd5266 100644
--- a/hw/xwin/InitOutput.c
+++ b/hw/xwin/InitOutput.c
@@ -66,6 +66,7 @@ typedef WINAPI HRESULT(*SHGETFOLDERPATHPROC) (HWND hwndOwner,
 #include "glx_extinit.h"
 #ifdef XWIN_GLX_WINDOWS
 #include "glx/glwindows.h"
+#include "dri/windowsdri.h"
 #endif
 
 /*
@@ -117,6 +118,9 @@ const int NUMFORMATS = sizeof(g_PixmapFormats) / sizeof(g_PixmapFormats[0]);
 static const ExtensionModule xwinExtensions[] = {
 #ifdef GLXEXT
   { GlxExtensionInit, "GLX", &noGlxExtension },
+#ifdef XWIN_WINDOWS_DRI
+  { WindowsDRIExtensionInit, "Windows-DRI", &noDriExtension },
+#endif
 #endif
 };
 
diff --git a/hw/xwin/Makefile.am b/hw/xwin/Makefile.am
index 4da3d12..50b4d9f 100644
--- a/hw/xwin/Makefile.am
+++ b/hw/xwin/Makefile.am
@@ -9,9 +9,17 @@ CLIPBOARD_LIBS = $(top_builddir)/hw/xwin/winclipboard/libXWinclipboard.la
 endif
 
 if XWIN_GLX_WINDOWS
-GLX_DIR = glx
-DEFS_GLX_WINDOWS = -DXWIN_GLX_WINDOWS
-XWIN_GLX_LIBS = $(top_builddir)/hw/xwin/glx/libXwinGLX.la
+GLX_DIR =
+DEFS_GLX_WINDOWS =
+XWIN_GLX_LIBS =
+if XWIN_WINDOWS_DRI
+GLX_DIR += dri
+DEFS_GLX_WINDOWS += -DXWIN_WINDOWS_DRI
+XWIN_GLX_LIBS += $(top_builddir)/hw/xwin/dri/libWindowsDRI.la
+endif
+GLX_DIR += glx
+DEFS_GLX_WINDOWS += -DXWIN_GLX_WINDOWS
+XWIN_GLX_LIBS += $(top_builddir)/hw/xwin/glx/libXwinGLX.la
 XWIN_GLX_SYS_LIBS = -lopengl32
 endif
 
diff --git a/hw/xwin/dri/Makefile.am b/hw/xwin/dri/Makefile.am
new file mode 100644
index 0000000..948c2b5
--- /dev/null
+++ b/hw/xwin/dri/Makefile.am
@@ -0,0 +1,9 @@
+noinst_LTLIBRARIES = libWindowsDRI.la
+
+libWindowsDRI_la_SOURCES = \
+	windowsdri.c \
+	windowsdri.h
+
+AM_CFLAGS =  $(DIX_CFLAGS) \
+	     @WINDOWSDRI_CFLAGS@ \
+	     -I$(top_srcdir)/hw/xwin/
diff --git a/hw/xwin/dri/windowsdri.c b/hw/xwin/dri/windowsdri.c
new file mode 100644
index 0000000..3666e97
--- /dev/null
+++ b/hw/xwin/dri/windowsdri.c
@@ -0,0 +1,274 @@
+/*
+ * Copyright © 2014 Jon Turney
+ *
+ * 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.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include <X11/extensions/windowsdristr.h>
+
+#include "dixstruct.h"
+#include "extnsionst.h"
+#include "scrnintstr.h"
+#include "swaprep.h"
+#include "protocol-versions.h"
+#include "windowsdri.h"
+#include "glx/dri_helpers.h"
+
+static int WindowsDRIErrorBase = 0;
+static unsigned char WindowsDRIReqCode = 0;
+static int WindowsDRIEventBase = 0;
+
+static void
+WindowsDRIResetProc(ExtensionEntry* extEntry)
+{
+}
+
+static int
+ProcWindowsDRIQueryVersion(ClientPtr client)
+{
+    xWindowsDRIQueryVersionReply rep;
+
+    REQUEST_SIZE_MATCH(xWindowsDRIQueryVersionReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.majorVersion = SERVER_WINDOWSDRI_MAJOR_VERSION;
+    rep.minorVersion = SERVER_WINDOWSDRI_MINOR_VERSION;
+    rep.patchVersion = SERVER_WINDOWSDRI_PATCH_VERSION;
+    if (client->swapped) {
+        swaps(&rep.sequenceNumber);
+        swapl(&rep.length);
+        swaps(&rep.majorVersion);
+        swaps(&rep.minorVersion);
+        swapl(&rep.patchVersion);
+    }
+    WriteToClient(client, sizeof(xWindowsDRIQueryVersionReply), &rep);
+    return Success;
+}
+
+static int
+ProcWindowsDRIQueryDirectRenderingCapable(ClientPtr client)
+{
+    xWindowsDRIQueryDirectRenderingCapableReply rep;
+
+    REQUEST(xWindowsDRIQueryDirectRenderingCapableReq);
+    REQUEST_SIZE_MATCH(xWindowsDRIQueryDirectRenderingCapableReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+
+    if (!client->local)
+        rep.isCapable = 0;
+    else
+        rep.isCapable = glxWinGetScreenAiglxIsActive(screenInfo.screens[stuff->screen]);
+
+    if (client->swapped) {
+        swaps(&rep.sequenceNumber);
+        swapl(&rep.length);
+    }
+
+    WriteToClient(client,
+                  sizeof(xWindowsDRIQueryDirectRenderingCapableReply),
+                  &rep);
+    return Success;
+}
+
+static int
+ProcWindowsDRIQueryDrawable(ClientPtr client)
+{
+    xWindowsDRIQueryDrawableReply rep;
+    int rc;
+
+    REQUEST(xWindowsDRIQueryDrawableReq);
+    REQUEST_SIZE_MATCH(xWindowsDRIQueryDrawableReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+
+    rc = glxWinQueryDrawable(client, stuff->drawable, &(rep.drawable_type), &(rep.handle));
+
+    if (rc)
+        return rc;
+
+    if (client->swapped) {
+        swaps(&rep.sequenceNumber);
+        swapl(&rep.length);
+        swapl(&rep.handle);
+        swapl(&rep.drawable_type);
+    }
+
+    WriteToClient(client, sizeof(xWindowsDRIQueryDrawableReply), &rep);
+    return Success;
+}
+
+static int
+ProcWindowsDRIFBConfigToPixelFormat(ClientPtr client)
+{
+    xWindowsDRIFBConfigToPixelFormatReply rep;
+
+    REQUEST(xWindowsDRIFBConfigToPixelFormatReq);
+    REQUEST_SIZE_MATCH(xWindowsDRIFBConfigToPixelFormatReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+
+    rep.pixelFormatIndex = glxWinFBConfigIDToPixelFormatIndex(stuff->screen, stuff->fbConfigID);
+
+    if (client->swapped) {
+        swaps(&rep.sequenceNumber);
+        swapl(&rep.length);
+        swapl(&rep.pixelFormatIndex);
+    }
+
+    WriteToClient(client, sizeof(xWindowsDRIFBConfigToPixelFormatReply), &rep);
+    return Success;
+}
+
+/* dispatch */
+
+static int
+ProcWindowsDRIDispatch(ClientPtr client)
+{
+    REQUEST(xReq);
+
+    switch (stuff->data) {
+    case X_WindowsDRIQueryVersion:
+        return ProcWindowsDRIQueryVersion(client);
+
+    case X_WindowsDRIQueryDirectRenderingCapable:
+        return ProcWindowsDRIQueryDirectRenderingCapable(client);
+    }
+
+    if (!client->local)
+        return WindowsDRIErrorBase + WindowsDRIClientNotLocal;
+
+    switch (stuff->data) {
+    case X_WindowsDRIQueryDrawable:
+        return ProcWindowsDRIQueryDrawable(client);
+
+    case X_WindowsDRIFBConfigToPixelFormat:
+        return ProcWindowsDRIFBConfigToPixelFormat(client);
+
+    default:
+        return BadRequest;
+    }
+}
+
+static void
+SNotifyEvent(xWindowsDRINotifyEvent *from,
+             xWindowsDRINotifyEvent *to)
+{
+    to->type = from->type;
+    to->kind = from->kind;
+    cpswaps(from->sequenceNumber, to->sequenceNumber);
+    cpswapl(from->time, to->time);
+}
+
+static int
+SProcWindowsDRIQueryVersion(ClientPtr client)
+{
+    REQUEST(xWindowsDRIQueryVersionReq);
+    swaps(&stuff->length);
+    return ProcWindowsDRIQueryVersion(client);
+}
+
+static int
+SProcWindowsDRIQueryDirectRenderingCapable(ClientPtr client)
+{
+    REQUEST(xWindowsDRIQueryDirectRenderingCapableReq);
+    swaps(&stuff->length);
+    swapl(&stuff->screen);
+    return ProcWindowsDRIQueryDirectRenderingCapable(client);
+}
+
+static int
+SProcWindowsDRIQueryDrawable(ClientPtr client)
+{
+    REQUEST(xWindowsDRIQueryDrawableReq);
+    swaps(&stuff->length);
+    swapl(&stuff->screen);
+    swapl(&stuff->drawable);
+    return ProcWindowsDRIQueryDrawable(client);
+}
+
+static int
+SProcWindowsDRIFBConfigToPixelFormat(ClientPtr client)
+{
+    REQUEST(xWindowsDRIFBConfigToPixelFormatReq);
+    swaps(&stuff->length);
+    swapl(&stuff->screen);
+    swapl(&stuff->fbConfigID);
+    return ProcWindowsDRIFBConfigToPixelFormat(client);
+}
+
+static int
+SProcWindowsDRIDispatch(ClientPtr client)
+{
+    REQUEST(xReq);
+
+    switch (stuff->data) {
+    case X_WindowsDRIQueryVersion:
+        return SProcWindowsDRIQueryVersion(client);
+
+    case X_WindowsDRIQueryDirectRenderingCapable:
+        return SProcWindowsDRIQueryDirectRenderingCapable(client);
+    }
+
+    if (!client->local)
+        return WindowsDRIErrorBase + WindowsDRIClientNotLocal;
+
+    switch (stuff->data) {
+    case X_WindowsDRIQueryDrawable:
+        return SProcWindowsDRIQueryDrawable(client);
+
+    case X_WindowsDRIFBConfigToPixelFormat:
+        return SProcWindowsDRIFBConfigToPixelFormat(client);
+
+    default:
+        return BadRequest;
+    }
+}
+
+void
+WindowsDRIExtensionInit(void)
+{
+    ExtensionEntry* extEntry;
+
+    if ((extEntry = AddExtension(WINDOWSDRINAME,
+                                 WindowsDRINumberEvents,
+                                 WindowsDRINumberErrors,
+                                 ProcWindowsDRIDispatch,
+                                 SProcWindowsDRIDispatch,
+                                 WindowsDRIResetProc,
+                                 StandardMinorOpcode))) {
+        size_t i;
+        WindowsDRIReqCode = (unsigned char)extEntry->base;
+        WindowsDRIErrorBase = extEntry->errorBase;
+        WindowsDRIEventBase = extEntry->eventBase;


Reply to: