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

xserver-xorg-video-i810: Changes to 'upstream-experimental'



 configure.ac           |   13 +
 man/intel.man          |   20 ++
 src/ch7017/Makefile.am |    2 
 src/ch7xxx/Makefile.am |    2 
 src/common.h           |    1 
 src/i810_accel.c       |    3 
 src/i810_dri.c         |    8 
 src/i810_driver.c      |    7 
 src/i830.h             |   15 +
 src/i830_accel.c       |    3 
 src/i830_common.h      |    6 
 src/i830_display.c     |   52 ++++++
 src/i830_display.h     |    3 
 src/i830_dri.c         |  421 ++++++++++++++++++++++++++++++++++---------------
 src/i830_dri.h         |    4 
 src/i830_driver.c      |  217 ++++++-------------------
 src/i830_memory.c      |   90 +++++++---
 src/i830_xaa.c         |    6 
 src/i965_render.c      |    1 
 src/ivch/Makefile.am   |    2 
 src/sil164/Makefile.am |    2 
 21 files changed, 542 insertions(+), 336 deletions(-)

New commits:
commit 1ed3843f73a0d8efa405daff3483ebe70bf6134f
Author: Eric Anholt <eric@anholt.net>
Date:   Mon Mar 12 17:47:32 2007 -0700

    Make the 965 use Y-major tiling for the depth buffer, as required by the spec.
    
    An example of the failure can be seen with the reflect demo when set to
    depth buffer mode.
    
    Reported by:	Haihao Xiang <haihao.xiang@intel.com>

diff --git a/src/i830_memory.c b/src/i830_memory.c
index e5168e1..0742d8c 100644
--- a/src/i830_memory.c
+++ b/src/i830_memory.c
@@ -1122,12 +1122,19 @@ i830_allocate_depthbuffer(ScrnInfoPtr pS
     /* First try allocating it tiled */
     if (!pI830->disableTiling && IsTileable(pScrn, pitch))
     {
+	enum tile_format tile_format;
+
 	size = ROUND_TO_PAGE(pitch * ALIGN(height, 16));
 
+	/* The 965 requires that the depth buffer be in Y Major format, while
+	 * the rest appear to fail when handed that format.
+	 */
+	tile_format = IS_I965G(pI830) ? TILING_YMAJOR: TILING_XMAJOR;
+
 	pI830->depth_buffer =
 	    i830_allocate_memory_tiled(pScrn, "depth buffer", size, pitch,
 				       GTT_PAGE_SIZE, ALIGN_BOTH_ENDS,
-				       TILING_XMAJOR);
+				       tile_format);
 	pI830->depth_tiled = FENCE_XMAJOR;
     }
 

commit 7aa257154685bd2520649ce87a3a84e55644d02c
Author: Michel Dänzer <michel@tungstengraphics.com>
Date:   Mon Mar 12 19:00:14 2007 +0100

    Fix build against released libdrm.

diff --git a/src/i830_dri.c b/src/i830_dri.c
index 96061bd..8fae4b7 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -83,6 +83,23 @@ #include "i830_dri.h"
 
 #include "i915_drm.h"
 
+/* This block and the corresponding configure test can be removed when
+ * libdrm >= 2.3.1 is required.
+ */
+#ifndef HAVE_I915_FLIP
+
+#define DRM_VBLANK_FLIP 0x8000000
+
+typedef struct drm_i915_flip {
+   int pipes;
+} drm_i915_flip_t;
+
+#undef DRM_IOCTL_I915_FLIP
+#define DRM_IOCTL_I915_FLIP DRM_IOW(DRM_COMMAND_BASE + DRM_I915_FLIP, \
+				    drm_i915_flip_t)
+
+#endif
+
 #include "dristruct.h"
 
 static char I830KernelDriverName[] = "i915";
@@ -1510,23 +1527,6 @@ I830DRITransitionTo3d(ScreenPtr pScreen)
    I830DRISetPfMask(pScreen, pI830->allowPageFlip ? 0x3 : 0);
 }
 
-/* This block and the corresponding configure test can be removed when
- * libdrm >= 2.3.1 is required.
- */
-#ifndef HAVE_I915_FLIP
-
-#define DRM_VBLANK_FLIP 0x8000000
-
-typedef struct drm_i915_flip {
-   int pipes;
-} drm_i915_flip_t;
-
-#undef DRM_IOCTL_I915_FLIP
-#define DRM_IOCTL_I915_FLIP DRM_IOW(DRM_COMMAND_BASE + DRM_I915_FLIP, \
-				    drm_i915_flip_t)
-
-#endif
-
 static void
 I830DRITransitionTo2d(ScreenPtr pScreen)
 {

commit 7c561956a28e90667fef140bc3cfa0edca464f15
Author: Michel Dänzer <michel@tungstengraphics.com>
Date:   Mon Mar 12 18:55:27 2007 +0100

    Defer flipping pages back to normal until the end of the DRI block handler.
    
    Doing it earlier can result in the wrong page being visible, giving the
    appearance of a frozen X server.

diff --git a/src/i830_dri.c b/src/i830_dri.c
index 5a3aec0..96061bd 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -1167,6 +1167,8 @@ #endif
    } else if (syncType == DRI_2D_SYNC &&
 	      oldContextType == DRI_NO_CONTEXT &&
 	      newContextType == DRI_2D_CONTEXT) {
+      drmI830Sarea *sPriv = (drmI830Sarea *) DRIGetSAREAPrivate(pScreen);
+
       if (I810_DEBUG & DEBUG_VERBOSE_DRI)
 	 ErrorF("i830DRISwapContext (out)\n");
 
@@ -1194,6 +1196,33 @@ #endif
 
       I830EmitFlush(pScrn);
 
+#ifdef DAMAGE
+      /* Try flipping back to the front page if necessary */
+      if (sPriv && !sPriv->pf_enabled && sPriv->pf_current_page != 0) {
+	 drm_i915_flip_t flip = { .pipes = 0 };
+
+	 if (sPriv->pf_current_page & (0x3 << 2)) {
+	    sPriv->pf_current_page = sPriv->pf_current_page & 0x3;
+	    sPriv->pf_current_page |= (sPriv->third_handle ? 2 : 1) << 2;
+
+	    flip.pipes |= 0x2;
+	 }
+
+	 if (sPriv->pf_current_page & 0x3) {
+	    sPriv->pf_current_page = sPriv->pf_current_page & (0x3 << 2);
+	    sPriv->pf_current_page |= sPriv->third_handle ? 2 : 1;
+
+	    flip.pipes |= 0x1;
+	 }
+
+	 drmCommandWrite(pI830->drmSubFD, DRM_I915_FLIP, &flip, sizeof(flip));
+
+	 if (sPriv->pf_current_page != 0)
+	    xf86DrvMsg(pScreen->myNum, X_WARNING,
+		       "[dri] %s: kernel failed to unflip buffers.\n", __func__);
+      }
+#endif
+
       pI830->LockHeld = 0;
    } else if (I810_DEBUG & DEBUG_VERBOSE_DRI)
       ErrorF("i830DRISwapContext (other)\n");
@@ -1448,7 +1477,7 @@ I830DRISetPfMask(ScreenPtr pScreen, int 
       pSAREAPriv->pf_enabled = pI830->allowPageFlip;
       pSAREAPriv->pf_active = pfMask;
    } else
-      pSAREAPriv->pf_enabled = pSAREAPriv->pf_active = 0;
+      pSAREAPriv->pf_active = 0;
 }
 
 static void
@@ -1501,36 +1530,11 @@ #endif
 static void
 I830DRITransitionTo2d(ScreenPtr pScreen)
 {
-   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-   I830Ptr pI830 = I830PTR(pScrn);
    drmI830Sarea *sPriv = (drmI830Sarea *) DRIGetSAREAPrivate(pScreen);
 
-   /* Try flipping back to the front page if necessary */
-   if (sPriv->pf_current_page != 0) {
-      drm_i915_flip_t flip = { .pipes = 0 };
-
-      if (sPriv->pf_current_page & (0x3 << 2)) {
-	 sPriv->pf_current_page = sPriv->pf_current_page & 0x3;
-	 sPriv->pf_current_page |= (sPriv->third_handle ? 2 : 1) << 2;
-
-	 flip.pipes |= 0x2;
-      }
-
-      if (sPriv->pf_current_page & 0x3) {
-	 sPriv->pf_current_page = sPriv->pf_current_page & (0x3 << 2);
-	 sPriv->pf_current_page |= sPriv->third_handle ? 2 : 1;
-
-	 flip.pipes |= 0x1;
-      }
-
-      drmCommandWrite(pI830->drmSubFD, DRM_I915_FLIP, &flip, sizeof(flip));
-   }
-
-   if (sPriv->pf_current_page != 0)
-      xf86DrvMsg(pScreen->myNum, X_WARNING,
-		 "[dri] %s: kernel failed to unflip buffers.\n", __func__);
-
    I830DRISetPfMask(pScreen, 0);
+
+   sPriv->pf_enabled = 0;
 }
 
 static void

commit fe59ab9f562fd10118563d80eb3351a4d3b48b3f
Author: Michel Dänzer <michel@tungstengraphics.com>
Date:   Mon Mar 12 13:03:47 2007 +0100

    Disable page flipping if the DRM is older than 1.9.
    
    Older versions don't support the functionality we need.

diff --git a/src/i830_dri.c b/src/i830_dri.c
index 52c30eb..5a3aec0 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -687,6 +687,14 @@ #define REQ_MIN 1
 	       pI830->memory_manager = NULL;
 	    }
 	 }
+#ifdef DAMAGE
+	 if (pI830->allowPageFlip && pI830->drmMinor < 9) {
+	    xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
+		       "DRM version 1.9 or newer required for Page flipping. "
+		       "Disabling.\n");
+	    pI830->allowPageFlip = FALSE;
+	 }
+#endif	 
 	 drmFreeVersion(version);
       }
    }

commit ba55ff15df974197bebd871e28bb96d817ae41c7
Author: Michel Dänzer <michel@tungstengraphics.com>
Date:   Mon Mar 12 13:01:00 2007 +0100

    Fix attempt to flip pages back to normal when the last 3D window disappears.
    
    When this succeeds, 2D rendering does not have to be synchronized to back
    buffers until the next 3D window appears.

diff --git a/configure.ac b/configure.ac
index fbb9c64..52cc07b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -180,6 +180,14 @@ if test "$DRI" = yes; then
 	if test "$have_damage_h" = yes; then
 		AC_DEFINE(DAMAGE,1,[Use Damage extension])
 	fi
+
+	save_CFLAGS="$CFLAGS"
+	CFLAGS="$DRI_CFLAGS"
+	AC_CHECK_TYPE(drm_i915_flip_t,
+		      [AC_DEFINE(HAVE_I915_FLIP, 1,
+			         [Have drm_i915_flip_t and related definitions])],
+		      [], [#include <i915_drm.h>])
+	CFLAGS="$save_CFLAGS"
 fi
 
 AM_CONDITIONAL(VIDEO_DEBUG, test x$VIDEO_DEBUG = xyes)
diff --git a/src/i830_dri.c b/src/i830_dri.c
index f55fa71..52c30eb 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -81,6 +81,8 @@ #include "GL/glxtokens.h"
 #include "i830.h"
 #include "i830_dri.h"
 
+#include "i915_drm.h"
+
 #include "dristruct.h"
 
 static char I830KernelDriverName[] = "i915";
@@ -563,12 +565,13 @@ #if DRIINFO_MAJOR_VERSION > 5 || \
 #endif
    }
 
+   pDRIInfo->TransitionTo2d = I830DRITransitionTo2d;
+
 #if DRIINFO_MAJOR_VERSION > 5 || \
     (DRIINFO_MAJOR_VERSION == 5 && DRIINFO_MINOR_VERSION >= 1)
    if (!pDRIInfo->ClipNotify)
 #endif
    {
-      pDRIInfo->TransitionTo2d = I830DRITransitionTo2d;
       pDRIInfo->TransitionTo3d = I830DRITransitionTo3d;
       pDRIInfo->TransitionSingleToMulti3D = I830DRITransitionSingleToMulti3d;
       pDRIInfo->TransitionMultiToSingle3D = I830DRITransitionMultiToSingle3d;
@@ -1470,6 +1473,22 @@ I830DRITransitionTo3d(ScreenPtr pScreen)
    I830DRISetPfMask(pScreen, pI830->allowPageFlip ? 0x3 : 0);
 }
 
+/* This block and the corresponding configure test can be removed when
+ * libdrm >= 2.3.1 is required.
+ */
+#ifndef HAVE_I915_FLIP
+
+#define DRM_VBLANK_FLIP 0x8000000
+
+typedef struct drm_i915_flip {
+   int pipes;
+} drm_i915_flip_t;
+
+#undef DRM_IOCTL_I915_FLIP
+#define DRM_IOCTL_I915_FLIP DRM_IOW(DRM_COMMAND_BASE + DRM_I915_FLIP, \
+				    drm_i915_flip_t)
+
+#endif
 
 static void
 I830DRITransitionTo2d(ScreenPtr pScreen)
@@ -1479,10 +1498,27 @@ I830DRITransitionTo2d(ScreenPtr pScreen)
    drmI830Sarea *sPriv = (drmI830Sarea *) DRIGetSAREAPrivate(pScreen);
 
    /* Try flipping back to the front page if necessary */
-   if (sPriv->pf_current_page == 1)
-      drmCommandNone(pI830->drmSubFD, DRM_I830_FLIP);
+   if (sPriv->pf_current_page != 0) {
+      drm_i915_flip_t flip = { .pipes = 0 };
+
+      if (sPriv->pf_current_page & (0x3 << 2)) {
+	 sPriv->pf_current_page = sPriv->pf_current_page & 0x3;
+	 sPriv->pf_current_page |= (sPriv->third_handle ? 2 : 1) << 2;
+
+	 flip.pipes |= 0x2;
+      }
+
+      if (sPriv->pf_current_page & 0x3) {
+	 sPriv->pf_current_page = sPriv->pf_current_page & (0x3 << 2);
+	 sPriv->pf_current_page |= sPriv->third_handle ? 2 : 1;
+
+	 flip.pipes |= 0x1;
+      }
+
+      drmCommandWrite(pI830->drmSubFD, DRM_I915_FLIP, &flip, sizeof(flip));
+   }
 
-   if (sPriv->pf_current_page == 1)
+   if (sPriv->pf_current_page != 0)
       xf86DrvMsg(pScreen->myNum, X_WARNING,
 		 "[dri] %s: kernel failed to unflip buffers.\n", __func__);
 

commit c4a23c5ef8ce56ee0fe547fbc7c6623c021f801b
Author: Michel Dänzer <michel@tungstengraphics.com>
Date:   Sat Mar 10 16:15:33 2007 +0100

    Remove unused have3DWindows from pI830.

diff --git a/src/i830.h b/src/i830.h
index 82a4166..dc8041c 100644
--- a/src/i830.h
+++ b/src/i830.h
@@ -306,7 +306,6 @@ #ifdef XF86DRI
 
    int TexGranularity;
    int drmMinor;
-   Bool have3DWindows;
    int mmModeFlags;
    int mmSize;
 
diff --git a/src/i830_dri.c b/src/i830_dri.c
index 38e11e7..f55fa71 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -1468,7 +1468,6 @@ I830DRITransitionTo3d(ScreenPtr pScreen)
    I830Ptr pI830 = I830PTR(pScrn);
 
    I830DRISetPfMask(pScreen, pI830->allowPageFlip ? 0x3 : 0);
-   pI830->have3DWindows = 1;
 }
 
 
@@ -1488,8 +1487,6 @@ I830DRITransitionTo2d(ScreenPtr pScreen)
 		 "[dri] %s: kernel failed to unflip buffers.\n", __func__);
 
    I830DRISetPfMask(pScreen, 0);
-
-   pI830->have3DWindows = 0;
 }
 
 static void

commit 797aa6fcb1231587bde1efb47bc8430c4c8d8110
Author: Dave Airlie <airlied@linux.ie>
Date:   Sun Mar 11 12:58:50 2007 +1100

    fixup missing assert includes

diff --git a/src/i830_driver.c b/src/i830_driver.c
index 599edc3..1be9fdd 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -165,6 +165,7 @@ #ifndef PRINT_MODE_INFO
 #define PRINT_MODE_INFO 0
 #endif
 
