b487c7d
From 1dd898dc07dadbb2f115bbb177bb52d05bea2df3 Mon Sep 17 00:00:00 2001
b487c7d
From: Dave Airlie <airlied@redhat.com>
b487c7d
Date: Mon, 3 Aug 2009 14:09:32 +1000
b487c7d
Subject: TO git xserver-1.6.99-git-e94c7c42ce.patch
b487c7d
b487c7d
---
b487c7d
diff --git a/configure.ac b/configure.ac
b487c7d
index f19b6fe..69d6abb 100644
b487c7d
--- a/configure.ac
b487c7d
+++ b/configure.ac
b487c7d
@@ -709,7 +709,7 @@ XEXTXORG_LIB='$(top_builddir)/Xext/libXextbuiltin.la'
b487c7d
 
b487c7d
 dnl Core modules for most extensions, et al.
b487c7d
 REQUIRED_MODULES="[randrproto >= 1.2.99.3] [renderproto >= 0.11] [fixesproto >= 4.0] [damageproto >= 1.1] xcmiscproto [xextproto >= 7.0.99.3] [xproto >= 7.0.13] [xtrans >= 1.2.2] bigreqsproto resourceproto fontsproto [inputproto >= 1.9.99.15] [kbproto >= 1.0.3]"
b487c7d
-REQUIRED_LIBS="xfont xau fontenc [pixman-1 >= 0.15.14]"
b487c7d
+REQUIRED_LIBS="xfont xau [pixman-1 >= 0.15.14]"
b487c7d
 
b487c7d
 dnl HAVE_DBUS is true if we actually have the D-Bus library, whereas
b487c7d
 dnl CONFIG_DBUS_API is true if we want to enable the D-Bus config