+#include <assert.h>
 #include <string.h>
 #include <stdio.h>
 #include <unistd.h>
diff --git a/src/i830_memory.c b/src/i830_memory.c
index d6338ec..e5168e1 100644
--- a/src/i830_memory.c
+++ b/src/i830_memory.c
@@ -99,6 +99,7 @@ #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
+#include <assert.h>
 #include <string.h>
 
 #include "xf86.h"
diff --git a/src/i830_xaa.c b/src/i830_xaa.c
index 46ea7ec..3440341 100644
--- a/src/i830_xaa.c
+++ b/src/i830_xaa.c
@@ -48,6 +48,7 @@ #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
+#include <assert.h>
 #include "xf86.h"
 #include "xaarop.h"
 #include "i830.h"
diff --git a/src/i965_render.c b/src/i965_render.c
index 78f1146..8d06c22 100644
--- a/src/i965_render.c
+++ b/src/i965_render.c
@@ -30,6 +30,7 @@ #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
+#include <assert.h>
 #include "xf86.h"
 #include "i830.h"
 #include "i915_reg.h"

commit 43a80ef9094efcb49027c83f0e726f907fecfbb2
Author: Dave Airlie <airlied@linux.ie>
Date:   Sun Mar 11 12:58:26 2007 +1100

    fixup brace alignment for older X.org

diff --git a/src/i830_dri.c b/src/i830_dri.c
index 5293574..38e11e7 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -549,8 +549,8 @@ #endif
    pDRIInfo->MoveBuffers = I830DRIMoveBuffers;
    pDRIInfo->bufferRequests = DRI_ALL_WINDOWS;
 
-#if DRIINFO_MAJOR_VERSION == 5 && DRIINFO_MINOR_VERSION >= 1
    {
+#if DRIINFO_MAJOR_VERSION == 5 && DRIINFO_MINOR_VERSION >= 1
       int major, minor, patch;
 
       DRIQueryVersion(&major, &minor, &patch);

commit 0d33fd3d03cef3a7e63d88ae441354390b37a937
Author: Dave Airlie <airlied@linux.ie>
Date:   Sun Mar 11 12:58:02 2007 +1100

    add XMODES flags to the i2c drivers

diff --git a/src/ch7017/Makefile.am b/src/ch7017/Makefile.am
index 7fbb440..45bf699 100644
--- a/src/ch7017/Makefile.am
+++ b/src/ch7017/Makefile.am
@@ -3,7 +3,7 @@ # -module lets us name the module exactl
 # -avoid-version prevents gratuitous .0.0.0 version numbers on the end
 # _ladir passes a dummy rpath to libtool so the thing will actually link
 # TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc.
-AM_CFLAGS = @XORG_CFLAGS@ @DRI_CFLAGS@ -I$(srcdir)/.. -I$(srcdir)/../modes
+AM_CFLAGS = @XMODES_CFLAGS@ @XORG_CFLAGS@ @DRI_CFLAGS@ -I$(srcdir)/.. -I$(srcdir)/../modes
 
 ch7017_la_LTLIBRARIES = ch7017.la
 ch7017_la_LDFLAGS = -module -avoid-version
diff --git a/src/ch7xxx/Makefile.am b/src/ch7xxx/Makefile.am
index b827bf8..68f766c 100644
--- a/src/ch7xxx/Makefile.am
+++ b/src/ch7xxx/Makefile.am
@@ -3,7 +3,7 @@ # -module lets us name the module exactl
 # -avoid-version prevents gratuitous .0.0.0 version numbers on the end
 # _ladir passes a dummy rpath to libtool so the thing will actually link
 # TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc.
-AM_CFLAGS = @XORG_CFLAGS@ @DRI_CFLAGS@ -I$(srcdir)/.. -I$(srcdir)/../modes
+AM_CFLAGS = @XMODES_CFLAGS@ @XORG_CFLAGS@ @DRI_CFLAGS@ -I$(srcdir)/.. -I$(srcdir)/../modes
 
 ch7xxx_la_LTLIBRARIES = ch7xxx.la
 ch7xxx_la_LDFLAGS = -module -avoid-version
diff --git a/src/ivch/Makefile.am b/src/ivch/Makefile.am
index 40e2627..ace076c 100644
--- a/src/ivch/Makefile.am
+++ b/src/ivch/Makefile.am
@@ -3,7 +3,7 @@ # -module lets us name the module exactl
 # -avoid-version prevents gratuitous .0.0.0 version numbers on the end
 # _ladir passes a dummy rpath to libtool so the thing will actually link
 # TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc.
-AM_CFLAGS = @XORG_CFLAGS@ @DRI_CFLAGS@ -I$(srcdir)/.. -I$(srcdir)/../modes
+AM_CFLAGS = @XMODES_CFLAGS@ @XORG_CFLAGS@ @DRI_CFLAGS@ -I$(srcdir)/.. -I$(srcdir)/../modes
 
 ivch_la_LTLIBRARIES = ivch.la
 ivch_la_LDFLAGS = -module -avoid-version
diff --git a/src/sil164/Makefile.am b/src/sil164/Makefile.am
index 4cf717c..ac1b33c 100644
--- a/src/sil164/Makefile.am
+++ b/src/sil164/Makefile.am
@@ -3,7 +3,7 @@ # -module lets us name the module exactl
 # -avoid-version prevents gratuitous .0.0.0 version numbers on the end
 # _ladir passes a dummy rpath to libtool so the thing will actually link
 # TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc.
-AM_CFLAGS = @XORG_CFLAGS@ @DRI_CFLAGS@ -I$(srcdir)/.. -I$(srcdir)/../modes
+AM_CFLAGS = @XMODES_CFLAGS@ @XORG_CFLAGS@ @DRI_CFLAGS@ -I$(srcdir)/.. -I$(srcdir)/../modes
 
 sil164_la_LTLIBRARIES = sil164.la
 sil164_la_LDFLAGS = -module -avoid-version

commit 3c2d6e07bdf8daef6486b594aef0d22460eb2585
Author: Michel Dänzer <michel@tungstengraphics.com>
Date:   Fri Mar 9 23:49:46 2007 +0100

    Don't crash when the SAREA pointer is NULL.

diff --git a/src/i830_display.c b/src/i830_display.c
index 7855712..d230f74 100644
--- a/src/i830_display.c
+++ b/src/i830_display.c
@@ -395,6 +395,9 @@ #ifdef XF86DRI
     if (pI830->directRenderingEnabled) {
 	drmI830Sarea *sPriv = (drmI830Sarea *) DRIGetSAREAPrivate(pScrn->pScreen);
 
+	if (!sPriv)
+	    return;
+
 	switch (pipe) {
 	case 0:
 	    sPriv->pipeA_x = x;
@@ -516,6 +519,9 @@ #ifdef XF86DRI
 	drmI830Sarea *sPriv = (drmI830Sarea *) DRIGetSAREAPrivate(pScrn->pScreen);
 	Bool enabled = crtc->enabled && mode != DPMSModeOff;
 
+	if (!sPriv)
+	    return;
+
 	switch (pipe) {
 	case 0:
 	    sPriv->pipeA_w = enabled ? crtc->mode.HDisplay : 0;

commit 7518b8959ee7598f3526365a83ea7e143a5d6a4e
Author: Michel Dänzer <michel@tungstengraphics.com>
Date:   Fri Mar 9 19:50:03 2007 +0100

    Revert change accidentally included in previous commit.

diff --git a/src/i830_exa.c b/src/i830_exa.c
index dfc8f99..bef8fae 100644
--- a/src/i830_exa.c
+++ b/src/i830_exa.c
@@ -42,7 +42,7 @@ #ifdef I830DEBUG
 #define DEBUG_I830FALLBACK 1
 #endif
 
-#define ALWAYS_SYNC		0
+#define ALWAYS_SYNC		1
 
 #ifdef DEBUG_I830FALLBACK
 #define I830FALLBACK(s, arg...)				\

commit 1991a90ae90b388c914985d20d6f8c3637856e9a
Author: Michel Dänzer <michel@tungstengraphics.com>
Date:   Fri Mar 9 19:47:13 2007 +0100

    Update SAREA pipe sizes in i830_crtc_dpms instead of i830PipeSetBase.
    
    This allows setting the size to 0 when a pipe gets disabled.

diff --git a/src/i830_display.c b/src/i830_display.c
index 8a2494f..7855712 100644
--- a/src/i830_display.c
+++ b/src/i830_display.c
@@ -399,14 +399,10 @@ #ifdef XF86DRI
 	case 0:
 	    sPriv->pipeA_x = x;
 	    sPriv->pipeA_y = y;
-	    sPriv->pipeA_w = crtc->mode.HDisplay;
-	    sPriv->pipeA_h = crtc->mode.VDisplay;
 	    break;
 	case 1:
 	    sPriv->pipeB_x = x;
 	    sPriv->pipeB_y = y;
-	    sPriv->pipeB_w = crtc->mode.HDisplay;
-	    sPriv->pipeB_h = crtc->mode.VDisplay;
 	    break;
 	default:
 	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
@@ -514,6 +510,28 @@ i830_crtc_dpms(xf86CrtcPtr crtc, int mod
 	usleep(150);
 	break;
     }
+
+#ifdef XF86DRI
+    if (pI830->directRenderingEnabled) {
+	drmI830Sarea *sPriv = (drmI830Sarea *) DRIGetSAREAPrivate(pScrn->pScreen);
+	Bool enabled = crtc->enabled && mode != DPMSModeOff;
+
+	switch (pipe) {
+	case 0:
+	    sPriv->pipeA_w = enabled ? crtc->mode.HDisplay : 0;
+	    sPriv->pipeA_h = enabled ? crtc->mode.VDisplay : 0;
+	    break;
+	case 1:
+	    sPriv->pipeB_w = enabled ? crtc->mode.HDisplay : 0;
+	    sPriv->pipeB_h = enabled ? crtc->mode.VDisplay : 0;
+	    break;
+	default:
+	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+		       "Can't update pipe %d in SAREA\n", pipe);
+	    break;
+	}
+    }
+#endif
 }
 
 static Bool
diff --git a/src/i830_exa.c b/src/i830_exa.c
index bef8fae..dfc8f99 100644
--- a/src/i830_exa.c
+++ b/src/i830_exa.c
@@ -42,7 +42,7 @@ #ifdef I830DEBUG
 #define DEBUG_I830FALLBACK 1
 #endif
 
-#define ALWAYS_SYNC		1
+#define ALWAYS_SYNC		0
 
 #ifdef DEBUG_I830FALLBACK
 #define I830FALLBACK(s, arg...)				\

commit 14ee9195d203192d3f613919f230b20b900ffdba
Author: Eric Anholt <eric@anholt.net>
Date:   Wed Mar 7 13:00:03 2007 -0800

    Bug #10157: Fix cursor corruption on server regen.

diff --git a/src/i830_driver.c b/src/i830_driver.c
index 30558ac..18a05ef 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -2962,6 +2962,8 @@ #endif
       pI830->CursorInfoRec = 0;
    }
 
+   i830_reset_allocations(pScrn);
+
    if (I830IsPrimary(pScrn)) {
       xf86GARTCloseScreen(scrnIndex);
 

commit a5f0522b1d34236278861fe15bac2df099f0a2c7
Author: Alan Hourihane <alanh@fairlite.demon.co.uk>
Date:   Wed Mar 7 15:49:47 2007 +0000

    Add some additional checks when XAA is enabled.

diff --git a/src/i810_accel.c b/src/i810_accel.c
index efbe290..1f859b8 100644
--- a/src/i810_accel.c
+++ b/src/i810_accel.c
@@ -597,7 +597,8 @@ I810RefreshRing(ScrnInfoPtr pScrn)
    if (pI810->LpRing->space < 0)
       pI810->LpRing->space += pI810->LpRing->mem.Size;
 
-   pI810->AccelInfoRec->NeedToSync = TRUE;
+   if (pI810->AccelInfoRec)
+      pI810->AccelInfoRec->NeedToSync = TRUE;
 }
 
 /* Emit on gaining VT?
diff --git a/src/i810_dri.c b/src/i810_dri.c
index 3e32283..72718d3 100644
--- a/src/i810_dri.c
+++ b/src/i810_dri.c
@@ -222,6 +222,7 @@ I810InitVisualConfigs(ScreenPtr pScreen)
 	       pConfigs[i].redSize = 5;
 	       pConfigs[i].greenSize = 6;
 	       pConfigs[i].blueSize = 5;
+	       pConfigs[i].alphaSize = 0;
 	       pConfigs[i].redMask = 0x0000F800;
 	       pConfigs[i].greenMask = 0x000007E0;
 	       pConfigs[i].blueMask = 0x0000001F;
@@ -1173,7 +1174,9 @@ I810DRIInitBuffers(WindowPtr pWin, Regio
       pbox++;
    }
    I810SelectBuffer(pScrn, I810_SELECT_FRONT);
-   pI810->AccelInfoRec->NeedToSync = TRUE;
+
+   if (pI810->AccelInfoRec)
+   	pI810->AccelInfoRec->NeedToSync = TRUE;
 }
 
 /* This routine is a modified form of XAADoBitBlt with the calls to
@@ -1332,7 +1335,8 @@ I810DRIMoveBuffers(WindowPtr pParent, DD
       DEALLOCATE_LOCAL(pboxNew1);
    }
 
-   pI810->AccelInfoRec->NeedToSync = TRUE;
+   if (pI810->AccelInfoRec)
+	pI810->AccelInfoRec->NeedToSync = TRUE;
 }
 
 

commit 81722a21d232fa6cfb11fbe3d984abab50e89bcc
Author: Keith Packard <keithp@guitar.keithp.com>
Date:   Tue Mar 6 23:16:53 2007 -0800

    Remove usage of 'shadow' module. Use xf86CrtcScreenInit.
    
    With the new mode setting code, rotation is handled outside of the driver,
    so the old usage of the 'shadow' module is no longer needed. Code to
    initialize the crtc structures has been moved out of the driver and into the
    modes code.

diff --git a/src/common.h b/src/common.h
index 6e8ddbd..f596eb8 100644
--- a/src/common.h
+++ b/src/common.h
@@ -87,7 +87,6 @@ extern const char *I810ddcSymbols[];
 extern const char *I810fbSymbols[];
 extern const char *I810xaaSymbols[];
 extern const char *I810shadowFBSymbols[];
-extern const char *I810shadowSymbols[];
 #ifdef XF86DRI
 extern const char *I810driSymbols[];
 extern const char *I810drmSymbols[];
diff --git a/src/i810_driver.c b/src/i810_driver.c
index 04166b7..6666d7f 100644
--- a/src/i810_driver.c
+++ b/src/i810_driver.c
@@ -341,12 +341,6 @@ const char *I810driSymbols[] = {
 
 #endif /* I830_ONLY */
 
-const char *I810shadowSymbols[] = {
-    "shadowSetup",
-    "shadowAdd",
-    NULL
-};
-
 const char *I810i2cSymbols[] = {
     "xf86CreateI2CBusRec",
     "xf86I2CBusInit",
@@ -435,7 +429,6 @@ #ifdef XF86DRI
 			I810drmSymbols,
 			I810driSymbols,
 #endif
-			I810shadowSymbols,
 			I810shadowFBSymbols,
 			I810vbeSymbols, vbeOptionalSymbols,
 			I810ddcSymbols, I810int10Symbols, NULL);
diff --git a/src/i830_dri.c b/src/i830_dri.c
index f81251a..680a28e 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -108,10 +108,6 @@ static void I830DRITransitionTo3d(Screen
 static void I830DRITransitionMultiToSingle3d(ScreenPtr pScreen);
 static void I830DRITransitionSingleToMulti3d(ScreenPtr pScreen);
 
-#if 0
-static void I830DRIShadowUpdate (ScreenPtr pScreen, shadowBufPtr pBuf);
-#endif
-
 extern void GlxSetVisualConfigs(int nconfigs,
 				__GLXvisualConfig * configs,
 				void **configprivs);
@@ -981,16 +977,7 @@ I830DRIFinishScreenInit(ScreenPtr pScree
 
    DPRINTF(PFX, "I830DRIFinishScreenInit\n");
 
-   /* Have shadow run only while there is 3d active.
-    */
-#if 0
-   if (pI830->allowPageFlip && pI830->drmMinor >= 1) {
-      shadowAdd(pScreen, 0, I830DRIShadowUpdate, 0, 0, 0);
-   }
-   else
-#endif
-      pI830->allowPageFlip = 0;
-
+   pI830->allowPageFlip = 0;
 
    if (!DRIFinishScreenInit(pScreen))
       return FALSE;
@@ -1267,70 +1254,6 @@ #endif
  * allocate and free 3d-specific memory on demand.
  */
 
-
-
-
-
-/* Use the miext/shadow module to maintain a list of dirty rectangles.
- * These are blitted to the back buffer to keep both buffers clean
- * during page-flipping when the 3d application isn't fullscreen.
- *
- * Unlike most use of the shadow code, both buffers are in video
- * memory.
- *
- * An alternative to this would be to organize for all on-screen
- * drawing operations to be duplicated for the two buffers.  That
- * might be faster, but seems like a lot more work...
- */
-
-
-#if 0
-/* This should be done *before* XAA syncs,
- * Otherwise will have to sync again???
- */
-static void
-I830DRIShadowUpdate (ScreenPtr pScreen, shadowBufPtr pBuf)
-{
-   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-   I830Ptr pI830 = I830PTR(pScrn);
-   RegionPtr damage = &pBuf->damage;
-   int i, num =  REGION_NUM_RECTS(damage);
-   BoxPtr pbox = REGION_RECTS(damage);
-   drmI830Sarea *pSAREAPriv = DRIGetSAREAPrivate(pScreen);
-   int cmd, br13;
-
-   /* Don't want to do this when no 3d is active and pages are
-    * right-way-round :
-    */
-   if (!pSAREAPriv->pf_active && pSAREAPriv->pf_current_page == 0)
-      return;
-
-   br13 = (pScrn->displayWidth * pI830->cpp) | (0xcc << 16);
-
-   if (pScrn->bitsPerPixel == 32) {
-      cmd = (XY_SRC_COPY_BLT_CMD | XY_SRC_COPY_BLT_WRITE_ALPHA |
-	     XY_SRC_COPY_BLT_WRITE_RGB);
-      br13 |= 3 << 24;
-   } else {
-      cmd = (XY_SRC_COPY_BLT_CMD);
-      br13 |= 1 << 24;
-   }
-
-   for (i = 0 ; i < num ; i++, pbox++) {
-      BEGIN_LP_RING(8);
-      OUT_RING(cmd);
-      OUT_RING(br13);
-      OUT_RING((pbox->y1 << 16) | pbox->x1);
-      OUT_RING((pbox->y2 << 16) | pbox->x2);
-      OUT_RING(pI830->back_buffer->offset);
-      OUT_RING((pbox->y1 << 16) | pbox->x1);
-      OUT_RING(br13 & 0xffff);
-      OUT_RING(pI830->front_buffer->offset);
-      ADVANCE_LP_RING();
-   }
-}
-#endif
-
 static void
 I830EnablePageFlip(ScreenPtr pScreen)
 {
diff --git a/src/i830_driver.c b/src/i830_driver.c
index ada334b..30558ac 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -1297,17 +1297,6 @@ #endif
    I830SetupOutputs(pScrn);
 
    SaveHWState(pScrn);
-   /* Do an initial detection of the outputs while none are configured on yet.
-    * This will give us some likely legitimate response for later if both
-    * pipes are already allocated and we're asked to do a detect.
-    */
-   for (i = 0; i < xf86_config->num_output; i++) 
-   {
-      xf86OutputPtr	      output = xf86_config->output[i];
-
-      output->status = (*output->funcs->detect) (output);
-   }
-
    if (!xf86InitialConfiguration (pScrn, FALSE))
    {
       xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes.\n");
@@ -1414,13 +1403,6 @@ #endif
       pI830->SWCursor = TRUE;
    }
 
-   if (!xf86RandR12PreInit (pScrn))
-   {
-      xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "RandR initialization failure\n");
-      PreInitCleanup(pScrn);
-      return FALSE;
-   }	
-
    if (pScrn->modes == NULL) {
       xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No modes.\n");
       PreInitCleanup(pScrn);
@@ -1467,7 +1449,7 @@ #ifdef I830_USE_EXA
 
       memset(&req, 0, sizeof(req));
       req.majorversion = 2;
-      req.minorversion = 0;
+      req.minorversion = 1;
       if (!LoadSubModule(pScrn->module, "exa", NULL, NULL, NULL, &req,
 		&errmaj, &errmin)) {
 	 LoaderErrorMsg(NULL, "exa", errmaj, errmin);
@@ -1511,29 +1493,6 @@ #if defined(XF86DRI)
    }
 #endif
 
-   /* rotation requires the newer libshadow */
-   if (I830IsPrimary(pScrn)) {
-      int errmaj, errmin;
-      pI830->shadowReq.majorversion = 1;
-      pI830->shadowReq.minorversion = 1;
-
-      if (!LoadSubModule(pScrn->module, "shadow", NULL, NULL, NULL,
-			       &pI830->shadowReq, &errmaj, &errmin)) {
-         pI830->shadowReq.minorversion = 0;
-         if (!LoadSubModule(pScrn->module, "shadow", NULL, NULL, NULL,
-			       &pI830->shadowReq, &errmaj, &errmin)) {
-            LoaderErrorMsg(NULL, "shadow", errmaj, errmin);
-	    return FALSE;
-         }
-      }
-   } else {
-      I830Ptr pI8301 = I830PTR(pI830->entityPrivate->pScrn_1);
-      pI830->shadowReq.majorversion = pI8301->shadowReq.majorversion;
-      pI830->shadowReq.minorversion = pI8301->shadowReq.minorversion;
-      pI830->shadowReq.patchlevel = pI8301->shadowReq.patchlevel;
-   }
-   xf86LoaderReqSymLists(I810shadowSymbols, NULL);
-
    pI830->preinit = FALSE;
 
    return TRUE;
@@ -1942,22 +1901,6 @@ I830PointerMoved(int index, int x, int y
 }
 
 static Bool
-I830CreateScreenResources (ScreenPtr pScreen)
-{
-   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-   I830Ptr pI830 = I830PTR(pScrn);
-
-   pScreen->CreateScreenResources = pI830->CreateScreenResources;
-   if (!(*pScreen->CreateScreenResources)(pScreen))
-      return FALSE;
-
-   if (!xf86RandR12CreateScreenResources (pScreen))
-      return FALSE;
-
-   return TRUE;
-}
-
-static Bool
 I830InitFBManager(
     ScreenPtr pScreen,  
     BoxPtr FullBox
@@ -2685,38 +2628,12 @@ #endif
    pI830->CloseScreen = pScreen->CloseScreen;
    pScreen->CloseScreen = I830CloseScreen;
 
-   if (pI830->shadowReq.minorversion >= 1) {
-      /* Rotation */
-      xf86DrvMsg(pScrn->scrnIndex, X_INFO, "RandR enabled, ignore the following RandR disabled message.\n");
-      xf86DisableRandR(); /* Disable built-in RandR extension */
-      shadowSetup(pScreen);
-      /* support all rotations */
-      xf86RandR12Init (pScreen);
-      if (pI830->useEXA) {
-#ifdef I830_USE_EXA
-	 if (pI830->EXADriverPtr->exa_minor >= 1) {
-	    xf86RandR12SetRotations (pScreen, RR_Rotate_0 | RR_Rotate_90 |
-				     RR_Rotate_180 | RR_Rotate_270);
-	 } else {
-	    xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
-		       "EXA version %d.%d too old to support rotation\n",
-		       pI830->EXADriverPtr->exa_major,
-		       pI830->EXADriverPtr->exa_minor);
-	    xf86RandR12SetRotations (pScreen, RR_Rotate_0);
-	 }
-#endif /* I830_USE_EXA */
-      } else {
-	 xf86RandR12SetRotations (pScreen, RR_Rotate_0 | RR_Rotate_90 |
-				  RR_Rotate_180 | RR_Rotate_270);
-      }
-      pI830->PointerMoved = pScrn->PointerMoved;
-      pScrn->PointerMoved = I830PointerMoved;
-      pI830->CreateScreenResources = pScreen->CreateScreenResources;
-      pScreen->CreateScreenResources = I830CreateScreenResources;
-   } else {
-      /* Rotation */
-      xf86DrvMsg(pScrn->scrnIndex, X_INFO, "libshadow is version %d.%d.%d, required 1.1.0 or greater for rotation.\n",pI830->shadowReq.majorversion,pI830->shadowReq.minorversion,pI830->shadowReq.patchlevel);
-   }
+   if (!xf86CrtcScreenInit (pScreen))
+       return FALSE;
+       
+   /* Wrap pointer motion to flip touch screen around */
+   pI830->PointerMoved = pScrn->PointerMoved;
+   pScrn->PointerMoved = I830PointerMoved;
 
    if (serverGeneration == 1)
       xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);

commit 04f50961e2f1610c39e7e4b45811f2a6b517cad6
Author: Eric Anholt <eric@anholt.net>
Date:   Tue Mar 6 14:23:06 2007 -0800

    Bug #9898: Fix a crash with NoAccel set.

diff --git a/src/i830_driver.c b/src/i830_driver.c
index bc6e07c..ada334b 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -537,8 +537,10 @@ I830MapMem(ScrnInfoPtr pScrn)
    if (!pI830->FbBase)
       return FALSE;
 
-   if (I830IsPrimary(pScrn))
-   pI830->LpRing->virtual_start = pI830->FbBase + pI830->LpRing->mem->offset;
+   if (I830IsPrimary(pScrn) && pI830->LpRing->mem != NULL) {
+      pI830->LpRing->virtual_start =
+	 pI830->FbBase + pI830->LpRing->mem->offset;
+   }
 
    return TRUE;
 }

commit b07dfbba5df7728232b38211c623185116dcea5c
Author: Eric Anholt <eric@anholt.net>
Date:   Tue Mar 6 13:59:14 2007 -0800

    Remove leftover code that was disabling tiling after we set it up.

diff --git a/src/i830_driver.c b/src/i830_driver.c
index 1aa06b9..bc6e07c 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -1913,18 +1913,6 @@ #endif
 }
 
 static void
-InitRegisterRec(ScrnInfoPtr pScrn)
-{
-   I830Ptr pI830 = I830PTR(pScrn);
-   int i;
-
-   if (!I830IsPrimary(pScrn)) return;
-
-   for (i = 0; i < 8; i++)
-      pI830->fence[i] = 0;
-}
-
-static void
 I830PointerMoved(int index, int x, int y)
 {
    ScrnInfoPtr pScrn = xf86Screens[index];
@@ -2505,8 +2493,6 @@ #ifdef I830_XV
    }
 #endif
 
-   InitRegisterRec(pScrn);
-
 #ifdef XF86DRI
    /*
     * pI830->directRenderingDisabled is set once in PreInit.  Reinitialise

commit 94c37f35872487c04136fb659526bffefd9c46ad
Author: Eric Anholt <eric@anholt.net>
Date:   Tue Mar 6 13:57:04 2007 -0800

    Make the depth buffer X tiled instead of Y, and fix a Y tiling nit on 945.
    
    The previous code claimed to set the depth buffer up as Y tiled, but due to
    lack of implementation in SetFence, it ended up being X tiled.  Actually
    setting the Y tiling flag in the new version broke the depth buffer, so just
    switch the depth buffer to X tiling, which appears to work fine.

diff --git a/src/i830_memory.c b/src/i830_memory.c
index ea6b90d..f0b50aa 100644
--- a/src/i830_memory.c
+++ b/src/i830_memory.c
@@ -1121,8 +1121,8 @@ i830_allocate_depthbuffer(ScrnInfoPtr pS
 	pI830->depth_buffer =
 	    i830_allocate_memory_tiled(pScrn, "depth buffer", size, pitch,
 				       GTT_PAGE_SIZE, ALIGN_BOTH_ENDS,
-				       TILING_YMAJOR);
-	pI830->depth_tiled = FENCE_YMAJOR;
+				       TILING_XMAJOR);
+	pI830->depth_tiled = FENCE_XMAJOR;
     }
 
     /* Otherwise, allocate it linear. */
@@ -1369,7 +1369,9 @@ i830_set_fence(ScrnInfoPtr pScrn, int nr
    	}
     }
 
-    if (IS_I9XX(pI830))
+    if ((IS_I945G(pI830) || IS_I945GM(pI830)) && tile_format == TILING_YMAJOR)
+	fence_pitch = pitch / 128;
+    else if (IS_I9XX(pI830))
 	fence_pitch = pitch / 512;
     else
 	fence_pitch = pitch / 128;

commit 30bb719ca0abc2599ffb89e59f297fa9a0a00c3c
Author: Eric Anholt <eric@anholt.net>
Date:   Tue Mar 6 12:23:43 2007 -0800

    Continue to allocate the legacy texture pool by default.
    
    This is a partial revert of 7358642e64ab6d13bc1dc1a44703ee66d715ff61
    
    If we don't allocate it now, when the DRM version is too low there won't be any
    memory allocated and DRI will fail.  Instead, waste the memory in the i915tex
    case for now, and leave fixing it right (check DRM version up front and decide
    which memory manager to set up) to later.

diff --git a/src/i830_driver.c b/src/i830_driver.c
index a27d805..1aa06b9 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -1234,14 +1234,13 @@ #ifdef XF86DRI
       pI830->mmModeFlags = 0;
 
       if (!pI830->directRenderingDisabled) {
+	 pI830->mmModeFlags = I830_KERNEL_TEX;
 #ifdef XF86DRI_MM
 	 Bool tmp = FALSE;
 
 	 if (!IS_I965G(pI830))
 	    pI830->mmModeFlags |= I830_KERNEL_MM;
-	 else
 #endif
-	    pI830->mmModeFlags |= I830_KERNEL_TEX;
 
 	 from = X_PROBED;
 

commit e972265261c421268e4fb806e587378d0adec577
Author: Michel Dänzer <michel@tungstengraphics.com>
Date:   Tue Mar 6 16:54:16 2007 +0100

    Fix build failure.
    
    Not sure how I missed this before... Thanks to Todd Merrill for reporting.

diff --git a/src/i830_dri.c b/src/i830_dri.c
index bb9de1e..9931acc 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -756,8 +756,9 @@ #endif
 	 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 		    "[drm] drmAddMap(third_handle) failed. Triple buffering "
 		    "inactive\n");
-	 i830_free_memory(pI830->third_buffer);
-	 sarea->third_handle = pI830->third_buffer = NULL;
+	 i830_free_memory(pScrn, pI830->third_buffer);
+	 pI830->third_buffer = NULL;
+	 sarea->third_handle = 0;
       } else
 	 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "[drm] Third Buffer = 0x%08x\n",
 		    (int)sarea->third_handle);

commit 1e1b45fa6ed1683cba4ae73ac98933e74c3ab9d6
Author: Michel Dänzer <michel@tungstengraphics.com>
Date:   Tue Mar 6 10:28:41 2007 +0100

    Fix reduced DRI memory manager size.
    
    pI830->mmSize is in kB.

diff --git a/src/i830_driver.c b/src/i830_driver.c
index 0977511..a27d805 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -2346,7 +2346,7 @@ #ifdef XF86DRI_MM
 	    /* For this allocation, switch to a smaller DRI memory manager
 	     * size.
 	     */
-	    pI830->mmSize = I830_MM_MINPAGES * GTT_PAGE_SIZE;
+	    pI830->mmSize = I830_MM_MINPAGES * GTT_PAGE_SIZE / KB(1);
 	 } else {
 	    pI830->mmSize = savedMMSize;
 	 }

commit 3c08bc7d6974a1a6cf5f9cb81898617032966c52
Author: Michel Dänzer <michel@tungstengraphics.com>
Date:   Tue Mar 6 10:14:47 2007 +0100

    Fix some conditionals related to triple buffering.
    
    Guard code that dereferences pI830->third_buffer with tests for that instead of
    pI830->TripleBuffer. It could happen that we want to enable triple buffering
    but (temporarily) can't because the third buffer couldn't be allocated.