b487c7d
diff --git a/exa/exa.c b/exa/exa.c
b487c7d
index c8fe12e..483e3b4 100644
b487c7d
--- a/exa/exa.c
b487c7d
+++ b/exa/exa.c
b487c7d
@@ -336,7 +336,7 @@ ExaDoPrepareAccess(DrawablePtr pDrawable, int index)
b487c7d
     if (!offscreen) {
b487c7d
 	/* Do we need to allocate our system buffer? */
b487c7d
 	if ((pExaScr->info->flags & EXA_HANDLES_PIXMAPS) && (pExaScr->info->flags & EXA_MIXED_PIXMAPS)) {
b487c7d
-	    if (!pExaPixmap->sys_ptr) {
b487c7d
+	    if (!pExaPixmap->sys_ptr && !exaPixmapIsPinned(pPixmap)) {
b487c7d
 		pExaPixmap->sys_ptr = malloc(pExaPixmap->sys_pitch * pDrawable->height);
b487c7d
 		if (!pExaPixmap->sys_ptr)
b487c7d
 		    FatalError("EXA: malloc failed for size %d bytes\n", pExaPixmap->sys_pitch * pDrawable->height);
b487c7d
diff --git a/exa/exa_migration_mixed.c b/exa/exa_migration_mixed.c
b487c7d
index 915bed9..ed0cc14 100644
b487c7d
--- a/exa/exa_migration_mixed.c
b487c7d
+++ b/exa/exa_migration_mixed.c
b487c7d
@@ -32,32 +32,37 @@
b487c7d
 #include "exa.h"
b487c7d
 
b487c7d
 static void
b487c7d
-exaUploadFallback(PixmapPtr pPixmap, CARD8 *src, int src_pitch,
b487c7d
-	      CARD8 *dst, int dst_pitch)
b487c7d
- {
b487c7d
+exaUploadFallback(PixmapPtr pPixmap, CARD8 *src, int src_pitch)
b487c7d
+{
b487c7d
     ExaPixmapPriv(pPixmap);
b487c7d
     RegionPtr damage = DamageRegion (pExaPixmap->pDamage);
b487c7d
-    int i, cpp = pPixmap->drawable.bitsPerPixel / 8;
b487c7d
-    int bytes, nbox;
b487c7d
+    GCPtr pGC = GetScratchGC (pPixmap->drawable.depth,
b487c7d
+		pPixmap->drawable.pScreen);
b487c7d
+    int nbox, cpp = pPixmap->drawable.bitsPerPixel / 8;
b487c7d
+    DamagePtr backup = pExaPixmap->pDamage;
b487c7d
     BoxPtr pbox;
b487c7d
+    CARD8 *src2;
b487c7d
+
b487c7d
+    /* We don't want damage optimisations. */
b487c7d
+    pExaPixmap->pDamage = NULL;
b487c7d
+    ValidateGC (&pPixmap->drawable, pGC);
b487c7d
 
b487c7d
     pbox = REGION_RECTS(damage);
b487c7d
     nbox = REGION_NUM_RECTS(damage);
b487c7d
 
b487c7d
     while (nbox--) {
b487c7d
-	bytes = (pbox->x2 - pbox->x1) * cpp;
b487c7d
+	src2 = src + pbox->y1 * src_pitch + pbox->x1 * cpp;
b487c7d
 
b487c7d
-	src += pbox->y1 * src_pitch + pbox->x1 * cpp;
b487c7d
-	dst += pbox->y1 * dst_pitch + pbox->x1 * cpp;
b487c7d
-
b487c7d
-	for (i = pbox->y2 - pbox->y1; i; i--) {
b487c7d
-	    memcpy (dst, src, bytes);
b487c7d
-	    src += src_pitch;
b487c7d
-	    dst += dst_pitch;
b487c7d
-	}
b487c7d
+	ExaCheckPutImage(&pPixmap->drawable, pGC,
b487c7d
+	    pPixmap->drawable.depth, pbox->x1, pbox->y1,
b487c7d
+	    pbox->x2 - pbox->x1, pbox->y2 - pbox->y1, 0,
b487c7d
+	    ZPixmap, (char*) src2);
b487c7d
 
b487c7d
 	pbox++;
b487c7d
     }
b487c7d
+
b487c7d
+    FreeScratchGC (pGC);
b487c7d
+    pExaPixmap->pDamage = backup;
b487c7d
 }
b487c7d
 
b487c7d
 void
b487c7d
@@ -99,7 +104,8 @@ exaCreateDriverPixmap_mixed(PixmapPtr pPixmap)
b487c7d
 	return;
b487c7d
 
b487c7d
     pExaPixmap->offscreen = TRUE;
b487c7d
-    pExaPixmap->sys_ptr = NULL;
b487c7d
+    pExaPixmap->sys_ptr = pPixmap->devPrivate.ptr = NULL;
b487c7d
+    pExaPixmap->sys_pitch = pPixmap->devKind = 0;
b487c7d
 
b487c7d
     pExaPixmap->score = EXA_PIXMAP_SCORE_PINNED;
b487c7d
     (*pScreen->ModifyPixmapHeader)(pPixmap, w, h, 0, 0,
b487c7d
@@ -130,10 +136,7 @@ exaCreateDriverPixmap_mixed(PixmapPtr pPixmap)
b487c7d
     goto finish;
b487c7d
 
b487c7d
 fallback:
b487c7d
-    ExaDoPrepareAccess(&pPixmap->drawable, EXA_PREPARE_DEST);
b487c7d
-    exaUploadFallback(pPixmap, sys_buffer, sys_pitch, pPixmap->devPrivate.ptr,
b487c7d
-	exaGetPixmapPitch(pPixmap));
b487c7d
-    exaFinishAccess(&pPixmap->drawable, EXA_PREPARE_DEST);
b487c7d
+    exaUploadFallback(pPixmap, sys_buffer, sys_pitch);
b487c7d
 
b487c7d
 finish:
b487c7d
     free(sys_buffer);
b487c7d
diff --git a/exa/exa_mixed.c b/exa/exa_mixed.c
b487c7d
index 47fa6d4..7ba62ea 100644
b487c7d
--- a/exa/exa_mixed.c
b487c7d
+++ b/exa/exa_mixed.c
b487c7d
@@ -82,12 +82,12 @@ exaCreatePixmap_mixed(ScreenPtr pScreen, int w, int h, int depth,
b487c7d
     datasize = h * paddedWidth;
b487c7d
 
b487c7d
     /* We will allocate the system pixmap later if needed. */
b487c7d
+    pPixmap->devPrivate.ptr = NULL;
b487c7d
     pExaPixmap->sys_ptr = NULL;
b487c7d
     pExaPixmap->sys_pitch = paddedWidth;
b487c7d
 
b487c7d
     pExaPixmap->area = NULL;
b487c7d
     pExaPixmap->offscreen = FALSE;
b487c7d
-    pExaPixmap->score = EXA_PIXMAP_SCORE_INIT;
b487c7d
     pExaPixmap->fb_ptr = NULL;
b487c7d
     pExaPixmap->pDamage = NULL;
b487c7d
 
b487c7d
@@ -95,19 +95,19 @@ exaCreatePixmap_mixed(ScreenPtr pScreen, int w, int h, int depth,
b487c7d
     exaSetAccelBlock(pExaScr, pExaPixmap,
b487c7d
 	w, h, bpp);
b487c7d
 
b487c7d
+    /* Avoid freeing sys_ptr. */
b487c7d
+    pExaPixmap->score = EXA_PIXMAP_SCORE_PINNED;
b487c7d
+
b487c7d
+    (*pScreen->ModifyPixmapHeader)(pPixmap, w, h, 0, 0,
b487c7d
+				    paddedWidth, NULL);
b487c7d
+
b487c7d
+    /* We want to be able to transfer the pixmap to driver memory later on. */
b487c7d
+    pExaPixmap->score = EXA_PIXMAP_SCORE_INIT;
b487c7d
+
b487c7d
     /* A scratch pixmap will become a driver pixmap right away. */
b487c7d
     if (!w || !h) {
b487c7d
 	exaCreateDriverPixmap_mixed(pPixmap);
b487c7d
     } else {
b487c7d
-	/* Avoid freeing sys_ptr. */
b487c7d
-	pExaPixmap->score = EXA_PIXMAP_SCORE_PINNED;
b487c7d
-
b487c7d
-	(*pScreen->ModifyPixmapHeader)(pPixmap, w, h, 0, 0,
b487c7d
-					paddedWidth, NULL);
b487c7d
-
b487c7d
-	/* We want to be able to copy the pixmap to driver memory later on. */
b487c7d
-	pExaPixmap->score = EXA_PIXMAP_SCORE_INIT;
b487c7d
-
b487c7d
 	/* Set up damage tracking */
b487c7d
 	pExaPixmap->pDamage = DamageCreate (NULL, NULL,
b487c7d
 					    DamageReportNone, TRUE,
b487c7d
@@ -145,20 +145,22 @@ exaModifyPixmapHeader_mixed(PixmapPtr pPixmap, int width, int height, int depth,
b487c7d
     pExaPixmap = ExaGetPixmapPriv(pPixmap);
b487c7d
 
b487c7d
     if (pExaPixmap) {
b487c7d
-        if (pPixData) {
b487c7d
-	    if (!exaPixmapIsPinned(pPixmap)) {
b487c7d
-		free(pExaPixmap->sys_ptr);
b487c7d
-
b487c7d
-		/* We no longer need this. */
b487c7d
-		if (pExaPixmap->pDamage) {
b487c7d
-		    DamageUnregister(&pPixmap->drawable, pExaPixmap->pDamage);
b487c7d
-		    DamageDestroy(pExaPixmap->pDamage);
b487c7d
-		    pExaPixmap->pDamage = NULL;
b487c7d
-		}
b487c7d
+	if (!exaPixmapIsPinned(pPixmap)) {
b487c7d
+	    free(pExaPixmap->sys_ptr);
b487c7d
+	    pExaPixmap->sys_ptr = pPixmap->devPrivate.ptr = NULL;
b487c7d
+	    pExaPixmap->sys_pitch = pPixmap->devKind = 0;
b487c7d
+
b487c7d
+	    /* We no longer need this. */
b487c7d
+	    if (pExaPixmap->pDamage) {
b487c7d
+		DamageUnregister(&pPixmap->drawable, pExaPixmap->pDamage);
b487c7d
+		DamageDestroy(pExaPixmap->pDamage);
b487c7d
+		pExaPixmap->pDamage = NULL;
b487c7d
 	    }
b487c7d
-            pExaPixmap->sys_ptr = pPixData;
b487c7d
 	}
b487c7d
 
b487c7d
+        if (pPixData)
b487c7d
+            pExaPixmap->sys_ptr = pPixData;
b487c7d
+
b487c7d
         if (devKind > 0)
b487c7d
             pExaPixmap->sys_pitch = devKind;
b487c7d
 
b487c7d
diff --git a/mi/mieq.c b/mi/mieq.c
b487c7d
index 6ec2dba..1b81e4d 100644
b487c7d
--- a/mi/mieq.c
b487c7d
+++ b/mi/mieq.c
b487c7d
@@ -159,26 +159,26 @@ mieqEnqueue(DeviceIntPtr pDev, InternalEvent *e)
b487c7d
 
b487c7d
     if (isMotion && isMotion == miEventQueue.lastMotion &&
b487c7d
         oldtail != miEventQueue.head) {
b487c7d
-	oldtail = (oldtail - 1) % QUEUE_SIZE;
b487c7d
+        oldtail = (oldtail - 1) % QUEUE_SIZE;
b487c7d
     }
b487c7d
     else {
b487c7d
-	static int stuck = 0;
b487c7d
-	/* Toss events which come in late.  Usually this means your server's
b487c7d
+        static int stuck = 0;
b487c7d
+        /* Toss events which come in late.  Usually this means your server's
b487c7d
          * stuck in an infinite loop somewhere, but SIGIO is still getting
b487c7d
          * handled. */
b487c7d
-	if (((oldtail + 1) % QUEUE_SIZE) == miEventQueue.head) {
b487c7d
-	    if (!stuck) {
b487c7d
+        if (((oldtail + 1) % QUEUE_SIZE) == miEventQueue.head) {
b487c7d
+            if (!stuck) {
b487c7d
                 ErrorF("[mi] EQ overflowing. The server is probably stuck "
b487c7d
                         "in an infinite loop.\n");
b487c7d
-		xorg_backtrace();
b487c7d
-		stuck = 1;
b487c7d
-	    }
b487c7d
+                xorg_backtrace();
b487c7d
+                stuck = 1;
b487c7d
+            }
b487c7d
 #ifdef XQUARTZ
b487c7d
-	    pthread_mutex_unlock(&miEventQueueMutex);
b487c7d
+            pthread_mutex_unlock(&miEventQueueMutex);
b487c7d
 #endif
b487c7d
-	    return;
b487c7d
+	        return;
b487c7d
         }
b487c7d
-	stuck = 0;
b487c7d
+        stuck = 0;
b487c7d
     }
b487c7d
 
b487c7d
     evlen = e->any.length;
b487c7d
@@ -225,7 +225,7 @@ mieqSwitchScreen(DeviceIntPtr pDev, ScreenPtr pScreen, Bool fromDIX)
b487c7d
 #endif
b487c7d
     EnqueueScreen(pDev) = pScreen;
b487c7d
     if (fromDIX)
b487c7d
-	DequeueScreen(pDev) = pScreen;
b487c7d
+        DequeueScreen(pDev) = pScreen;
b487c7d
 #ifdef XQUARTZ
b487c7d
     pthread_mutex_unlock(&miEventQueueMutex);
b487c7d
 #endif
b487c7d
@@ -267,8 +267,8 @@ ChangeDeviceID(DeviceIntPtr dev, InternalEvent* event)
b487c7d
             event->device.deviceid = dev->id;
b487c7d
             break;
b487c7d
 #if XFreeXDGA
b487c7d
-	case ET_DGAEvent:
b487c7d
-	    break;
b487c7d
+        case ET_DGAEvent:
b487c7d
+            break;
b487c7d
 #endif
b487c7d
         case ET_RawKeyPress:
b487c7d
         case ET_RawKeyRelease:
b487c7d
@@ -367,39 +367,48 @@ mieqProcessDeviceEvent(DeviceIntPtr dev,
b487c7d
     /* Custom event handler */
b487c7d
     handler = miEventQueue.handlers[event->any.type];
b487c7d
 
b487c7d
-    if (dev && screen && screen != DequeueScreen(dev) && !handler) {
b487c7d
-        /* Assumption - screen switching can only occur on motion events. */
b487c7d
-        DequeueScreen(dev) = screen;
b487c7d
-        x = event->device.root_x;
b487c7d
-        y = event->device.root_y;
b487c7d
-        NewCurrentScreen (dev, DequeueScreen(dev), x, y);
b487c7d
+    switch (event->any.type) {
b487c7d
+        /* Catch events that include valuator information and check if they
b487c7d
+         * are changing the screen */
b487c7d
+        case ET_Motion:
b487c7d
+        case ET_KeyPress:
b487c7d
+        case ET_KeyRelease:
b487c7d
+        case ET_ButtonPress:
b487c7d
+        case ET_ButtonRelease:
b487c7d
+            if (dev && screen && screen != DequeueScreen(dev) && !handler) {
b487c7d
+                DequeueScreen(dev) = screen;
b487c7d
+                x = event->device.root_x;
b487c7d
+                y = event->device.root_y;
b487c7d
+                NewCurrentScreen (dev, DequeueScreen(dev), x, y);
b487c7d
+            }
b487c7d
+            break;
b487c7d
+        default:
b487c7d
+            break;
b487c7d
     }
b487c7d
-    else {
b487c7d
-        master = CopyGetMasterEvent(dev, event, &mevent);
b487c7d
+    master = CopyGetMasterEvent(dev, event, &mevent);
b487c7d
 
b487c7d
-        if (master)
b487c7d
-            master->u.lastSlave = dev;
b487c7d
+    if (master)
b487c7d
+        master->u.lastSlave = dev;
b487c7d
 
b487c7d
-        /* If someone's registered a custom event handler, let them
b487c7d
-         * steal it. */
b487c7d
-        if (handler)
b487c7d
-        {
b487c7d
-            int screenNum = dev && DequeueScreen(dev) ? DequeueScreen(dev)->myNum : (screen ? screen->myNum : 0);
b487c7d
-            handler(screenNum, event, dev);
b487c7d
-            /* Check for the SD's master in case the device got detached
b487c7d
-             * during event processing */
b487c7d
-            if (master && dev->u.master)
b487c7d
-                handler(screenNum, &mevent, master);
b487c7d
-        } else
b487c7d
-        {
b487c7d
-            /* process slave first, then master */
b487c7d
-            dev->public.processInputProc(event, dev);
b487c7d
+    /* If someone's registered a custom event handler, let them
b487c7d
+     * steal it. */
b487c7d
+    if (handler)
b487c7d
+    {
b487c7d
+        int screenNum = dev && DequeueScreen(dev) ? DequeueScreen(dev)->myNum : (screen ? screen->myNum : 0);
b487c7d
+        handler(screenNum, event, dev);
b487c7d
+        /* Check for the SD's master in case the device got detached
b487c7d
+         * during event processing */
b487c7d
+        if (master && dev->u.master)
b487c7d
+            handler(screenNum, &mevent, master);
b487c7d
+    } else
b487c7d
+    {
b487c7d
+        /* process slave first, then master */
b487c7d
+        dev->public.processInputProc(event, dev);
b487c7d
 
b487c7d
-            /* Check for the SD's master in case the device got detached
b487c7d
-             * during event processing */
b487c7d
-            if (master && dev->u.master)
b487c7d
-                master->public.processInputProc(&mevent, master);
b487c7d
-        }
b487c7d
+        /* Check for the SD's master in case the device got detached
b487c7d
+         * during event processing */
b487c7d
+        if (master && dev->u.master)
b487c7d
+            master->public.processInputProc(&mevent, master);
b487c7d
     }
b487c7d
 }
b487c7d