diff --git a/src/i830_dri.c b/src/i830_dri.c
index d69ab3f..bb9de1e 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -748,18 +748,19 @@ #endif
    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "[drm] Back Buffer = 0x%08x\n",
               (int)sarea->back_handle);
 
-   if (pI830->TripleBuffer) {
+   if (pI830->third_buffer) {
       if (drmAddMap(pI830->drmSubFD,
 		    (drm_handle_t)(sarea->third_offset + pI830->LinearAddr),
 		    sarea->third_size, DRM_AGP, 0,
 		    (drmAddress) &sarea->third_handle) < 0) {
-	xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-		   "[drm] drmAddMap(third_handle) failed. Disabling DRI\n");
-	DRICloseScreen(pScreen);
-	return FALSE;
-      }
-      xf86DrvMsg(pScrn->scrnIndex, X_INFO, "[drm] Third Buffer = 0x%08x\n",
-		 (int)sarea->third_handle);
+	 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+		    "[drm] drmAddMap(third_handle) failed. Triple buffering "
+		    "inactive\n");
+	 i830_free_memory(pI830->third_buffer);
+	 sarea->third_handle = pI830->third_buffer = NULL;
+      } else
+	 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "[drm] Third Buffer = 0x%08x\n",
+		    (int)sarea->third_handle);
    }
 
    if (drmAddMap(pI830->drmSubFD,
@@ -1103,7 +1104,7 @@ I830DRIRefreshArea (ScrnInfoPtr pScrn, i
 
    I830DRIDoRefreshArea(pScrn, num, pbox, pI830->back_buffer->offset);
 
-   if (pI830->TripleBuffer) {
+   if (pI830->third_buffer) {
       I830DRIDoRefreshArea(pScrn, num, pbox, pI830->third_buffer->offset);
    }
 
@@ -1207,7 +1208,7 @@ I830DRIInitBuffers(WindowPtr pWin, Regio
       I830SubsequentSolidFillRect(pScrn, pbox->x1, pbox->y1,
 				  pbox->x2 - pbox->x1, pbox->y2 - pbox->y1);
 
-      if (I830PTR(pScrn)->TripleBuffer) {
+      if (I830PTR(pScrn)->third_buffer) {
 	 I830SelectBuffer(pScrn, I830_SELECT_THIRD);
 	 I830SubsequentSolidFillRect(pScrn, pbox->x1, pbox->y1,
 				     pbox->x2 - pbox->x1, pbox->y2 - pbox->y1);
@@ -1386,7 +1387,7 @@ #endif
 
       I830SelectBuffer(pScrn, I830_SELECT_BACK);
       I830SubsequentScreenToScreenCopy(pScrn, x1, y1, destx, desty, w, h);
-      if (pI830->TripleBuffer) {
+      if (pI830->third_buffer) {
 	 I830SelectBuffer(pScrn, I830_SELECT_THIRD);
 	 I830SubsequentScreenToScreenCopy(pScrn, x1, y1, destx, desty, w, h);
       }
@@ -1582,8 +1583,13 @@ I830UpdateDRIBuffers(ScrnInfoPtr pScrn, 
    sarea->height = pScreen->height;
    sarea->back_offset = pI830->back_buffer->offset;
    sarea->back_size = pI830->back_buffer->size;
-   sarea->third_offset = pI830->third_buffer->offset;
-   sarea->third_size = pI830->third_buffer->size;
+   if (pI830->third_buffer != NULL) {
+      sarea->third_offset = pI830->third_buffer->offset;
+      sarea->third_size = pI830->third_buffer->size;
+   } else {
+      sarea->third_offset = 0;
+      sarea->third_size = 0;
+   }
    sarea->depth_offset = pI830->depth_buffer->offset;
    sarea->depth_size = pI830->depth_buffer->size;
    if (pI830->textures != NULL) {

commit c25cfafbe1eb380b58b5fc16e94f5cc6f422f0cd
Author: Michel Dänzer <michel@tungstengraphics.com>
Date:   Tue Mar 6 10:00:12 2007 +0100

    Unify allocation of back buffers.

diff --git a/src/i830_memory.c b/src/i830_memory.c
index 17cad73..54cd6be 100644
--- a/src/i830_memory.c
+++ b/src/i830_memory.c
@@ -1064,7 +1064,8 @@ myLog2(unsigned int n)
 }
 
 static Bool
-i830_allocate_backbuffer(ScrnInfoPtr pScrn)
+i830_allocate_backbuffer(ScrnInfoPtr pScrn, i830_memory **buffer,
+			 unsigned int *tiled, const char *name)
 {
     I830Ptr pI830 = I830PTR(pScrn);
     unsigned int pitch = pScrn->displayWidth * pI830->cpp;
@@ -1080,69 +1081,23 @@ i830_allocate_backbuffer(ScrnInfoPtr pSc
     if (!pI830->disableTiling && IsTileable(pScrn, pitch))
     {
 	size = ROUND_TO_PAGE(pitch * ALIGN(height, 16));
-	pI830->back_buffer =
-	    i830_allocate_memory_tiled(pScrn, "back buffer",
-				       size, pitch, GTT_PAGE_SIZE,
-				       ALIGN_BOTH_ENDS,
-				       TILING_XMAJOR);
-	pI830->back_tiled = FENCE_XMAJOR;
+	*buffer = i830_allocate_memory_tiled(pScrn, name, size, pitch,
+					     GTT_PAGE_SIZE, ALIGN_BOTH_ENDS,
+					     TILING_XMAJOR);
+	*tiled = FENCE_XMAJOR;
     }
 
     /* Otherwise, just allocate it linear */
-    if (pI830->back_buffer == NULL) {
+    if (*buffer == NULL) {
 	size = ROUND_TO_PAGE(pitch * height);
-	pI830->back_buffer = i830_allocate_memory(pScrn, "back buffer",
-						  size, GTT_PAGE_SIZE,
-						  ALIGN_BOTH_ENDS);
-	pI830->back_tiled = FENCE_LINEAR;
+	*buffer = i830_allocate_memory(pScrn, name, size, GTT_PAGE_SIZE,
+				       ALIGN_BOTH_ENDS);
+	*tiled = FENCE_LINEAR;
     }
 
-    if (pI830->back_buffer == NULL) {
+    if (*buffer == NULL) {
 	xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
-		   "Failed to allocate back buffer space.\n");
-	return FALSE;
-    }
-
-    return TRUE;
-}
-
-static Bool
-i830_allocate_thirdbuffer(ScrnInfoPtr pScrn)
-{
-    I830Ptr pI830 = I830PTR(pScrn);
-    unsigned int pitch = pScrn->displayWidth * pI830->cpp;
-    unsigned long size;
-    int height;
-
-    if (pI830->rotation & (RR_Rotate_0 | RR_Rotate_180))
-	height = pScrn->virtualY;
-    else
-	height = pScrn->virtualX;
-
-    /* Try to allocate on the best tile-friendly boundaries. */
-    if (!pI830->disableTiling && IsTileable(pScrn, pitch))
-    {
-	size = ROUND_TO_PAGE(pitch * ALIGN(height, 16));
-	pI830->third_buffer =
-	    i830_allocate_memory_tiled(pScrn, "third buffer",
-				       size, pitch, GTT_PAGE_SIZE,
-				       ALIGN_BOTH_ENDS,
-				       TILING_XMAJOR);
-	pI830->third_tiled = FENCE_XMAJOR;
-    }
-
-    /* Otherwise, just allocate it linear */
-    if (pI830->third_buffer == NULL) {
-	size = ROUND_TO_PAGE(pitch * height);
-	pI830->third_buffer = i830_allocate_memory(pScrn, "third buffer",
-						   size, GTT_PAGE_SIZE,
-						   ALIGN_BOTH_ENDS);
-	pI830->third_tiled = FENCE_LINEAR;
-    }
-
-    if (pI830->third_buffer == NULL) {
-	xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
-		   "Failed to allocate third buffer space.\n");
+		   "Failed to allocate %s space.\n", name);
 	return FALSE;
     }
 
@@ -1246,10 +1201,14 @@ i830_allocate_3d_memory(ScrnInfoPtr pScr
 
     DPRINTF(PFX, "i830_allocate_3d_memory\n");
 
-    if (!i830_allocate_backbuffer(pScrn))
+    if (!i830_allocate_backbuffer(pScrn, &pI830->back_buffer,
+				  &pI830->back_tiled, "back buffer"))
 	return FALSE;
 
-    if (pI830->TripleBuffer && !i830_allocate_thirdbuffer(pScrn)) {
+    if (pI830->TripleBuffer && !i830_allocate_backbuffer(pScrn,
+							 &pI830->third_buffer,
+							 &pI830->third_tiled,
+							 "third buffer")) {
        xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
 		  "Failed to allocate third buffer, triple buffering "
 		  "inactive\n");

commit e787d7b698d320a7c45df35d58c5113413561fe2
Author: Michel Dänzer <michel@tungstengraphics.com>
Date:   Tue Mar 6 09:35:42 2007 +0100

    Remove warnings about potential artifacts with page flipping and mixed 2D/3D.
    
    The artifacts only seemed to occur when EXA was falling back to software for
    the front buffer.

diff --git a/man/intel.man b/man/intel.man
index 05a91f7..32aa7c1 100644
--- a/man/intel.man
+++ b/man/intel.man
@@ -161,9 +161,9 @@ Default: 32768.
 .TP
 .BI "Option \*qPageFlip\*q \*q" boolean \*q
 Enable support for page flipping. This should improve 3D performance at the
-potential cost of worse performance or artifacts with mixed 2D/3D. Also note
-that this gives no benefit without corresponding support in the Mesa 3D driver
-and may not give the full benefit without triple buffering (see
+potential cost of worse performance with mixed 2D/3D. Also note that this gives
+no benefit without corresponding support in the Mesa 3D driver and may not give
+the full benefit without triple buffering (see
 .B "Option \*qTripleBuffer\*q"
 ).
 Default for i810: The option is not used.

commit 4042b27f01fdb94e7fc0d4e991e054fff88479ea
Author: Keith Packard <keithp@guitar.keithp.com>
Date:   Mon Mar 5 22:32:52 2007 -0800

    Move EnterVT mode setting code to xf86SetDesiredModes.
    
    Make the application of crtc desiredModes generic code instead of
    per-driver by creating xf86SetDesiredModes from the code that was in EnterVT
    and calling it.
    
    Also, move the frame buffer clear until just before mode setting to make
    sure things are mapped correctly.

diff --git a/src/i830.h b/src/i830.h
index 08d9e3e..dfa94d8 100644
--- a/src/i830.h
+++ b/src/i830.h
@@ -255,8 +255,6 @@ typedef struct _I830Rec {
    unsigned char *FbBase;
    int cpp;
 
-   DisplayModePtr currentMode;
-
    I830EntPtr entityPrivate;	
    int init;
 
diff --git a/src/i830_display.h b/src/i830_display.h
index 31ab615..07dfe93 100644
--- a/src/i830_display.h
+++ b/src/i830_display.h
@@ -28,9 +28,6 @@
 #include "xorgVersion.h"
 
 /* i830_display.c */
-DisplayModePtr
-i830PipeFindClosestMode(xf86CrtcPtr crtc, DisplayModePtr pMode);
-Bool i830SetMode(ScrnInfoPtr pScrn, DisplayModePtr pMode, Rotation rotation);
 void i830PipeSetBase(xf86CrtcPtr crtc, int x, int y);
 void i830WaitForVblank(ScrnInfoPtr pScrn);
 void i830DescribeOutputConfiguration(ScrnInfoPtr pScrn);
diff --git a/src/i830_driver.c b/src/i830_driver.c
index 7ab2cdc..0977511 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -2885,9 +2885,7 @@ static Bool
 I830EnterVT(int scrnIndex, int flags)
 {
    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
-   xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
    I830Ptr  pI830 = I830PTR(pScrn);
-   int	    i;
 
    DPRINTF(PFX, "Enter VT\n");
 
@@ -2902,12 +2900,6 @@ I830EnterVT(int scrnIndex, int flags)
 
    pI830->leaving = FALSE;
 
-#if 1
-   /* Clear the framebuffer */
-   memset(pI830->FbBase + pScrn->fbOffset, 0,
-	  pScrn->virtualY * pScrn->displayWidth * pI830->cpp);
-#endif
-
    if (I830IsPrimary(pScrn))
       if (!i830_bind_all_memory(pScrn))
          return FALSE;
@@ -2920,27 +2912,13 @@ #endif
    ResetState(pScrn, FALSE);
    SetHWOperatingState(pScrn);
 
-   for (i = 0; i < xf86_config->num_crtc; i++)
-   {
-      xf86CrtcPtr	crtc = xf86_config->crtc[i];
-
-      /* Mark that we'll need to re-set the mode for sure */
-      memset(&crtc->mode, 0, sizeof(crtc->mode));
-      if (!crtc->desiredMode.CrtcHDisplay)
-      {
-	 crtc->desiredMode = *i830PipeFindClosestMode (crtc, pScrn->currentMode);
-	 crtc->desiredRotation = RR_Rotate_0;
-	 crtc->desiredX = 0;
-	 crtc->desiredY = 0;
-      }
-      
-      if (!xf86CrtcSetMode (crtc, &crtc->desiredMode, crtc->desiredRotation,
-			    crtc->desiredX, crtc->desiredY))
-	 return FALSE;
-   }
-
-   xf86DisableUnusedFunctions(pScrn);
+   /* Clear the framebuffer */
+   memset(pI830->FbBase + pScrn->fbOffset, 0,
+	  pScrn->virtualY * pScrn->displayWidth * pI830->cpp);
 
+   if (!xf86SetDesiredModes (pScrn))
+      return FALSE;
+   
    i830DumpRegs (pScrn);
    i830DescribeOutputConfiguration(pScrn);
 
@@ -3003,8 +2981,6 @@ #endif
    if (pI830->checkDevices)
       pI830->devicesTimer = TimerSet(NULL, 0, 1000, I830CheckDevicesTimer, pScrn);
 
-   pI830->currentMode = pScrn->currentMode;
-
    /* Force invarient 3D state to be emitted */
    *pI830->used3D = 1<<31;
 
@@ -3014,17 +2990,10 @@ #endif
 static Bool
 I830SwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
 {
-
    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
    I830Ptr pI830 = I830PTR(pScrn);
-   Bool ret = TRUE;
 
-   DPRINTF(PFX, "I830SwitchMode: mode == %p\n", mode);
-
-   if (!i830SetMode(pScrn, mode, pI830->rotation))
-      pI830->currentMode = mode;
-
-   return ret;
+   return xf86SetSingleMode (pScrn, mode, pI830->rotation);
 }
 
 static Bool
diff --git a/src/i830_memory.c b/src/i830_memory.c
index 7bcf48e..ea6b90d 100644
--- a/src/i830_memory.c
+++ b/src/i830_memory.c
@@ -835,6 +835,8 @@ i830_allocate_framebuffer(ScrnInfoPtr pS
 	return NULL;
     }
 
+    if (pI830->FbBase)
+	memset (pI830->FbBase + front_buffer->offset, 0, size);
     return front_buffer;
 }
 

commit 5c720147e2b86ca4046b7c3812c1ca6b0fb78c9d
Author: Wang Zhenyu <zhenyu.z.wang@intel.com>
Date:   Tue Mar 6 12:44:04 2007 +0800

    EXA: try to always alloc exa i965 state buffer in stolen mem
    
    I think this is a safe way to work around any possible chip
    error.

diff --git a/src/i830_memory.c b/src/i830_memory.c
index 5cddf17..7bcf48e 100644
--- a/src/i830_memory.c
+++ b/src/i830_memory.c
@@ -936,6 +936,20 @@ i830_allocate_2d_memory(ScrnInfoPtr pScr
 		   "Failed to allocate logical context space.\n");
 	return FALSE;
     }
+#ifdef I830_USE_EXA
+    if (pI830->useEXA) {
+	if (IS_I965G(pI830) && pI830->exa_965_state == NULL) {
+	    pI830->exa_965_state =
+		i830_allocate_memory(pScrn, "exa G965 state buffer",
+				     EXA_LINEAR_EXTRA, GTT_PAGE_SIZE, 0);
+	    if (pI830->exa_965_state == NULL) {
+		xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
+			   "Failed to allocate exa state buffer for 965.\n");
+		return FALSE;
+	    }
+	}
+    }
+#endif
 
 #ifdef I830_XV
     /* Allocate overlay register space and optional XAA linear allocator
@@ -982,17 +996,6 @@ #ifdef I830_USE_EXA
 		return FALSE;
 	    }
 	}
-
-	if (IS_I965G(pI830) && pI830->exa_965_state == NULL) {
-	    pI830->exa_965_state =
-		i830_allocate_memory(pScrn, "exa G965 state buffer",
-				     EXA_LINEAR_EXTRA, GTT_PAGE_SIZE, 0);
-	    if (pI830->exa_965_state == NULL) {
-		xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
-			   "Failed to allocate exa state buffer for 965.\n");
-		return FALSE;
-	    }
-	}
     }
 #endif /* I830_USE_EXA */
 

commit 50ba1fff886a7f51b178ac6d3a1ba79a3014b214
Author: Michel Dänzer <michel@tungstengraphics.com>
Date:   Mon Mar 5 10:22:07 2007 +0100

    Be more verbose when page flipping can't be enabled for various reasons.

diff --git a/src/i830_dri.c b/src/i830_dri.c
index e546066..dba1a07 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -1146,7 +1146,7 @@ #ifdef DAMAGE
 	 if (pI830->pDamage == NULL) {
 	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
                        "No screen damage record, page flipping disabled\n");
-            pI830->allowPageFlip = 0;
+            pI830->allowPageFlip = FALSE;
 	 } else {
 	    DamageRegister(&pPix->drawable, pI830->pDamage);
 
diff --git a/src/i830_driver.c b/src/i830_driver.c
index 9bd7029..c950149 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -853,7 +853,6 @@ I830PreInit(ScrnInfoPtr pScrn, int flags
    int i;
    char *s;
    pointer pVBEModule = NULL;
-   Bool enable;
    const char *chipname;
    int num_pipe;
    int max_width, max_height;
@@ -1479,14 +1478,14 @@ #ifdef I830_XV
 	      pI830->colorKey);
 #endif
 
-   pI830->allowPageFlip = FALSE;
-   enable = xf86ReturnOptValBool(pI830->Options, OPTION_PAGEFLIP, FALSE);
 #ifdef XF86DRI
-   if (!pI830->directRenderingDisabled) {
-      pI830->allowPageFlip = enable;
-      xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "page flipping %s\n",
-		 enable ? "enabled" : "disabled");
-   }
+   pI830->allowPageFlip = FALSE;
+   from = (!pI830->directRenderingDisabled &&
+	   xf86GetOptValBool(pI830->Options, OPTION_PAGEFLIP,
+			     &pI830->allowPageFlip)) ? X_CONFIG : X_DEFAULT;
+
+   xf86DrvMsg(pScrn->scrnIndex, from, "Will%s try to enable page flipping\n",
+	      pI830->allowPageFlip ? "" : " not");
 #endif
 
 #ifdef XF86DRI
@@ -1676,6 +1675,9 @@ #endif
 			     -pI830->MemoryAperture.Size / 1024);
 	       }
 	       pScrn->displayWidth = savedDisplayWidth;
+	       if (pI830->allowPageFlip)
+		  xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
+			     "Can't enable page flipping due to the above\n");
 	       pI830->allowPageFlip = FALSE;
 	    } else if (pScrn->displayWidth != savedDisplayWidth) {
 	       xf86DrvMsg(pScrn->scrnIndex, X_INFO,
@@ -2682,6 +2684,9 @@ #ifdef XF86DRI
       I830SetupMemoryTiling(pScrn);
       pI830->directRenderingEnabled = I830DRIDoMappings(pScreen);
    }
+
+   xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Page Flipping %sabled\n",
+	      pI830->allowPageFlip ? "en" : "dis");
 #endif
 
    DPRINTF(PFX, "assert( if(!I830MapMem(pScrn)) )\n");
diff --git a/src/i830_memory.c b/src/i830_memory.c
index 2d1cca9..a952b70 100644
--- a/src/i830_memory.c
+++ b/src/i830_memory.c
@@ -1762,6 +1762,9 @@ I830SetupMemoryTiling(ScrnInfoPtr pScrn)
       xf86DrvMsg(pScrn->scrnIndex, X_INFO,
 		 "I830SetupMemoryTiling: Not tileable 0x%x\n",
 		 pScrn->displayWidth * pI830->cpp);
+      if (pI830->allowPageFlip)
+	 xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
+		    "Can't enable page flipping due to the above\n");
       pI830->allowPageFlip = FALSE;
       return;
    }
@@ -1778,14 +1781,20 @@ I830SetupMemoryTiling(ScrnInfoPtr pScrn)
 		       "Activating tiled memory for the front buffer\n");
             pI830->front_tiled = FENCE_XMAJOR;
 	 } else {
-	    pI830->allowPageFlip = FALSE;
 	    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
 		       "MakeTiles failed for the front buffer\n");
+	    if (pI830->allowPageFlip)
+	       xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
+			  "Can't enable page flipping due to the above\n");
+	    pI830->allowPageFlip = FALSE;
 	 }
       } else {
-	 pI830->allowPageFlip = FALSE;
 	 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
 		 "Alignment bad for the front buffer\n");
+	 if (pI830->allowPageFlip)
+	    xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
+		       "Can't enable page flipping due to the above\n");
+	 pI830->allowPageFlip = FALSE;
       }
    }
 
@@ -1803,6 +1812,9 @@ I830SetupMemoryTiling(ScrnInfoPtr pScrn)
       } else {
 	 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
 		    "MakeTiles failed for the back buffer.\n");
+	 if (pI830->allowPageFlip)
+	    xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
+		       "Can't enable page flipping due to the above\n");
 	 pI830->allowPageFlip = FALSE;
       }
    }
@@ -1815,6 +1827,9 @@ I830SetupMemoryTiling(ScrnInfoPtr pScrn)
       } else {
 	 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
 		    "MakeTiles failed for the third buffer.\n");
+	 if (pI830->allowPageFlip)
+	    xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
+		       "Can't enable page flipping due to the above\n");
 	 pI830->allowPageFlip = FALSE;
       }
    }

commit 36cad3fcb65e3dcd88e58e301cd60adb121cb96b
Author: Michel Dänzer <michel@tungstengraphics.com>
Date:   Wed Feb 28 17:52:42 2007 +0100

    Update vblank pipe setup when setting a mode.

diff --git a/src/i830_display.c b/src/i830_display.c
index 258897e..04159e7 100644
--- a/src/i830_display.c
+++ b/src/i830_display.c
@@ -864,6 +864,9 @@ #endif
     OUTREG(dspcntr_reg, dspcntr);
     /* Flush the plane changes */
     i830PipeSetBase(crtc, x, y);
+#ifdef XF86DRI
+   I830DRISetVBlankInterrupt (pScrn, TRUE);
+#endif
     
     i830WaitForVblank(pScrn);
 }
@@ -1041,9 +1044,6 @@ i830SetMode(ScrnInfoPtr pScrn, DisplayMo
 
     i830DescribeOutputConfiguration(pScrn);
 
-#ifdef XF86DRI
-   I830DRISetVBlankInterrupt (pScrn, TRUE);
-#endif
 done:
     i830DumpRegs (pScrn);
     i830_sdvo_dump(pScrn);
diff --git a/src/i830_driver.c b/src/i830_driver.c
index 3c8ec1a..9bd7029 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -3085,10 +3085,6 @@ #endif
    i830DumpRegs (pScrn);
    i830DescribeOutputConfiguration(pScrn);
 
-#ifdef XF86DRI
-   I830DRISetVBlankInterrupt (pScrn, TRUE);
-#endif
-
    ResetState(pScrn, TRUE);
    SetHWOperatingState(pScrn);
 

commit b5316fb2623e9630cbd58020e0a7c95bf354c587
Author: Michel Dänzer <michel@tungstengraphics.com>
Date:   Wed Feb 28 17:50:56 2007 +0100

    I830DRIClipNotify: Fix initialization of crtcBox[1].[xy]2.

diff --git a/src/i830_dri.c b/src/i830_dri.c
index afc7de0..e546066 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -1523,8 +1523,8 @@ I830DRIClipNotify(ScreenPtr pScreen, Win
       crtcBox[0].y2 = crtcBox[0].y1 + sPriv->pipeA_h;
       crtcBox[1].x1 = sPriv->pipeB_x;
       crtcBox[1].y1 = sPriv->pipeB_y;
-      crtcBox[1].x2 = crtcBox[0].x1 + sPriv->pipeB_w;
-      crtcBox[1].y2 = crtcBox[0].y1 + sPriv->pipeB_h;
+      crtcBox[1].x2 = crtcBox[1].x1 + sPriv->pipeB_w;
+      crtcBox[1].y2 = crtcBox[1].y1 + sPriv->pipeB_h;
 
       for (i = 0; i < 2; i++) {
 	 for (j = 0; j < num; j++) {

commit f5ab9e0ad3a65c972861dd53be6e33e1aac13191
Author: Michel Dänzer <michel@tungstengraphics.com>
Date:   Thu Feb 22 18:57:23 2007 +0100

    I830DRISwapContext: Some cleanups.
    
    Also call I830EmitFlush() when entering/leaving the server context. Doesn't
    seem to help for artifacts with page flipping and mixed 2D/3D unfortunately.

diff --git a/src/i830_dri.c b/src/i830_dri.c
index 6c91cdc..afc7de0 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -1135,6 +1135,8 @@ I830DRISwapContext(ScreenPtr pScreen, DR
       pI830->LockHeld = 1;
       I830RefreshRing(pScrn);
 
+      I830EmitFlush(pScrn);
+
 #ifdef DAMAGE
       if (!pI830->pDamage && pI830->allowPageFlip) {
 	 PixmapPtr pPix  = pScreen->GetScreenPixmap(pScreen);
@@ -1159,10 +1161,12 @@ #endif
    } else if (syncType == DRI_2D_SYNC &&
 	      oldContextType == DRI_NO_CONTEXT &&
 	      newContextType == DRI_2D_CONTEXT) {
-      pI830->LockHeld = 0;
       if (I810_DEBUG & DEBUG_VERBOSE_DRI)
 	 ErrorF("i830DRISwapContext (out)\n");
 
+      if (!pScrn->vtSema)
+     	 return;
+
 #ifdef DAMAGE
       if (pI830->pDamage) {
 	 RegionPtr pDamageReg = DamageRegion(pI830->pDamage);
@@ -1181,6 +1185,10 @@ #ifdef DAMAGE
 	 }
       }
 #endif
+
+      I830EmitFlush(pScrn);
+
+      pI830->LockHeld = 0;
    } else if (I810_DEBUG & DEBUG_VERBOSE_DRI)
       ErrorF("i830DRISwapContext (other)\n");
 }

commit 8cce74f195e5ef6ce5599ecd52f35bcfcb0d7913
Author: Michel Dänzer <michel@tungstengraphics.com>
Date:   Thu Feb 22 18:27:59 2007 +0100

    Do not sync DRI windows between pages when possible.

diff --git a/src/i830.h b/src/i830.h
index bbbb4a8..e26556f 100644
--- a/src/i830.h
+++ b/src/i830.h
@@ -310,6 +310,7 @@ #ifdef XF86DRI
 
 #ifdef DAMAGE
    DamagePtr pDamage;
+   RegionRec driRegion;
 #endif
 #endif
 
diff --git a/src/i830_dri.c b/src/i830_dri.c
index 65736cd..6c91cdc 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -980,6 +980,10 @@ I830DRICloseScreen(ScreenPtr pScreen)
 
    DPRINTF(PFX, "I830DRICloseScreen\n");
 
+#ifdef DAMAGE
+   REGION_UNINIT(pScreen, &pI830->driRegion);
+#endif
+
    if (pI830DRI->irq) {
        drmCtlUninstHandler(pI830->drmSubFD);
        pI830DRI->irq = 0;
@@ -1164,10 +1168,16 @@ #ifdef DAMAGE
 	 RegionPtr pDamageReg = DamageRegion(pI830->pDamage);
 
 	 if (pDamageReg) {
-	    int nrects = REGION_NUM_RECTS(pDamageReg);
+	    RegionRec region;
+	    int nrects;
+
+	    REGION_NULL(pScreen, &region);
+	    REGION_SUBTRACT(pScreen, &region, pDamageReg, &pI830->driRegion);
 
-	    if (nrects)
-	       I830DRIRefreshArea(pScrn, nrects, REGION_RECTS(pDamageReg));
+	    if ((nrects = REGION_NUM_RECTS(&region)))
+	       I830DRIRefreshArea(pScrn, nrects, REGION_RECTS(&region));
+
+	    REGION_UNINIT(pScreen, &region);
 	 }
       }
 #endif
@@ -1486,8 +1496,13 @@ I830DRITransitionTo2d(ScreenPtr pScreen)
 static void
 I830DRIClipNotify(ScreenPtr pScreen, WindowPtr *ppWin, int num)
 {
+   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+   I830Ptr pI830 = I830PTR(pScrn);
    unsigned pfMask = 0;
 
+   REGION_UNINIT(pScreen, &pI830->driRegion);
+   REGION_NULL(pScreen, &pI830->driRegion);
+
    if (num > 0) {
       drmI830Sarea *sPriv = (drmI830Sarea *) DRIGetSAREAPrivate(pScreen);
       BoxRec crtcBox[2];
@@ -1505,15 +1520,24 @@ I830DRIClipNotify(ScreenPtr pScreen, Win
 
       for (i = 0; i < 2; i++) {
 	 for (j = 0; j < num; j++) {
-	    if (ppWin[j] && RECT_IN_REGION(pScreen, &ppWin[j]->clipList,
-					   &crtcBox[i]) != rgnOUT)
-	       numvisible[i]++;
+	    WindowPtr pWin = ppWin[j];
+
+	    if (pWin) {
+	       if (RECT_IN_REGION(pScreen, &pWin->clipList, &crtcBox[i]) !=
+		   rgnOUT)
+		  numvisible[i]++;
+
+	       if (i == 0)
+		  REGION_UNION(pScreen, &pI830->driRegion, &pWin->clipList,
+			       &pI830->driRegion);
+	    }
 	 }
 
 	 if (numvisible[i] == 1)
 	    pfMask |= 1 << i;
       }
-   }
+   } else
+      REGION_NULL(pScreen, &pI830->driRegion);
 
    I830DRISetPfMask(pScreen, pfMask);
 }

commit f346549183a407a4bff6521ec2450dacb97442e9
Author: Michel Dänzer <michel@tungstengraphics.com>
Date:   Wed Feb 21 09:19:54 2007 +0100

    intel.man: Fix typo.

diff --git a/man/intel.man b/man/intel.man
index 503b52a..05a91f7 100644
--- a/man/intel.man
+++ b/man/intel.man
@@ -170,7 +170,7 @@ Default for i810: The option is not used
 Default for i830 and above: Disabled.
 .TP
 .BI "Option \*qTripleBuffer\*q \*q" boolean \*q
-Enable support for triple flipping. This should improve 3D performance at the
+Enable support for triple buffering. This should improve 3D performance at the
 potential cost of worse performance with mixed 2D/3D. Also note that this gives
 no benefit without corresponding support in the Mesa 3D driver and may not give
 any benefit without page flipping either (see

commit 0bee64f4bc7581de7ab28ca438581d215e85c610
Author: Michel Dänzer <michel@tungstengraphics.com>
Date:   Tue Feb 20 19:09:37 2007 +0100

    Add support for triple buffering using a third static buffer.
    
    Need to bump the DRI DDX version minor for the added SAREA fields.

diff --git a/man/intel.man b/man/intel.man
index 3f4cff8..503b52a 100644
--- a/man/intel.man
+++ b/man/intel.man
@@ -162,9 +162,22 @@ Default: 32768.
 .BI "Option \*qPageFlip\*q \*q" boolean \*q
 Enable support for page flipping. This should improve 3D performance at the
 potential cost of worse performance or artifacts with mixed 2D/3D. Also note
-that this gives no benefit without corresponding support in the Mesa 3D driver.
+that this gives no benefit without corresponding support in the Mesa 3D driver
+and may not give the full benefit without triple buffering (see
+.B "Option \*qTripleBuffer\*q"
+).
 Default for i810: The option is not used.
-Default for i9xx: Disabled.
+Default for i830 and above: Disabled.
+.TP
+.BI "Option \*qTripleBuffer\*q \*q" boolean \*q
+Enable support for triple flipping. This should improve 3D performance at the
+potential cost of worse performance with mixed 2D/3D. Also note that this gives
+no benefit without corresponding support in the Mesa 3D driver and may not give
+any benefit without page flipping either (see
+.B "Option \*qPageFlip\*q"
+).
+Default for i810: The option is not used.
+Default for i830 and above: Disabled.
 .TP
 .BI "Option \*qAccelMethod\*q \*q" string \*q
 Choose acceleration architecture, either "XAA" or "EXA".  XAA is the old
diff --git a/src/i830.h b/src/i830.h
index 78381fb..bbbb4a8 100644
--- a/src/i830.h
+++ b/src/i830.h
@@ -294,6 +294,7 @@ #endif
    I830MemRange ContextMem;
 #ifdef XF86DRI
    I830MemRange BackBuffer;
+   I830MemRange ThirdBuffer;
    I830MemRange DepthBuffer;
    I830MemRange TexMem;
    int TexGranularity;
@@ -304,6 +305,7 @@ #ifdef XF86DRI
 
    unsigned int front_tiled;
    unsigned int back_tiled;
+   unsigned int third_tiled;
    unsigned int depth_tiled;
 
 #ifdef DAMAGE
@@ -313,6 +315,7 @@ #endif
 
    Bool NeedRingBufferLow;
    Bool allowPageFlip;
+   Bool TripleBuffer;
    Bool disableTiling;
 
    int backPitch;
@@ -511,6 +514,7 @@ #define I830REGPTR(p) (&(I830PTR(p)->Mod
 #define I830_SELECT_FRONT	0
 #define I830_SELECT_BACK	1
 #define I830_SELECT_DEPTH	2
+#define I830_SELECT_THIRD	3
 
 /* I830 specific functions */
 extern int I830WaitLpRing(ScrnInfoPtr pScrn, int n, int timeout_millis);
@@ -539,6 +543,7 @@ #endif
 #ifdef XF86DRI
 extern Bool I830Allocate3DMemory(ScrnInfoPtr pScrn, const int flags);
 extern Bool I830AllocateBackBuffer(ScrnInfoPtr pScrn, const int flags);
+extern Bool I830AllocateThirdBuffer(ScrnInfoPtr pScrn, const int flags);
 extern Bool I830AllocateDepthBuffer(ScrnInfoPtr pScrn, const int flags);
 extern Bool I830AllocateTextureMemory(ScrnInfoPtr pScrn, const int flags);
 extern void I830SetupMemoryTiling(ScrnInfoPtr pScrn);
diff --git a/src/i830_accel.c b/src/i830_accel.c
index db3168a..c76c748 100644
--- a/src/i830_accel.c
+++ b/src/i830_accel.c
@@ -228,6 +228,9 @@ #ifdef XF86DRI
    case I830_SELECT_BACK:
       pI830->bufferOffset = pI830->BackBuffer.Start;
       break;
+   case I830_SELECT_THIRD:
+      pI830->bufferOffset = pI830->ThirdBuffer.Start;
+      break;
    case I830_SELECT_DEPTH:
       pI830->bufferOffset = pI830->DepthBuffer.Start;
       break;
diff --git a/src/i830_common.h b/src/i830_common.h
index 79455b6..f853ccd 100644
--- a/src/i830_common.h
+++ b/src/i830_common.h
@@ -130,6 +130,12 @@ typedef struct {
 	int pipeB_y;
 	int pipeB_w;
 	int pipeB_h;
+
+	/* Triple buffering */
+	drm_handle_t third_handle;
+	int third_offset;
+	int third_size;
+	unsigned int third_tiled;
 } drmI830Sarea;
 
 /* Flags for perf_boxes
diff --git a/src/i830_dri.c b/src/i830_dri.c
index d655183..65736cd 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -751,6 +751,20 @@ #endif
    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "[drm] Back Buffer = 0x%08x\n",
               (int)sarea->back_handle);
 
+   if (pI830->TripleBuffer) {
+      if (drmAddMap(pI830->drmSubFD,
+		    (drm_handle_t)(sarea->third_offset + pI830->LinearAddr),
+		    sarea->third_size, DRM_AGP, 0,
+		    (drmAddress) &sarea->third_handle) < 0) {
+	xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+		   "[drm] drmAddMap(third_handle) failed. Disabling DRI\n");
+	DRICloseScreen(pScreen);
+	return FALSE;
+      }
+      xf86DrvMsg(pScrn->scrnIndex, X_INFO, "[drm] Third Buffer = 0x%08x\n",
+		 (int)sarea->third_handle);
+   }
+
    if (drmAddMap(pI830->drmSubFD,
                  (drm_handle_t)sarea->depth_offset + pI830->LinearAddr,
                  sarea->depth_size, DRM_AGP, 0,
@@ -794,6 +808,10 @@ I830DRIUnmapScreenRegions(ScrnInfoPtr pS
       drmRmMap(pI830->drmSubFD, sarea->back_handle);
       sarea->back_handle = 0;
    }
+   if (sarea->third_handle) {
+      drmRmMap(pI830->drmSubFD, sarea->third_handle);
+      sarea->third_handle = 0;
+   }
    if (sarea->depth_handle) {
       drmRmMap(pI830->drmSubFD, sarea->depth_handle);
       sarea->depth_handle = 0;
@@ -870,6 +888,7 @@ I830DRIDoMappings(ScreenPtr pScreen)
    /* init to zero to be safe */
    sarea->front_handle = 0;
    sarea->back_handle = 0;
+   sarea->third_handle = 0;
    sarea->depth_handle = 0;
    sarea->tex_handle = 0;
 
@@ -1041,17 +1060,10 @@ #ifdef DAMAGE
  * Otherwise will have to sync again???
  */
 static void
-I830DRIRefreshArea (ScrnInfoPtr pScrn, int num, BoxPtr pbox)
+I830DRIDoRefreshArea (ScrnInfoPtr pScrn, int num, BoxPtr pbox, CARD32 dst)
 {
    I830Ptr pI830 = I830PTR(pScrn);
    int i, cmd, br13 = (pScrn->displayWidth * pI830->cpp) | (0xcc << 16);
-   drmI830Sarea *pSAREAPriv = DRIGetSAREAPrivate(pScrn->pScreen);
-
-   /* Don't want to do this when no 3d is active and pages are
-    * right-way-round :
-    */
-   if (!pSAREAPriv->pf_active && pSAREAPriv->pf_current_page == 0)
-      return;
 
    if (pScrn->bitsPerPixel == 32) {
       cmd = (XY_SRC_COPY_BLT_CMD | XY_SRC_COPY_BLT_WRITE_ALPHA |
@@ -1068,12 +1080,31 @@ I830DRIRefreshArea (ScrnInfoPtr pScrn, i
       OUT_RING(br13);
       OUT_RING((pbox->y1 << 16) | pbox->x1);
       OUT_RING((pbox->y2 << 16) | pbox->x2);
-      OUT_RING(pI830->BackBuffer.Start);
+      OUT_RING(dst);
       OUT_RING((pbox->y1 << 16) | pbox->x1);
       OUT_RING(br13 & 0xffff);
       OUT_RING(pI830->FrontBuffer.Start);
       ADVANCE_LP_RING();
    }
+}
+
+static void
+I830DRIRefreshArea (ScrnInfoPtr pScrn, int num, BoxPtr pbox)
+{
+   I830Ptr pI830 = I830PTR(pScrn);
+   drmI830Sarea *pSAREAPriv = DRIGetSAREAPrivate(pScrn->pScreen);
+
+   /* Don't want to do this when no 3d is active and pages are
+    * right-way-round :
+    */
+   if (!pSAREAPriv->pf_active && pSAREAPriv->pf_current_page == 0)
+      return;
+
+   I830DRIDoRefreshArea(pScrn, num, pbox, pI830->BackBuffer.Start);
+
+   if (pI830->TripleBuffer) {
+      I830DRIDoRefreshArea(pScrn, num, pbox, pI830->ThirdBuffer.Start);
+   }
 
    DamageEmpty(pI830->pDamage);
 }
@@ -1160,6 +1191,13 @@ I830DRIInitBuffers(WindowPtr pWin, Regio
       I830SelectBuffer(pScrn, I830_SELECT_BACK);
       I830SubsequentSolidFillRect(pScrn, pbox->x1, pbox->y1,
 				  pbox->x2 - pbox->x1, pbox->y2 - pbox->y1);
+
+      if (I830PTR(pScrn)->TripleBuffer) {
+	 I830SelectBuffer(pScrn, I830_SELECT_THIRD);
+	 I830SubsequentSolidFillRect(pScrn, pbox->x1, pbox->y1,
+				     pbox->x2 - pbox->x1, pbox->y2 - pbox->y1);
+      }
+
       pbox++;
    }
 
@@ -1333,6 +1371,10 @@ #endif
 
       I830SelectBuffer(pScrn, I830_SELECT_BACK);
       I830SubsequentScreenToScreenCopy(pScrn, x1, y1, destx, desty, w, h);
+      if (pI830->TripleBuffer) {
+	 I830SelectBuffer(pScrn, I830_SELECT_THIRD);
+	 I830SubsequentScreenToScreenCopy(pScrn, x1, y1, destx, desty, w, h);
+      }
       if (!IS_I965G(pI830)) {
          I830SelectBuffer(pScrn, I830_SELECT_DEPTH);
          I830SubsequentScreenToScreenCopy(pScrn, x1, y1, destx, desty, w, h);
@@ -1492,6 +1534,7 @@ I830UpdateDRIBuffers(ScrnInfoPtr pScrn, 
 
    sarea->front_tiled = pI830->front_tiled;
    sarea->back_tiled = pI830->back_tiled;
+   sarea->third_tiled = pI830->third_tiled;
    sarea->depth_tiled = pI830->depth_tiled;
    sarea->rotated_tiled = FALSE;
 
@@ -1509,6 +1552,8 @@ I830UpdateDRIBuffers(ScrnInfoPtr pScrn, 
    sarea->height = pScreen->height;
    sarea->back_offset = pI830->BackBuffer.Start;
    sarea->back_size = pI830->BackBuffer.Size;
+   sarea->third_offset = pI830->ThirdBuffer.Start;
+   sarea->third_size = pI830->ThirdBuffer.Size;
    sarea->depth_offset = pI830->DepthBuffer.Start;
    sarea->depth_size = pI830->DepthBuffer.Size;
    sarea->tex_offset = pI830->TexMem.Start;
diff --git a/src/i830_dri.h b/src/i830_dri.h
index a140497..a2cf78e 100644
--- a/src/i830_dri.h
+++ b/src/i830_dri.h
@@ -9,8 +9,8 @@ #include "i830_common.h"
 #define I830_MAX_DRAWABLES 256
 
 #define I830_MAJOR_VERSION 1
-#define I830_MINOR_VERSION 7
-#define I830_PATCHLEVEL 2
+#define I830_MINOR_VERSION 8
+#define I830_PATCHLEVEL 0
 
 #define I830_REG_SIZE 0x80000
 
diff --git a/src/i830_driver.c b/src/i830_driver.c
index d1f83e5..3c8ec1a 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -273,7 +273,8 @@ #endif
    OPTION_CHECKDEVICES,
    OPTION_LINEARALLOC,
    OPTION_INTELTEXPOOL,
-   OPTION_INTELMMSIZE
+   OPTION_INTELMMSIZE,
+   OPTION_TRIPLEBUFFER,
 } I830Opts;
 
 static OptionInfoRec I830Options[] = {
@@ -292,6 +293,7 @@ #endif
    {OPTION_LINEARALLOC, "LinearAlloc",  OPTV_INTEGER,   {0},    FALSE},
    {OPTION_INTELTEXPOOL,"Legacy3D",     OPTV_BOOLEAN,	{0},	FALSE},
    {OPTION_INTELMMSIZE, "AperTexSize",  OPTV_INTEGER,	{0},	FALSE},
+   {OPTION_TRIPLEBUFFER, "TripleBuffer", OPTV_BOOLEAN,	{0},	FALSE},
    {-1,			NULL,		OPTV_NONE,	{0},	FALSE}
 };
 /* *INDENT-ON* */
@@ -1487,6 +1489,16 @@ #ifdef XF86DRI
    }
 #endif
 
+#ifdef XF86DRI
+   pI830->TripleBuffer = FALSE;
+   from =  (!pI830->directRenderingDisabled &&
+	    xf86GetOptValBool(pI830->Options, OPTION_TRIPLEBUFFER,
+			      &pI830->TripleBuffer)) ? X_CONFIG : X_DEFAULT;
+
+   xf86DrvMsg(pScrn->scrnIndex, from, "Triple buffering %sabled\n",
+	      pI830->TripleBuffer ? "en" : "dis");
+#endif
+
    /*
     * If the driver can do gamma correction, it should call xf86SetGamma() here.
     */
diff --git a/src/i830_memory.c b/src/i830_memory.c
index 29d9d31..2d1cca9 100644
--- a/src/i830_memory.c
+++ b/src/i830_memory.c
@@ -1118,6 +1118,69 @@ I830AllocateBackBuffer(ScrnInfoPtr pScrn
 }
 
 Bool
+I830AllocateThirdBuffer(ScrnInfoPtr pScrn, const int flags)
+{
+   I830Ptr pI830 = I830PTR(pScrn);
+   unsigned long size, alloced, align = 0;
+   Bool tileable;
+   Bool dryrun = ((flags & ALLOCATE_DRY_RUN) != 0);
+   int verbosity = dryrun ? 4 : 1;
+   const char *s = dryrun ? "[dryrun] " : "";
+   int lines;
+   int height = (pI830->rotation & (RR_Rotate_0 | RR_Rotate_180)) ? pScrn->virtualY : pScrn->virtualX;
+
+   /* Third Buffer */
+   memset(&(pI830->ThirdBuffer), 0, sizeof(pI830->ThirdBuffer));
+   pI830->ThirdBuffer.Key = -1;
+   tileable = !(flags & ALLOC_NO_TILING) &&
+	      IsTileable(pScrn, pScrn->displayWidth * pI830->cpp);
+   if (tileable) {
+      /* Make the height a multiple of the tile height (16) */
+      lines = (height + 15) / 16 * 16;
+   } else {
+      lines = height;
+   }
+
+   size = ROUND_TO_PAGE(pScrn->displayWidth * lines * pI830->cpp);
+   /*
+    * Try to allocate on the best tile-friendly boundaries.
+    */
+   alloced = 0;
+   if (tileable) {
+      align = GetBestTileAlignment(size);
+      for (align = GetBestTileAlignment(size); align >= (IS_I9XX(pI830) ? MB(1) : KB(512)); align >>= 1) {
+	 alloced = I830AllocVidMem(pScrn, &(pI830->ThirdBuffer),
+				   &(pI830->StolenPool), size, align,
+				   flags | FROM_ANYWHERE | ALLOCATE_AT_TOP |
+				   ALIGN_BOTH_ENDS);
+	 if (alloced >= size)
+	    break;
+      }
+   }
+   if (alloced < size) {
+      /* Give up on trying to tile */
+      tileable = FALSE;
+      size = ROUND_TO_PAGE(pScrn->displayWidth * height * pI830->cpp);
+      align = GTT_PAGE_SIZE;
+      alloced = I830AllocVidMem(pScrn, &(pI830->ThirdBuffer),
+				&(pI830->StolenPool), size, align,
+				flags | FROM_ANYWHERE | ALLOCATE_AT_TOP);
+   }
+   if (alloced < size) {
+      if (!dryrun) {
+	 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+		    "Failed to allocate third buffer space.\n");
+      }
+      return FALSE;
+   }
+   xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, verbosity,
+		  "%sAllocated %ld kB for the third buffer at 0x%lx.\n", s,
+		  alloced / 1024, pI830->ThirdBuffer.Start);
+
+   return TRUE;
+}
+
+Bool
 I830AllocateDepthBuffer(ScrnInfoPtr pScrn, const int flags)
 {
    I830Ptr pI830 = I830PTR(pScrn);
@@ -1271,6 +1334,9 @@ I830Allocate3DMemory(ScrnInfoPtr pScrn, 
    if (!I830AllocateBackBuffer(pScrn, flags))
       return FALSE;
 
+   if (pI830->TripleBuffer && !I830AllocateThirdBuffer(pScrn, flags))
+      return FALSE;
+
    if (!I830AllocateDepthBuffer(pScrn, flags))
       return FALSE;
 
@@ -1439,6 +1505,7 @@ #ifdef XF86DRI
    if (pI830->directRenderingEnabled) {
       I830FixOffset(pScrn, &(pI830->ContextMem));
       I830FixOffset(pScrn, &(pI830->BackBuffer));
+      I830FixOffset(pScrn, &(pI830->ThirdBuffer));
       I830FixOffset(pScrn, &(pI830->DepthBuffer));
       if (pI830->mmModeFlags & I830_KERNEL_TEX) {
 	 I830FixOffset(pScrn, &(pI830->TexMem));
@@ -1701,6 +1768,7 @@ I830SetupMemoryTiling(ScrnInfoPtr pScrn)
 
    pI830->front_tiled = FENCE_LINEAR;
    pI830->back_tiled = FENCE_LINEAR;
+   pI830->third_tiled = FENCE_LINEAR;
    pI830->depth_tiled = FENCE_LINEAR;
 
    if (pI830->allowPageFlip) {
@@ -1739,6 +1807,18 @@ I830SetupMemoryTiling(ScrnInfoPtr pScrn)
       }
    }
 
+   if (pI830->ThirdBuffer.Alignment >= KB(512)) {
+      if (MakeTiles(pScrn, &(pI830->ThirdBuffer), FENCE_XMAJOR)) {
+	 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+		    "Activating tiled memory for the third buffer.\n");
+         pI830->third_tiled = FENCE_XMAJOR;
+      } else {
+	 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+		    "MakeTiles failed for the third buffer.\n");
+	 pI830->allowPageFlip = FALSE;
+      }
+   }
+
    if (pI830->DepthBuffer.Alignment >= KB(512)) {
       if (MakeTiles(pScrn, &(pI830->DepthBuffer), FENCE_YMAJOR)) {
 	 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
@@ -1825,6 +1905,8 @@ #ifdef XF86DRI
 	    return FALSE;
 	 if (!BindMemRange(pScrn, &(pI830->BackBuffer)))
 	    return FALSE;
+	 if (pI830->TripleBuffer && !BindMemRange(pScrn, &(pI830->ThirdBuffer)))
+	    return FALSE;
 	 if (!BindMemRange(pScrn, &(pI830->DepthBuffer)))
 	    return FALSE;
 	 if ((pI830->mmModeFlags & I830_KERNEL_TEX) && 
@@ -1919,6 +2001,8 @@ #ifdef XF86DRI
 	    return FALSE;
 	 if (!UnbindMemRange(pScrn, &(pI830->BackBuffer)))
 	    return FALSE;
+	 if (pI830->TripleBuffer && !UnbindMemRange(pScrn, &(pI830->ThirdBuffer)))
+	    return FALSE;
 	 if (!UnbindMemRange(pScrn, &(pI830->DepthBuffer)))
 	    return FALSE;
 	 if ((pI830->mmModeFlags & I830_KERNEL_TEX) && 
diff --git a/src/i830_xaa.c b/src/i830_xaa.c
index 5ef5d3c..9b11973 100644
--- a/src/i830_xaa.c
+++ b/src/i830_xaa.c
@@ -281,6 +281,8 @@ CheckTiling(ScrnInfoPtr pScrn)
          tiled = 1;
       if (pI830->bufferOffset == pI830->BackBuffer.Start && pI830->back_tiled == FENCE_XMAJOR)
          tiled = 1;
+      if (pI830->bufferOffset == pI830->ThirdBuffer.Start && pI830->third_tiled == FENCE_XMAJOR)
+         tiled = 1;
       /* not really supported as it's always YMajor tiled */
       if (pI830->bufferOffset == pI830->DepthBuffer.Start && pI830->depth_tiled == FENCE_XMAJOR)
          tiled = 1;

commit 2212baa8454abb4c7948c3f2e20e337f831d1b86
Author: Michel Dänzer <michel@tungstengraphics.com>
Date:   Tue Feb 20 18:39:13 2007 +0100

    Don't mark page flipping as active when it really isn't.

diff --git a/src/i830_dri.c b/src/i830_dri.c
index b368c99..d655183 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -1382,8 +1382,11 @@ I830DRISetPfMask(ScreenPtr pScreen, int 
    I830Ptr pI830 = I830PTR(pScrn);
    drmI830Sarea *pSAREAPriv = DRIGetSAREAPrivate(pScreen);
 
-   pSAREAPriv->pf_enabled = pI830->allowPageFlip;
-   pSAREAPriv->pf_active = pfMask;
+   if (pI830->allowPageFlip && pfMask) {
+      pSAREAPriv->pf_enabled = pI830->allowPageFlip;
+      pSAREAPriv->pf_active = pfMask;
+   } else
+      pSAREAPriv->pf_enabled = pSAREAPriv->pf_active = 0;
 }
 
 static void

commit fac8f2eb49de22abd853ca75f3c985d4d94e3633
Author: Michel Dänzer <michel@tungstengraphics.com>
Date:   Tue Feb 20 18:38:40 2007 +0100

    Document Option "PageFlip".

diff --git a/man/intel.man b/man/intel.man
index b932632..3f4cff8 100644
--- a/man/intel.man
+++ b/man/intel.man
@@ -159,6 +159,13 @@ atctivate the legacy texture pool (see 
 gain some performance by increasing this value.
 Default: 32768.
 .TP
+.BI "Option \*qPageFlip\*q \*q" boolean \*q
+Enable support for page flipping. This should improve 3D performance at the
+potential cost of worse performance or artifacts with mixed 2D/3D. Also note
+that this gives no benefit without corresponding support in the Mesa 3D driver.
+Default for i810: The option is not used.
+Default for i9xx: Disabled.
+.TP
 .BI "Option \*qAccelMethod\*q \*q" string \*q
 Choose acceleration architecture, either "XAA" or "EXA".  XAA is the old
 (but stable) XFree86 based acceleration architecture.  EXA is a newer and

commit 55c7b017ed718107b9b11467030addf225728b84
Author: Michel Dänzer <michel@tungstengraphics.com>
Date:   Wed Feb 14 16:45:22 2007 +0100

    Use new DRI ClipNotify hook to track page flipping per CRTC when available.

diff --git a/src/i830_dri.c b/src/i830_dri.c
index 05171d3..b368c99 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -107,6 +107,7 @@ static void I830DRITransitionTo2d(Screen
 static void I830DRITransitionTo3d(ScreenPtr pScreen);
 static void I830DRITransitionMultiToSingle3d(ScreenPtr pScreen);
 static void I830DRITransitionSingleToMulti3d(ScreenPtr pScreen);
+static void I830DRIClipNotify(ScreenPtr pScreen, WindowPtr *ppWin, int num);
 
 #if 0
 static void I830DRIShadowUpdate (ScreenPtr pScreen, shadowBufPtr pBuf);
@@ -551,10 +552,31 @@ #endif
    pDRIInfo->InitBuffers = I830DRIInitBuffers;
    pDRIInfo->MoveBuffers = I830DRIMoveBuffers;
    pDRIInfo->bufferRequests = DRI_ALL_WINDOWS;
-   pDRIInfo->TransitionTo2d = I830DRITransitionTo2d;
-   pDRIInfo->TransitionTo3d = I830DRITransitionTo3d;
-   pDRIInfo->TransitionSingleToMulti3D = I830DRITransitionSingleToMulti3d;
-   pDRIInfo->TransitionMultiToSingle3D = I830DRITransitionMultiToSingle3d;
+
+#if DRIINFO_MAJOR_VERSION == 5 && DRIINFO_MINOR_VERSION >= 1
+   {
+      int major, minor, patch;
+
+      DRIQueryVersion(&major, &minor, &patch);
+
+      if (minor >= 1)
+#endif
+#if DRIINFO_MAJOR_VERSION > 5 || \
+    (DRIINFO_MAJOR_VERSION == 5 && DRIINFO_MINOR_VERSION >= 1)
+	 pDRIInfo->ClipNotify = I830DRIClipNotify;
+#endif
+   }
+
+#if DRIINFO_MAJOR_VERSION > 5 || \
+    (DRIINFO_MAJOR_VERSION == 5 && DRIINFO_MINOR_VERSION >= 1)
+   if (!pDRIInfo->ClipNotify)
+#endif
+   {
+      pDRIInfo->TransitionTo2d = I830DRITransitionTo2d;
+      pDRIInfo->TransitionTo3d = I830DRITransitionTo3d;
+      pDRIInfo->TransitionSingleToMulti3D = I830DRITransitionSingleToMulti3d;
+      pDRIInfo->TransitionMultiToSingle3D = I830DRITransitionMultiToSingle3d;
+   }
 
    /* do driver-independent DRI screen initialization here */
    if (!DRIScreenInit(pScreen, pDRIInfo, &pI830->drmSubFD)) {
@@ -1354,25 +1376,16 @@ #endif
  */
 
 static void
-I830EnablePageFlip(ScreenPtr pScreen)
+I830DRISetPfMask(ScreenPtr pScreen, int pfMask)
 {
    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
    I830Ptr pI830 = I830PTR(pScrn);
    drmI830Sarea *pSAREAPriv = DRIGetSAREAPrivate(pScreen);
 
    pSAREAPriv->pf_enabled = pI830->allowPageFlip;
-   pSAREAPriv->pf_active = pI830->allowPageFlip;
-}
-
-static void
-I830DisablePageFlip(ScreenPtr pScreen)
-{
-   drmI830Sarea *pSAREAPriv = DRIGetSAREAPrivate(pScreen);
-
-   pSAREAPriv->pf_active = 0;
+   pSAREAPriv->pf_active = pfMask;
 }
 
-
 static void
 I830DRITransitionSingleToMulti3d(ScreenPtr pScreen)
 {
@@ -1380,15 +1393,18 @@ I830DRITransitionSingleToMulti3d(ScreenP
     *   -- Field in sarea, plus bumping the window counters.
     *   -- DRM needs to cope with Front-to-Back swapbuffers.
     */
-   I830DisablePageFlip(pScreen);
+   I830DRISetPfMask(pScreen, 0);
 }
 
 static void
 I830DRITransitionMultiToSingle3d(ScreenPtr pScreen)
 {
+   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+   I830Ptr pI830 = I830PTR(pScrn);
+
    /* Let the remaining 3d app start page flipping again.
     */
-   I830EnablePageFlip(pScreen);
+   I830DRISetPfMask(pScreen, pI830->allowPageFlip ? 0x3 : 0);
 }
 
 static void
@@ -1397,7 +1413,7 @@ I830DRITransitionTo3d(ScreenPtr pScreen)
    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
    I830Ptr pI830 = I830PTR(pScrn);
 
-   I830EnablePageFlip(pScreen);
+   I830DRISetPfMask(pScreen, pI830->allowPageFlip ? 0x3 : 0);
    pI830->have3DWindows = 1;
 }
 
@@ -1417,11 +1433,46 @@ I830DRITransitionTo2d(ScreenPtr pScreen)
       xf86DrvMsg(pScreen->myNum, X_WARNING,
 		 "[dri] %s: kernel failed to unflip buffers.\n", __func__);
 
-   I830DisablePageFlip(pScreen);
+   I830DRISetPfMask(pScreen, 0);
 
    pI830->have3DWindows = 0;
 }
 
+static void
+I830DRIClipNotify(ScreenPtr pScreen, WindowPtr *ppWin, int num)
+{
+   unsigned pfMask = 0;
+
+   if (num > 0) {
+      drmI830Sarea *sPriv = (drmI830Sarea *) DRIGetSAREAPrivate(pScreen);
+      BoxRec crtcBox[2];
+      unsigned numvisible[2] = { 0, 0 };
+      int i, j;
+
+      crtcBox[0].x1 = sPriv->pipeA_x;
+      crtcBox[0].y1 = sPriv->pipeA_y;
+      crtcBox[0].x2 = crtcBox[0].x1 + sPriv->pipeA_w;
+      crtcBox[0].y2 = crtcBox[0].y1 + sPriv->pipeA_h;
+      crtcBox[1].x1 = sPriv->pipeB_x;
+      crtcBox[1].y1 = sPriv->pipeB_y;
+      crtcBox[1].x2 = crtcBox[0].x1 + sPriv->pipeB_w;
+      crtcBox[1].y2 = crtcBox[0].y1 + sPriv->pipeB_h;
+
+      for (i = 0; i < 2; i++) {
+	 for (j = 0; j < num; j++) {
+	    if (ppWin[j] && RECT_IN_REGION(pScreen, &ppWin[j]->clipList,
+					   &crtcBox[i]) != rgnOUT)
+	       numvisible[i]++;
+	 }
+
+	 if (numvisible[i] == 1)
+	    pfMask |= 1 << i;
+      }
+   }
+
+   I830DRISetPfMask(pScreen, pfMask);
+}
+
 
 /**
  * Update the SAREA fields with the most recent values.

commit 3bd8edb95fcbbb49e97a1a2bdd5c8eae4f83d3a8
Author: Michel Dänzer <michel@tungstengraphics.com>
Date:   Fri Feb 2 17:41:18 2007 +0100

    Revive i830 page flipping support.
    
    Use the damage layer directly instead of via shadowfb.

diff --git a/configure.ac b/configure.ac
index d45185a..219fbe6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -94,6 +94,8 @@ if test "$DRI" != no; then
                       [have_sarea_h="yes"], [have_sarea_h="no"])
         AC_CHECK_FILE([${sdkdir}/dristruct.h],
                       [have_dristruct_h="yes"], [have_dristruct_h="no"])
+	AC_CHECK_FILE([${sdkdir}/damage.h],
+                      [have_damage_h="yes"], [have_damage_h="no"])
 fi
 
 AC_MSG_CHECKING([whether to include DRI support])
@@ -127,6 +129,9 @@ if test "$DRI" = yes; then
 	if test "x$DRI_MM" = xyes; then
 		AC_DEFINE(XF86DRI_MM,1,[Extended DRI memory management])
 	fi
+	if test "$have_damage_h" = yes; then
+		AC_DEFINE(DAMAGE,1,[Use Damage extension])
+	fi
 fi
 
 AM_CONDITIONAL(VIDEO_DEBUG, test x$VIDEO_DEBUG = xyes)
diff --git a/src/i830.h b/src/i830.h
index 96972eb..78381fb 100644
--- a/src/i830.h
+++ b/src/i830.h
@@ -68,6 +68,9 @@ #define _XF86DRI_SERVER_
 #include "dri.h"
 #include "GL/glxint.h"
 #include "i830_dri.h"
+#ifdef DAMAGE
+#include "damage.h"
+#endif
 #endif
 
 #ifdef I830_USE_EXA
@@ -302,6 +305,10 @@ #ifdef XF86DRI
    unsigned int front_tiled;
    unsigned int back_tiled;
    unsigned int depth_tiled;
+
+#ifdef DAMAGE
+   DamagePtr pDamage;
+#endif
 #endif
 
    Bool NeedRingBufferLow;
diff --git a/src/i830_dri.c b/src/i830_dri.c
index 3531bf5..05171d3 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -984,17 +984,6 @@ I830DRIFinishScreenInit(ScreenPtr pScree
 
    DPRINTF(PFX, "I830DRIFinishScreenInit\n");
 
-   /* Have shadow run only while there is 3d active.
-    */
-#if 0
-   if (pI830->allowPageFlip && pI830->drmMinor >= 1) {
-      shadowAdd(pScreen, 0, I830DRIShadowUpdate, 0, 0, 0);
-   }
-   else
-#endif
-      pI830->allowPageFlip = 0;
-
-
    if (!DRIFinishScreenInit(pScreen))
       return FALSE;
 
@@ -1025,6 +1014,49 @@ #endif
    }
 }
 
+#ifdef DAMAGE
+/* This should be done *before* XAA syncs,
+ * Otherwise will have to sync again???
+ */
+static void
+I830DRIRefreshArea (ScrnInfoPtr pScrn, int num, BoxPtr pbox)
+{
+   I830Ptr pI830 = I830PTR(pScrn);
+   int i, cmd, br13 = (pScrn->displayWidth * pI830->cpp) | (0xcc << 16);
+   drmI830Sarea *pSAREAPriv = DRIGetSAREAPrivate(pScrn->pScreen);
+
+   /* Don't want to do this when no 3d is active and pages are
+    * right-way-round :
+    */
+   if (!pSAREAPriv->pf_active && pSAREAPriv->pf_current_page == 0)
+      return;
+
+   if (pScrn->bitsPerPixel == 32) {
+      cmd = (XY_SRC_COPY_BLT_CMD | XY_SRC_COPY_BLT_WRITE_ALPHA |
+	     XY_SRC_COPY_BLT_WRITE_RGB);
+      br13 |= 3 << 24;
+   } else {
+      cmd = (XY_SRC_COPY_BLT_CMD);
+      br13 |= 1 << 24;
+   }
+
+   for (i = 0 ; i < num ; i++, pbox++) {
+      BEGIN_LP_RING(8);
+      OUT_RING(cmd);
+      OUT_RING(br13);
+      OUT_RING((pbox->y1 << 16) | pbox->x1);
+      OUT_RING((pbox->y2 << 16) | pbox->x2);
+      OUT_RING(pI830->BackBuffer.Start);
+      OUT_RING((pbox->y1 << 16) | pbox->x1);
+      OUT_RING(br13 & 0xffff);
+      OUT_RING(pI830->FrontBuffer.Start);
+      ADVANCE_LP_RING();
+   }
+
+   DamageEmpty(pI830->pDamage);
+}
+#endif
+
 static void
 I830DRISwapContext(ScreenPtr pScreen, DRISyncType syncType,
 		   DRIContextType oldContextType, void *oldContext,
@@ -1045,12 +1077,47 @@ I830DRISwapContext(ScreenPtr pScreen, DR
      	 return;
       pI830->LockHeld = 1;
       I830RefreshRing(pScrn);
+
+#ifdef DAMAGE
+      if (!pI830->pDamage && pI830->allowPageFlip) {
+	 PixmapPtr pPix  = pScreen->GetScreenPixmap(pScreen);
+	 pI830->pDamage = DamageCreate(NULL, NULL, DamageReportNone, TRUE,
+				       pScreen, pPix);
+
+	 if (pI830->pDamage == NULL) {
+	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+                       "No screen damage record, page flipping disabled\n");
+            pI830->allowPageFlip = 0;
+	 } else {
+	    DamageRegister(&pPix->drawable, pI830->pDamage);
+
+	    DamageDamageRegion(&pPix->drawable,
+			       &WindowTable[pScreen->myNum]->winSize);
+
+            xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+                       "Damage tracking initialized for page flipping\n");
+	 }
+    }
+#endif
    } else if (syncType == DRI_2D_SYNC &&
 	      oldContextType == DRI_NO_CONTEXT &&
 	      newContextType == DRI_2D_CONTEXT) {
       pI830->LockHeld = 0;
       if (I810_DEBUG & DEBUG_VERBOSE_DRI)
 	 ErrorF("i830DRISwapContext (out)\n");
+
+#ifdef DAMAGE
+      if (pI830->pDamage) {
+	 RegionPtr pDamageReg = DamageRegion(pI830->pDamage);
+
+	 if (pDamageReg) {
+	    int nrects = REGION_NUM_RECTS(pDamageReg);
+
+	    if (nrects)
+	       I830DRIRefreshArea(pScrn, nrects, REGION_RECTS(pDamageReg));
+	 }
+      }
+#endif
    } else if (I810_DEBUG & DEBUG_VERBOSE_DRI)
       ErrorF("i830DRISwapContext (other)\n");
 }
@@ -1286,54 +1353,6 @@ #endif
  * might be faster, but seems like a lot more work...
  */
 
-
-#if 0
-/* This should be done *before* XAA syncs,
- * Otherwise will have to sync again???
- */
-static void
-I830DRIShadowUpdate (ScreenPtr pScreen, shadowBufPtr pBuf)
-{
-   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-   I830Ptr pI830 = I830PTR(pScrn);
-   RegionPtr damage = &pBuf->damage;
-   int i, num =  REGION_NUM_RECTS(damage);
-   BoxPtr pbox = REGION_RECTS(damage);
-   drmI830Sarea *pSAREAPriv = DRIGetSAREAPrivate(pScreen);
-   int cmd, br13;
-
-   /* Don't want to do this when no 3d is active and pages are
-    * right-way-round :
-    */
-   if (!pSAREAPriv->pf_active && pSAREAPriv->pf_current_page == 0)
-      return;
-
-   br13 = (pScrn->displayWidth * pI830->cpp) | (0xcc << 16);
-
-   if (pScrn->bitsPerPixel == 32) {
-      cmd = (XY_SRC_COPY_BLT_CMD | XY_SRC_COPY_BLT_WRITE_ALPHA |
-	     XY_SRC_COPY_BLT_WRITE_RGB);
-      br13 |= 3 << 24;
-   } else {
-      cmd = (XY_SRC_COPY_BLT_CMD);
-      br13 |= 1 << 24;
-   }
-
-   for (i = 0 ; i < num ; i++, pbox++) {
-      BEGIN_LP_RING(8);
-      OUT_RING(cmd);
-      OUT_RING(br13);
-      OUT_RING((pbox->y1 << 16) | pbox->x1);
-      OUT_RING((pbox->y2 << 16) | pbox->x2);
-      OUT_RING(pI830->BackBuffer.Start);
-      OUT_RING((pbox->y1 << 16) | pbox->x1);
-      OUT_RING(br13 & 0xffff);
-      OUT_RING(pI830->FrontBuffer.Start);
-      ADVANCE_LP_RING();
-   }
-}
-#endif
-
 static void
 I830EnablePageFlip(ScreenPtr pScreen)
 {
@@ -1342,32 +1361,7 @@ I830EnablePageFlip(ScreenPtr pScreen)
    drmI830Sarea *pSAREAPriv = DRIGetSAREAPrivate(pScreen);
 
    pSAREAPriv->pf_enabled = pI830->allowPageFlip;
-   pSAREAPriv->pf_active = 0;
-
-   if (pI830->allowPageFlip) {
-      int br13 = (pScrn->displayWidth * pI830->cpp) | (0xcc << 16);
-
-      BEGIN_LP_RING(8);
-      if (pScrn->bitsPerPixel == 32) {
-	 OUT_RING(XY_SRC_COPY_BLT_CMD | XY_SRC_COPY_BLT_WRITE_ALPHA |
-		  XY_SRC_COPY_BLT_WRITE_RGB);
-	 br13 |= 3 << 24;
-      } else {
-	 OUT_RING(XY_SRC_COPY_BLT_CMD);
-	 br13 |= 1 << 24;
-      }
-
-      OUT_RING(br13);
-      OUT_RING(0);
-      OUT_RING((pScrn->virtualY << 16) | pScrn->virtualX);
-      OUT_RING(pI830->BackBuffer.Start);
-      OUT_RING(0);
-      OUT_RING(br13 & 0xffff);
-      OUT_RING(pI830->FrontBuffer.Start);
-      ADVANCE_LP_RING();
-
-      pSAREAPriv->pf_active = 1;
-   }
+   pSAREAPriv->pf_active = pI830->allowPageFlip;
 }
 
 static void
@@ -1419,14 +1413,13 @@ I830DRITransitionTo2d(ScreenPtr pScreen)
    if (sPriv->pf_current_page == 1)
       drmCommandNone(pI830->drmSubFD, DRM_I830_FLIP);
 
-   /* Shut down shadowing if we've made it back to the front page:
-    */
-   if (sPriv->pf_current_page == 0) {
-      I830DisablePageFlip(pScreen);
-   }
+   if (sPriv->pf_current_page == 1)
+      xf86DrvMsg(pScreen->myNum, X_WARNING,
+		 "[dri] %s: kernel failed to unflip buffers.\n", __func__);
 
-   pI830->have3DWindows = 0;
+   I830DisablePageFlip(pScreen);
 
+   pI830->have3DWindows = 0;
 }
 
 
diff --git a/src/i830_driver.c b/src/i830_driver.c
index cb3dd87..d1f83e5 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -3168,6 +3168,15 @@ #endif
    pI830->closing = TRUE;
 #ifdef XF86DRI
    if (pI830->directRenderingOpen) {
+#ifdef DAMAGE
+      if (pI830->pDamage) {
+	 PixmapPtr pPix = pScreen->GetScreenPixmap(pScreen);
+
+	 DamageUnregister(&pPix->drawable, pI830->pDamage);
+	 DamageDestroy(pI830->pDamage);
+	 pI830->pDamage = NULL;
+      }
+#endif
 #ifdef XF86DRI_MM
       if (pI830->mmModeFlags & I830_KERNEL_MM) {
 #ifndef XSERVER_LIBDRM_MM
diff --git a/src/i830_memory.c b/src/i830_memory.c
index 6ceb05b..29d9d31 100644
--- a/src/i830_memory.c
+++ b/src/i830_memory.c
@@ -515,7 +515,7 @@ I830AllocateFramebuffer(ScrnInfoPtr pScr
    int verbosity = dryrun ? 4 : 1;
    const char *s = dryrun ? "[dryrun] " : "";
    Bool tileable;
-   int align, alignflags;
+   int align;
    long size, alloced, fb_height;
 
    /* Clear everything first. */
@@ -586,16 +586,6 @@ I830AllocateFramebuffer(ScrnInfoPtr pScr
 
    tileable = !(flags & ALLOC_NO_TILING) && pI830->allowPageFlip &&
       IsTileable(pScrn, pScrn->displayWidth * pI830->cpp);
-   if (tileable) {
-      if (IS_I9XX(pI830))
-	 align = MB(1);
-      else
-	 align = KB(512);
-      alignflags = ALIGN_BOTH_ENDS;
-   } else {
-      align = KB(64);
-      alignflags = 0;
-   }
 
    size = lineSize * (fb_height + cacheLines);
    size = ROUND_TO_PAGE(size);
@@ -603,10 +593,26 @@ I830AllocateFramebuffer(ScrnInfoPtr pScr
 		  "%sInitial %sframebuffer allocation size: %ld kByte\n",
 		  s, secondary ? "secondary " : "",
 		  size / 1024);
-   alloced = I830AllocVidMem(pScrn, FrontBuffer,
-			     StolenPool, size, align,
-			     flags | alignflags |
-			     FROM_ANYWHERE | ALLOCATE_AT_BOTTOM);
+
+   if (tileable) {
+      align = GetBestTileAlignment(size);
+
+      for (align = GetBestTileAlignment(size);
+	   align >= (IS_I9XX(pI830) ? MB(1) : KB(512)); align >>= 1) {
+	 alloced = I830AllocVidMem(pScrn, FrontBuffer, StolenPool, size, align,
+				   flags | FROM_ANYWHERE | ALLOCATE_AT_TOP |
+				   ALIGN_BOTH_ENDS);
+	 if (alloced >= size)
+	    break;
+      }
+   } else {
+      align = KB(64);
+
+      alloced = I830AllocVidMem(pScrn, FrontBuffer,
+				StolenPool, size, align,
+				flags | FROM_ANYWHERE | ALLOCATE_AT_BOTTOM);
+   }
+
    if (alloced < size) {
       if (!dryrun) {
 	 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Failed to allocate "
@@ -718,7 +724,7 @@ I830Allocate2DMemory(ScrnInfoPtr pScrn, 
    int verbosity = dryrun ? 4 : 1;
    const char *s = dryrun ? "[dryrun] " : "";
    Bool tileable;
-   int align, alignflags, i;
+   int align, i;
 
    DPRINTF(PFX, "I830Allocate2DMemory: inital is %s\n",
 	   BOOLTOSTRING(flags & ALLOC_INITIAL));
@@ -877,20 +883,26 @@ #endif
 	 pI830->FbMemBox.y2 = maxFb / lineSize;
 	 tileable = !(flags & ALLOC_NO_TILING) && pI830->allowPageFlip &&
 		 IsTileable(pScrn, pScrn->displayWidth * pI830->cpp);
+
 	 if (tileable) {
-            if (IS_I9XX(pI830))
-               align = MB(1);
-            else
-	       align = KB(512);
-	    alignflags = ALIGN_BOTH_ENDS;
+	    align = GetBestTileAlignment(size);
+
+	    for (align = GetBestTileAlignment(size);
+		 align >= (IS_I9XX(pI830) ? MB(1) : KB(512)); align >>= 1) {
+	       alloced = I830AllocVidMem(pScrn, &(pI830->FrontBuffer),
+					 &(pI830->StolenPool), size, align,
+					 flags | FROM_ANYWHERE |
+					 ALLOCATE_AT_TOP | ALIGN_BOTH_ENDS);
+	       if (alloced >= size)
+		  break;
+	    }
 	 } else {
-	    align = KB(64);
-	    alignflags = 0;
+	    alloced = I830AllocVidMem(pScrn, &(pI830->FrontBuffer),
+				      &(pI830->StolenPool), maxFb, align,
+				      flags |
+				      FROM_ANYWHERE | ALLOCATE_AT_BOTTOM);
 	 }
-	 alloced = I830AllocVidMem(pScrn, &(pI830->FrontBuffer),
-				   &(pI830->StolenPool), maxFb, align,
-				   flags | alignflags |
-				   FROM_ANYWHERE | ALLOCATE_AT_BOTTOM);
+
 	 if (alloced < maxFb) {
 	    if (!dryrun) {
 	       xf86DrvMsg(pScrn->scrnIndex, X_ERROR,

commit 1d22bad33b634aaf61976907cb2ceeec8a9ebe4d
Author: Michel Dänzer <michel@tungstengraphics.com>
Date:   Wed Feb 14 12:57:12 2007 +0100

    Update SAREA pipe fields in i830PipeSetBase.

diff --git a/src/i830_display.c b/src/i830_display.c
index 345eea9..258897e 100644
--- a/src/i830_display.c
+++ b/src/i830_display.c
@@ -361,6 +361,31 @@ i830PipeSetBase(xf86CrtcPtr crtc, int x,
 	OUTREG(dspbase, Start + ((y * pScrn->displayWidth + x) * pI830->cpp));
 	(void) INREG(dspbase);
     }
+
+#ifdef XF86DRI
+    if (pI830->directRenderingEnabled) {
+	drmI830Sarea *sPriv = (drmI830Sarea *) DRIGetSAREAPrivate(pScrn->pScreen);
+
+	switch (pipe) {
+	case 0:
+	    sPriv->pipeA_x = x;
+	    sPriv->pipeA_y = y;
+	    sPriv->pipeA_w = crtc->mode.HDisplay;
+	    sPriv->pipeA_h = crtc->mode.VDisplay;
+	    break;
+	case 1:
+	    sPriv->pipeB_x = x;
+	    sPriv->pipeB_y = y;
+	    sPriv->pipeB_w = crtc->mode.HDisplay;
+	    sPriv->pipeB_h = crtc->mode.VDisplay;
+	    break;
+	default:
+	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+		       "Can't update pipe %d in SAREA\n", pipe);
+	    break;
+	}
+    }
+#endif
 }
 
 /**

commit 0df490938af10d3a748221e2fb5467b0f244f9eb
Author: Michel Dänzer <michel@tungstengraphics.com>
Date:   Thu Dec 21 11:27:28 2006 +0100

    If the DRM can handle it, enable vertical blank interrupts for both pipes.

diff --git a/src/i830_dri.c b/src/i830_dri.c
index 70e7e49..3531bf5 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -1497,7 +1497,10 @@ I830DRISetVBlankInterrupt (ScrnInfoPtr p
     if (pI830->directRenderingEnabled && pI830->drmMinor >= 5) {
 	if (on) {
 	    if (xf86_config->num_crtc > 1 && xf86_config->crtc[1]->enabled)
-		pipe.pipe = DRM_I830_VBLANK_PIPE_B;
+		if (pI830->drmMinor >= 6)
+		    pipe.pipe = DRM_I830_VBLANK_PIPE_A | DRM_I830_VBLANK_PIPE_B;
+		else
+		    pipe.pipe = DRM_I830_VBLANK_PIPE_B;
 	    else
 		pipe.pipe = DRM_I830_VBLANK_PIPE_A;
 	} else {



Reply to: