xf86-video-intel: Branch 'dri2' - 12 commits - configure.ac src/i830_accel.c src/i830_batchbuffer.c src/i830_display.c src/i830_dri.c src/i830_driver.c src/i830_exa.c src/i830.h src/i830_memory.c

Kristian Høgsberg krh at kemper.freedesktop.org
Mon Dec 1 19:05:58 PST 2008


Rebased ref, commits from common ancestor:
commit ee87f7becc2138348ec0d948829db6e86cee86da
Merge: 3dd7f0f... a5b1e62...
Author: Kristian Høgsberg <krh at redhat.com>
Date:   Wed Nov 12 16:40:37 2008 -0500

    Merge commit 'origin/master' into dri2
    
    Conflicts:
    	src/i830_dri.c
    	src/i830_driver.c
    	src/i830_memory.c

diff --cc src/i830_accel.c
index 52e22ba,fe76fa0..c01076a
--- a/src/i830_accel.c
+++ b/src/i830_accel.c
@@@ -192,9 -192,9 +192,9 @@@ I830Sync(ScrnInfoPtr pScrn
  
     I830EmitFlush(pScrn);
  
-    intel_batch_flush(pScrn);
+    intel_batch_flush(pScrn, TRUE);
  
 -   if (pI830->directRenderingEnabled) {
 +   if (pI830->directRenderingType > DRI_NONE) {
         struct drm_i915_irq_emit emit;
         struct drm_i915_irq_wait wait;
         int ret;
diff --cc src/i830_display.c
index 95ce51e,006b634..2626612
--- a/src/i830_display.c
+++ b/src/i830_display.c
@@@ -753,10 -753,10 +753,10 @@@ static void i830_modeset_ctl(xf86CrtcPt
      I830CrtcPrivatePtr intel_crtc = crtc->driver_private;
      struct drm_modeset_ctl modeset;
  
 -    if (!pI830->directRenderingEnabled)
 +    if (pI830->directRenderingType <= DRI_NONE)
        return;
  
-     modeset.crtc = intel_crtc->plane;
+     modeset.crtc = intel_crtc->pipe;
  
      /*
       * DPMS will be called many times (especially off), but we only
diff --cc src/i830_dri.c
index 12de9d4,c60ee24..9c10c99
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@@ -1824,200 -1810,3 +1822,202 @@@ I830DRIUnlock(ScrnInfoPtr pScrn
        pI830->LockHeld = 0;
     }
  }
 +
 +#ifdef DRI2
 +
 +typedef struct {
 +    PixmapPtr pPixmap;
 +} I830DRI2BufferPrivateRec, *I830DRI2BufferPrivatePtr;
 +
 +static DRI2BufferPtr
 +I830DRI2CreateBuffers(DrawablePtr pDraw, unsigned int *attachments, int count)
 +{
 +    ScreenPtr pScreen = pDraw->pScreen;
 +    DRI2BufferPtr buffers;
 +    dri_bo *bo;
 +    int i;
 +    I830DRI2BufferPrivatePtr privates;
 +    PixmapPtr pPixmap, pDepthPixmap;
 +
 +    buffers = xcalloc(count, sizeof *buffers);
 +    if (buffers == NULL)
 +	return NULL;
 +    privates = xcalloc(count, sizeof *privates);
 +    if (privates == NULL) {
 +	xfree(buffers);
 +	return NULL;
 +    }
 +
 +    pDepthPixmap = NULL;
 +    for (i = 0; i < count; i++) {
 +	if (attachments[i] == DRI2BufferFrontLeft) {
 +	    if (pDraw->type == DRAWABLE_PIXMAP)
 +		pPixmap = (PixmapPtr) pDraw;
 +	    else
 +		pPixmap = (*pScreen->GetWindowPixmap)((WindowPtr) pDraw);
 +	    pPixmap->refcnt++;
 +	} else if (attachments[i] == DRI2BufferStencil && pDepthPixmap) {
 +	    pPixmap = pDepthPixmap;
 +	    pPixmap->refcnt++;
 +	} else {
 +	    pPixmap = (*pScreen->CreatePixmap)(pScreen,
 +					       pDraw->width,
 +					       pDraw->height,
 +					       pDraw->depth, 0);
 +	}
 +
 +	if (attachments[i] == DRI2BufferDepth)
 +	    pDepthPixmap = pPixmap;
 +
 +	buffers[i].attachment = attachments[i];
 +	buffers[i].pitch = pPixmap->devKind;
 +	buffers[i].cpp = pPixmap->drawable.bitsPerPixel / 8;
 +	buffers[i].driverPrivate = &privates[i];
 +	buffers[i].flags = 0; /* not tiled */
 +	privates[i].pPixmap = pPixmap;
 +
 +	bo = i830_get_pixmap_bo (pPixmap);
 +	if (dri_bo_flink(bo, &buffers[i].name) != 0) {
 +	    /* failed to name buffer */
 +	}
 +
 +    }
 +
 +    return buffers;
 +}
 +
 +static void
 +I830DRI2DestroyBuffers(DrawablePtr pDraw, DRI2BufferPtr buffers, int count)
 +{
 +    ScreenPtr pScreen = pDraw->pScreen;
 +    I830DRI2BufferPrivatePtr private;
 +    int i;
 +
 +    for (i = 0; i < count; i++)
 +    {
 +	private = buffers[i].driverPrivate;
 +	(*pScreen->DestroyPixmap)(private->pPixmap);
 +    }
 +
 +    if (buffers)
 +    {
 +	xfree(buffers[0].driverPrivate);
 +	xfree(buffers);
 +    }
 +}
 +
- static void
++static unsigned int
 +I830DRI2CopyRegion(DrawablePtr pDraw, RegionPtr pRegion,
 +		   DRI2BufferPtr pDestBuffer, DRI2BufferPtr pSrcBuffer)
 +{
 +    I830DRI2BufferPrivatePtr private = pSrcBuffer->driverPrivate;
 +    ScreenPtr pScreen = pDraw->pScreen;
 +    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
 +    I830Ptr pI830 = I830PTR(pScrn);
 +    PixmapPtr pPixmap = private->pPixmap;
 +    RegionPtr pCopyClip;
 +    GCPtr pGC;
 +
 +    pGC = GetScratchGC(pDraw->depth, pScreen);
 +    pCopyClip = REGION_CREATE(pScreen, NULL, 0);
 +    REGION_COPY(pScreen, pCopyClip, pRegion);
 +    (*pGC->funcs->ChangeClip) (pGC, CT_REGION, pCopyClip, 0);
 +    ValidateGC(pDraw, pGC);
 +    (*pGC->ops->CopyArea)(&pPixmap->drawable,
 +			  pDraw, pGC, 0, 0, pDraw->width, pDraw->height, 0, 0);
 +    FreeScratchGC(pGC);
 +
 +    /* Emit a flush of the rendering cache, or on the 965 and beyond
 +     * rendering results may not hit the framebuffer until significantly
 +     * later.
 +     */
 +    I830EmitFlush(pScrn);
 +    pI830->need_mi_flush = FALSE;
 +
 +    /* We can't rely on getting into the block handler before the DRI
 +     * client gets to run again so flush now. */
-     intel_batch_flush(pScrn);
++    intel_batch_flush(pScrn, TRUE);
 +#if ALWAYS_SYNC
 +    I830Sync(pScrn);
 +#endif
 +    drmCommandNone(pI830->drmSubFD, DRM_I915_GEM_THROTTLE);
++
++    return 1;
 +}
 +
 +Bool I830DRI2ScreenInit(ScreenPtr pScreen)
 +{
 +    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
 +    I830Ptr pI830 = I830PTR(pScrn);
 +    DRI2InfoRec info;
 +    char *p, *busId, buf[64];
 +    int fd, i, cmp;
 +
 +    if (pI830->accel != ACCEL_UXA) {
 +	xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "DRI2 requires UXA\n");
 +	return FALSE;
 +    }
 +
 +    sprintf(buf, "pci:%04x:%02x:%02x.%d",
 +	    pI830->PciInfo->domain,
 +	    pI830->PciInfo->bus,
 +	    pI830->PciInfo->dev,
 +	    pI830->PciInfo->func);
 +
 +    info.fd = drmOpen("i915", buf);
 +    if (info.fd < 0) {
 +	xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Failed to open DRM device\n");
 +	return FALSE;
 +    }
 +
 +    /* The whole drmOpen thing is a fiasco and we need to find a way
 +     * back to just using open(2).  For now, however, lets just make
 +     * things worse with even more ad hoc directory walking code to
 +     * discover the device file name. */
 +
 +    p = pI830->deviceName;
 +    for (i = 0; i < DRM_MAX_MINOR; i++) {
 +	sprintf(p, DRM_DEV_NAME, DRM_DIR_NAME, i);
 +	fd = open(p, O_RDWR);
 +	if (fd < 0)
 +	    continue;
 +
 +	busId = drmGetBusid(fd);
 +	close(fd);
 +	if (busId == NULL)
 +	    continue;
 +
 +	cmp = strcmp(busId, buf);
 +	drmFree(busId);
 +	if (cmp == 0)
 +	    break;
 +    }
 +    if (i == DRM_MAX_MINOR) {
 +	xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
 +		   "DRI2: failed to open drm device\n");
 +	return FALSE;
 +    }
 +
 +    info.driverName = IS_I965G(pI830) ? "i965" : "i915";
 +    info.deviceName = p;
 +    info.version = 1;
 +
 +    info.CreateBuffers = I830DRI2CreateBuffers;
 +    info.DestroyBuffers = I830DRI2DestroyBuffers;
 +    info.CopyRegion = I830DRI2CopyRegion;
 +
 +    pI830->drmSubFD = info.fd;
 +
 +    return DRI2ScreenInit(pScreen, &info);
 +}
 +
 +void I830DRI2CloseScreen(ScreenPtr pScreen)
 +{
 +    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
 +    I830Ptr pI830 = I830PTR(pScrn);
 +
 +    DRI2CloseScreen(pScreen);
 +    pI830->directRenderingType = DRI_NONE;
 +}
 +
 +#endif
diff --cc src/i830_driver.c
index 7bc10fd,1407a22..5775763
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@@ -1564,26 -1565,12 +1566,12 @@@ I830AccelMethodInit(ScrnInfoPtr pScrn
  	} else if (pScrn->depth != 16 && pScrn->depth != 24) {
  	    xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "DRI is disabled because it "
  		       "runs only at depths 16 and 24.\n");
 -	    pI830->directRenderingDisabled = TRUE;
 +	    pI830->directRenderingType = DRI_DISABLED;
  	}
  
 -	if (!pI830->directRenderingDisabled) {
 +	if (pI830->directRenderingType == DRI_XF86DRI) {
- 	    pI830->allocate_classic_textures = TRUE;
- 
- 	    from = X_PROBED;
- 
- #ifdef XF86DRI_MM
- 	    if (!IS_I965G(pI830)) {
- 		Bool tmp;
- 
- 		if (xf86GetOptValBool(pI830->Options,
- 				      OPTION_INTELTEXPOOL, &tmp)) {
- 		    from = X_CONFIG;
- 		    if (!tmp)
- 			pI830->allocate_classic_textures = FALSE;
- 		}
- 	    }
- #endif /* XF86DRI_MM */
+ 	   pI830->allocate_classic_textures =
+ 	      xf86ReturnOptValBool(pI830->Options, OPTION_LEGACY3D, TRUE);
  	}
      }
  #endif /* XF86DRI */
@@@ -3558,12 -3517,13 +3532,14 @@@ I830LeaveVT(int scrnIndex, int flags
     }
  
  #ifdef XF86DRI
 -   if (pI830->directRenderingOpen) {
 +   if (pI830->directRenderingOpen &&
 +       pI830->directRenderingType == DRI_XF86DRI) {
        DRILock(screenInfo.screens[pScrn->scrnIndex], 0);
  
-       I830DRISetVBlankInterrupt (pScrn, FALSE);
-       drmCtlUninstHandler(pI830->drmSubFD);
+       if (!pI830->memory_manager) {
+ 	  I830DRISetVBlankInterrupt (pScrn, FALSE);
+ 	  drmCtlUninstHandler(pI830->drmSubFD);
+       }
     }
  #endif
  
diff --cc src/i830_memory.c
index 276f900,caae135..2bbffed
--- a/src/i830_memory.c
+++ b/src/i830_memory.c
@@@ -431,24 -432,33 +432,34 @@@ i830_allocator_init(ScrnInfoPtr pScrn, 
      pI830->memory_list = start;
  
  #ifdef XF86DRI
-     if (pI830->directRenderingType == DRI_XF86DRI)
+     has_gem = FALSE;
+     has_dri = FALSE;
+     
 -    if (pI830->directRenderingEnabled &&
++    if (pI830->directRenderingType == DRI_XF86DRI &&
+ 	xf86LoaderCheckSymbol ("DRIQueryVersion"))
+     {
  	DRIQueryVersion(&dri_major, &dri_minor, &dri_patch);
+ 	has_dri = TRUE;
+     }
  
-     has_gem = 0;
-     gp.param = I915_PARAM_HAS_GEM;
-     gp.value = &has_gem;
- 
-     (void)drmCommandWriteRead(pI830->drmSubFD, DRM_I915_GETPARAM,
- 			      &gp, sizeof(gp));
 -    if (pI830->directRenderingEnabled)
++    if (pI830->directRenderingType >= DRI_XF86DRI)
+     {
+ 	has_gem = FALSE;
+ 	gp.param = I915_PARAM_HAS_GEM;
+ 	gp.value = &has_gem;
+     
+ 	(void)drmCommandWriteRead(pI830->drmSubFD, DRM_I915_GETPARAM,
+ 				  &gp, sizeof(gp));
+     }
  
      /* Now that we have our manager set up, initialize the kernel MM if
       * possible, covering almost all of the aperture.  We need libdri interface
       * 5.4 or newer so we can rely on the lock being held after DRIScreenInit,
       * rather than after DRIFinishScreenInit.
       */
-     if ((pI830->directRenderingType == DRI_XF86DRI && has_gem &&
- 	 (dri_major > 5 || (dri_major == 5 && dri_minor >= 4))) ||
 -    if (pI830->directRenderingEnabled && has_gem && has_dri &&
 -	(dri_major > 5 || (dri_major == 5 && dri_minor >= 4)))
++    if ((pI830->directRenderingType == DRI_XF86DRI && has_gem && has_dri &&
++	(dri_major > 5 || (dri_major == 5 && dri_minor >= 4))) ||
 +	(pI830->directRenderingType == DRI_DRI2 && has_gem))
      {
  	int mmsize;
  
commit 3dd7f0f9423bb891bc99cd3b77dc3d57e057a7ef
Author: Kristian Høgsberg <krh at redhat.com>
Date:   Tue Oct 14 23:57:10 2008 -0400

    Update to DRI2 changes.
    
    Implement DRI2CopyRegion and provide drm device filename to DRI2 module.

diff --git a/src/i830.h b/src/i830.h
index 55db772..823bfef 100644
--- a/src/i830.h
+++ b/src/i830.h
@@ -593,6 +593,7 @@ typedef struct _I830Rec {
    I830ConfigPrivPtr pVisualConfigsPriv;
    drm_handle_t buffer_map;
    drm_handle_t ring_map;
+   char deviceName[64];
 #endif
 
    /* Broken-out options. */
diff --git a/src/i830_accel.c b/src/i830_accel.c
index c935af6..52e22ba 100644
--- a/src/i830_accel.c
+++ b/src/i830_accel.c
@@ -322,7 +322,7 @@ I830AccelInit(ScreenPtr pScreen)
      */
     if (IS_I965G(pI830)) {
 	pI830->accel_pixmap_offset_alignment = 4 * 2;
-	pI830->accel_pixmap_pitch_alignment = 16;
+	pI830->accel_pixmap_pitch_alignment = 64;
 	pI830->accel_max_x = 8192;
 	pI830->accel_max_y = 8192;
     } else {
diff --git a/src/i830_dri.c b/src/i830_dri.c
index da1588c..12de9d4 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -68,6 +68,8 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <sys/types.h>
 #include <sys/ioctl.h>
 #include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
 
 #include "xf86.h"
 #include "xf86_OSproc.h"
@@ -1850,13 +1852,13 @@ I830DRI2CreateBuffers(DrawablePtr pDraw, unsigned int *attachments, int count)
 
     pDepthPixmap = NULL;
     for (i = 0; i < count; i++) {
-	if (attachments[i] == DRI2_BUFFER_FRONT_LEFT) {
+	if (attachments[i] == DRI2BufferFrontLeft) {
 	    if (pDraw->type == DRAWABLE_PIXMAP)
 		pPixmap = (PixmapPtr) pDraw;
 	    else
 		pPixmap = (*pScreen->GetWindowPixmap)((WindowPtr) pDraw);
 	    pPixmap->refcnt++;
-	} else if (attachments[i] == DRI2_BUFFER_STENCIL && pDepthPixmap) {
+	} else if (attachments[i] == DRI2BufferStencil && pDepthPixmap) {
 	    pPixmap = pDepthPixmap;
 	    pPixmap->refcnt++;
 	} else {
@@ -1866,7 +1868,7 @@ I830DRI2CreateBuffers(DrawablePtr pDraw, unsigned int *attachments, int count)
 					       pDraw->depth, 0);
 	}
 
-	if (attachments[i] == DRI2_BUFFER_DEPTH)
+	if (attachments[i] == DRI2BufferDepth)
 	    pDepthPixmap = pPixmap;
 
 	buffers[i].attachment = attachments[i];
@@ -1907,20 +1909,24 @@ I830DRI2DestroyBuffers(DrawablePtr pDraw, DRI2BufferPtr buffers, int count)
 }
 
 static void
-I830DRI2SwapBuffers(DrawablePtr pDraw, DRI2BufferPtr pSrcBuffer,
-		    int x, int y, int width, int height)
+I830DRI2CopyRegion(DrawablePtr pDraw, RegionPtr pRegion,
+		   DRI2BufferPtr pDestBuffer, DRI2BufferPtr pSrcBuffer)
 {
     I830DRI2BufferPrivatePtr private = pSrcBuffer->driverPrivate;
     ScreenPtr pScreen = pDraw->pScreen;
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
     I830Ptr pI830 = I830PTR(pScrn);
     PixmapPtr pPixmap = private->pPixmap;
+    RegionPtr pCopyClip;
     GCPtr pGC;
 
     pGC = GetScratchGC(pDraw->depth, pScreen);
+    pCopyClip = REGION_CREATE(pScreen, NULL, 0);
+    REGION_COPY(pScreen, pCopyClip, pRegion);
+    (*pGC->funcs->ChangeClip) (pGC, CT_REGION, pCopyClip, 0);
     ValidateGC(pDraw, pGC);
     (*pGC->ops->CopyArea)(&pPixmap->drawable,
-			  pDraw, pGC, x, y, width, height, x, y);
+			  pDraw, pGC, 0, 0, pDraw->width, pDraw->height, 0, 0);
     FreeScratchGC(pGC);
 
     /* Emit a flush of the rendering cache, or on the 965 and beyond
@@ -1944,26 +1950,61 @@ Bool I830DRI2ScreenInit(ScreenPtr pScreen)
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
     I830Ptr pI830 = I830PTR(pScrn);
     DRI2InfoRec info;
-    char busId[64];
+    char *p, *busId, buf[64];
+    int fd, i, cmp;
 
     if (pI830->accel != ACCEL_UXA) {
 	xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "DRI2 requires UXA\n");
 	return FALSE;
     }
 
-    sprintf(busId, "PCI:%d:%d:%d",
-	    ((pI830->PciInfo->domain << 8) | pI830->PciInfo->bus),
-	    pI830->PciInfo->dev, pI830->PciInfo->func);
+    sprintf(buf, "pci:%04x:%02x:%02x.%d",
+	    pI830->PciInfo->domain,
+	    pI830->PciInfo->bus,
+	    pI830->PciInfo->dev,
+	    pI830->PciInfo->func);
+
+    info.fd = drmOpen("i915", buf);
+    if (info.fd < 0) {
+	xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Failed to open DRM device\n");
+	return FALSE;
+    }
+
+    /* The whole drmOpen thing is a fiasco and we need to find a way
+     * back to just using open(2).  For now, however, lets just make
+     * things worse with even more ad hoc directory walking code to
+     * discover the device file name. */
+
+    p = pI830->deviceName;
+    for (i = 0; i < DRM_MAX_MINOR; i++) {
+	sprintf(p, DRM_DEV_NAME, DRM_DIR_NAME, i);
+	fd = open(p, O_RDWR);
+	if (fd < 0)
+	    continue;
+
+	busId = drmGetBusid(fd);
+	close(fd);
+	if (busId == NULL)
+	    continue;
+
+	cmp = strcmp(busId, buf);
+	drmFree(busId);
+	if (cmp == 0)
+	    break;
+    }
+    if (i == DRM_MAX_MINOR) {
+	xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
+		   "DRI2: failed to open drm device\n");
+	return FALSE;
+    }
 
     info.driverName = IS_I965G(pI830) ? "i965" : "i915";
+    info.deviceName = p;
     info.version = 1;
-    info.fd = drmOpen(info.driverName, busId);
-    if (info.fd < 0)
-	return FALSE;
 
     info.CreateBuffers = I830DRI2CreateBuffers;
     info.DestroyBuffers = I830DRI2DestroyBuffers;
-    info.SwapBuffers = I830DRI2SwapBuffers;
+    info.CopyRegion = I830DRI2CopyRegion;
 
     pI830->drmSubFD = info.fd;
 
diff --git a/src/i830_driver.c b/src/i830_driver.c
index 46e33bf..7bc10fd 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -1661,8 +1661,8 @@ I830DrmModeInit(ScrnInfoPtr pScrn)
     char *bus_id;
     char *s;
 
-    /* Default to EXA but allow override */
-    pI830->accel = ACCEL_EXA;
+    /* Default to UXA but allow override */
+    pI830->accel = ACCEL_UXA;
 
     if ((s = (char *)xf86GetOptValString(pI830->Options, OPTION_ACCELMETHOD))) {
 	if (!xf86NameCmp(s, "EXA"))
@@ -1670,7 +1670,7 @@ I830DrmModeInit(ScrnInfoPtr pScrn)
 	else if (!xf86NameCmp(s, "UXA"))
 	    pI830->accel = ACCEL_UXA;
 	else
-	    pI830->accel = ACCEL_EXA;
+	    pI830->accel = ACCEL_UXA;
     }
 
     bus_id = DRICreatePCIBusID(pI830->PciInfo);
@@ -1688,7 +1688,7 @@ I830DrmModeInit(ScrnInfoPtr pScrn)
     pI830->drmSubFD = pI830->drmmode.fd;
     xfree(bus_id);
 
-    pI830->directRenderingDisabled = FALSE;
+    pI830->directRenderingType = DRI_DRI2;
     pI830->allocate_classic_textures = FALSE;
 
     i830_init_bufmgr(pScrn);
commit 282f51c3f0e5bc2cedd2f60f458ca2662290d471
Merge: 8a54e3b... 4dd0068...
Author: Kristian Høgsberg <krh at redhat.com>
Date:   Tue Oct 14 23:13:40 2008 -0400

    Merge commit 'origin/master' into HEAD

commit 8a54e3be5c5057fe8e3c52c03401fdada7978c45
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Sep 12 12:47:13 2008 -0700

    Fix mis-merge of DRI2 changes related to pI830->directRenderingType
    
    The old code had a directRendering boolean, the new one has an enum. A bunch
    of the merges failed to remove the '!' in front of the old name, breaking a
    bunch of 'we don't have DRI' tests.

diff --git a/src/i830_batchbuffer.c b/src/i830_batchbuffer.c
index 6e71b50..47fc331 100644
--- a/src/i830_batchbuffer.c
+++ b/src/i830_batchbuffer.c
@@ -124,7 +124,7 @@ intel_batch_init(ScrnInfoPtr pScrn)
 
     intel_next_batch(pScrn);
 
-    if (!pI830->directRenderingType <= DRI_NONE) {
+    if (pI830->directRenderingType <= DRI_NONE) {
 	if (IS_I830(pI830) || IS_845G(pI830)) {
 	    intel_bufmgr_fake_set_exec_callback(pI830->bufmgr,
 						intel_nondrm_exec_i830,
diff --git a/src/i830_driver.c b/src/i830_driver.c
index a8bf925..9f76b7c 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -1715,7 +1715,7 @@ I830XvInit(ScrnInfoPtr pScrn)
 #endif
 #ifdef INTEL_XVMC
     pI830->XvMCEnabled = FALSE;
-    from =  (!pI830->directRenderingType != DRI_DISABLED &&
+    from =  (pI830->directRenderingType != DRI_DISABLED &&
 	     xf86GetOptValBool(pI830->Options, OPTION_XVMC,
 			       &pI830->XvMCEnabled)) ? X_CONFIG : X_DEFAULT;
     xf86DrvMsg(pScrn->scrnIndex, from, "Intel XvMC decoder %sabled\n",
@@ -1731,7 +1731,7 @@ I830DriOptsInit(ScrnInfoPtr pScrn)
     MessageType from = X_PROBED;
 
     pI830->allowPageFlip = FALSE;
-    from = (!pI830->directRenderingType != DRI_DISABLED &&
+    from = (pI830->directRenderingType != DRI_DISABLED &&
 	    xf86GetOptValBool(pI830->Options, OPTION_PAGEFLIP,
 			      &pI830->allowPageFlip)) ? X_CONFIG : X_DEFAULT;
 
@@ -1739,7 +1739,7 @@ I830DriOptsInit(ScrnInfoPtr pScrn)
 	       pI830->allowPageFlip ? "" : " not");
 
     pI830->TripleBuffer = FALSE;
-    from =  (!pI830->directRenderingType != DRI_DISABLED &&
+    from =  (pI830->directRenderingType != DRI_DISABLED &&
 	     xf86GetOptValBool(pI830->Options, OPTION_TRIPLEBUFFER,
 			       &pI830->TripleBuffer)) ? X_CONFIG : X_DEFAULT;
 
@@ -2008,7 +2008,7 @@ I830PreInit(ScrnInfoPtr pScrn, int flags)
 #if defined(XF86DRI)
    /* Load the dri module if requested. */
    if (xf86ReturnOptValBool(pI830->Options, OPTION_DRI, FALSE) &&
-       !pI830->directRenderingType != DRI_DISABLED) {
+       pI830->directRenderingType != DRI_DISABLED) {
       if (xf86LoadSubModule(pScrn, "dri")) {
 	 xf86LoaderReqSymLists(I810driSymbols, I810drmSymbols, NULL);
       }
commit d8d95d8c71f2cd4bab277f44132ece7963714a5b
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Sep 11 16:11:46 2008 -0700

    Fix build failures that should have been in the previous merge commit.

diff --git a/src/i830_batchbuffer.c b/src/i830_batchbuffer.c
index 3727f0e..6e71b50 100644
--- a/src/i830_batchbuffer.c
+++ b/src/i830_batchbuffer.c
@@ -124,7 +124,7 @@ intel_batch_init(ScrnInfoPtr pScrn)
 
     intel_next_batch(pScrn);
 
-    if (!pI830->directRenderingEnabled) {
+    if (!pI830->directRenderingType <= DRI_NONE) {
 	if (IS_I830(pI830) || IS_845G(pI830)) {
 	    intel_bufmgr_fake_set_exec_callback(pI830->bufmgr,
 						intel_nondrm_exec_i830,
diff --git a/src/i830_dri.c b/src/i830_dri.c
index 4bfe286..da1588c 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -1877,7 +1877,7 @@ I830DRI2CreateBuffers(DrawablePtr pDraw, unsigned int *attachments, int count)
 	privates[i].pPixmap = pPixmap;
 
 	bo = i830_get_pixmap_bo (pPixmap);
-	if (intel_bo_flink(bo, &buffers[i].name) != 0) {
+	if (dri_bo_flink(bo, &buffers[i].name) != 0) {
 	    /* failed to name buffer */
 	}
 
commit 7e8eb6e20b6b1a2a3c1ef28f694fa23c68a15c48
Merge: fba9b5a... 58a3817...
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Sep 10 14:10:26 2008 -0700

    Merge branch 'master' into dri2
    
    Conflicts:
    
    	src/i830_batchbuffer.c
    	src/i830_display.c

commit fba9b5aff450d874ef98cafd3ecc0fd85f9597b5
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Sep 3 16:49:07 2008 +0100

    DRI2: Move pixmap pitch alignment for use with depth to pixmap create.
    
    The previous location for pitch fixup would have only worked when depth was
    used with the backbuffer, and no page flipping or other adventures occurred.

diff --git a/src/i830_accel.c b/src/i830_accel.c
index 4059121..c6044a5 100644
--- a/src/i830_accel.c
+++ b/src/i830_accel.c
@@ -302,6 +302,7 @@ I830AccelInit(ScreenPtr pScreen)
      * i915 limits 3D textures to pitch of 16B - 8kB, in dwords.
      * i915 limits 3D destination to ~4kB-aligned offset if tiled.
      * i915 limits 3D destination to pitch of 16B - 8kB, in dwords, if un-tiled.
+     * i915 limits 3D destination to pitch 64B-aligned if used with depth.
      * i915 limits 3D destination to pitch of 512B - 8kB, in tiles, if tiled.
      * i915 limits 3D destination to POT aligned pitch if tiled.
      * i915 limits 3D destination drawing rect to w,h of 2048,2048.
@@ -326,7 +327,7 @@ I830AccelInit(ScreenPtr pScreen)
 	pI830->accel_max_y = 8192;
     } else {
 	pI830->accel_pixmap_offset_alignment = 4;
-	pI830->accel_pixmap_pitch_alignment = 16;
+	pI830->accel_pixmap_pitch_alignment = 64;
 	pI830->accel_max_x = 2048;
 	pI830->accel_max_y = 2048;
     }
diff --git a/src/i830_dri.c b/src/i830_dri.c
index 56339f3..3168a4b 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -1830,7 +1830,7 @@ I830DRI2CreateBuffers(DrawablePtr pDraw, unsigned int *attachments, int count)
     ScreenPtr pScreen = pDraw->pScreen;
     DRI2BufferPtr buffers;
     dri_bo *bo;
-    int i, depth, width, cpp;
+    int i;
     I830DRI2BufferPrivatePtr privates;
     PixmapPtr pPixmap, pDepthPixmap;
 
@@ -1841,11 +1841,7 @@ I830DRI2CreateBuffers(DrawablePtr pDraw, unsigned int *attachments, int count)
     if (privates == NULL) {
 	xfree(buffers);
 	return NULL;
-    }	
-
-    /* The byte rowstride for 3D buffers must be a multiple of 64 bytes. */
-    cpp = pDraw->bitsPerPixel / 8;
-    width = ((pDraw->width * cpp + 63) & ~63) / cpp;
+    }
 
     pDepthPixmap = NULL;
     for (i = 0; i < count; i++) {
@@ -1860,9 +1856,9 @@ I830DRI2CreateBuffers(DrawablePtr pDraw, unsigned int *attachments, int count)
 	    pPixmap->refcnt++;
 	} else {
 	    pPixmap = (*pScreen->CreatePixmap)(pScreen,
-					      width,
-					      pDraw->height, 
-					      pDraw->depth, 0);
+					       pDraw->width,
+					       pDraw->height,
+					       pDraw->depth, 0);
 	}
 
 	if (attachments[i] == DRI2_BUFFER_DEPTH)
commit 71ec627c3a65cfc7bca7353af43c60b18e73230d
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Sep 3 16:37:25 2008 +0100

    DRI2: Emit the MI_FLUSH before flushing batch in swapbuffers.
    
    Should fix issues with swapbuffers flushing to front buffer on 965.

diff --git a/src/i830_dri.c b/src/i830_dri.c
index 6519b48..56339f3 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -1576,7 +1576,7 @@ i830_update_sarea(ScrnInfoPtr pScrn, drmI830Sarea *sarea)
    I830Ptr pI830 = I830PTR(pScrn);
 
    if (pI830->directRenderingType == DRI_DRI2)
-       return TRUE;
+       return;
 
    sarea->width = pScreen->width;
    sarea->height = pScreen->height;
@@ -1921,12 +1921,17 @@ I830DRI2SwapBuffers(DrawablePtr pDraw, DRI2BufferPtr pSrcBuffer,
     (*pGC->ops->CopyArea)(&pPixmap->drawable,
 			  pDraw, pGC, x, y, width, height, x, y);
     FreeScratchGC(pGC);
-    
+
+    /* Emit a flush of the rendering cache, or on the 965 and beyond
+     * rendering results may not hit the framebuffer until significantly
+     * later.
+     */
+    I830EmitFlush(pScrn);
+    pI830->need_mi_flush = FALSE;
+
     /* We can't rely on getting into the block handler before the DRI
      * client gets to run again so flush now. */
     intel_batch_flush(pScrn);
-    I830EmitFlush(pScrn);
-    pI830->need_mi_flush = FALSE;
 #if ALWAYS_SYNC
     I830Sync(pScrn);
 #endif
commit daaefd173b4c98d0ebabd43352bfa3a030a62e4b
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Sep 3 16:26:27 2008 +0100

    UXA: Re-enable non-965 render.

diff --git a/src/i830_exa.c b/src/i830_exa.c
index 4cfbdb9..a90bd85 100644
--- a/src/i830_exa.c
+++ b/src/i830_exa.c
@@ -903,7 +903,6 @@ i830_uxa_init (ScreenPtr pScreen)
     i830->uxa_driver->copy = I830EXACopy;
     i830->uxa_driver->done_copy = I830EXADoneCopy;
 
-#if 0
     /* Composite */
     if (!IS_I9XX(i830)) {
     	i830->uxa_driver->check_composite = i830_check_composite;
@@ -918,12 +917,13 @@ i830_uxa_init (ScreenPtr pScreen)
     	i830->uxa_driver->composite = i830_composite;
     	i830->uxa_driver->done_composite = i830_done_composite;
     } else {
+#if 0
  	i830->uxa_driver->check_composite = i965_check_composite;
  	i830->uxa_driver->prepare_composite = i965_prepare_composite;
  	i830->uxa_driver->composite = i965_composite;
  	i830->uxa_driver->done_composite = i830_done_composite;
-    }
 #endif
+    }
 
     i830->uxa_driver->prepare_access = i830_uxa_prepare_access;
     i830->uxa_driver->finish_access = i830_uxa_finish_access;
commit 32bb5fc7db14911d0438aea1504e1551b2c9fc25
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Sep 3 16:19:03 2008 +0100

    Don't set up sarea or drm mappings in DRI2 mode.

diff --git a/src/i830_dri.c b/src/i830_dri.c
index 2b4a46f..6519b48 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -1575,6 +1575,9 @@ i830_update_sarea(ScrnInfoPtr pScrn, drmI830Sarea *sarea)
    ScreenPtr pScreen = pScrn->pScreen;
    I830Ptr pI830 = I830PTR(pScrn);
 
+   if (pI830->directRenderingType == DRI_DRI2)
+       return TRUE;
+
    sarea->width = pScreen->width;
    sarea->height = pScreen->height;
    sarea->pitch = pScrn->displayWidth;
@@ -1672,6 +1675,9 @@ i830_update_dri_mappings(ScrnInfoPtr pScrn, drmI830Sarea *sarea)
 {
    I830Ptr pI830 = I830PTR(pScrn);
 
+   if (pI830->directRenderingType == DRI_DRI2)
+       return TRUE;
+
    if (!i830_do_addmap(pScrn, pI830->front_buffer, &sarea->front_handle,
 		       &sarea->front_size, &sarea->front_offset)) {
        xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Disabling DRI.\n");
commit 4a5e31138115f435be7f8f5999b1b2329a18d669
Author: Kristian Høgsberg <krh at redhat.com>
Date:   Wed Sep 3 16:18:23 2008 +0100

    Fix broken test for DRI1 in DRI2 conversion.

diff --git a/src/i830_driver.c b/src/i830_driver.c
index 04f2646..665d781 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -3296,7 +3296,7 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
        pI830->directRenderingType = DRI_NONE;
 
    /* If we failed for any reason, free DRI memory. */
-   if (!pI830->directRenderingType != DRI_XF86DRI &&
+   if (pI830->directRenderingType != DRI_XF86DRI &&
        pI830->back_buffer != NULL)
        i830_free_3d_memory(pScrn);
 
commit fd6a9ca5b59a868260eb91272091ea6169091737
Author: Kristian Høgsberg <krh at redhat.com>
Date:   Fri Aug 8 15:36:35 2008 -0400

    Add DRI2 support.

diff --git a/configure.ac b/configure.ac
index e276f0e..161005e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -245,6 +245,7 @@ if test "$XVMC" = yes; then
     	AC_SUBST([XVMCLIB_CFLAGS])
 fi
 
+AC_DEFINE(DRI2, 1,[Enable DRI2 code])
 
 AC_SUBST([DRI_CFLAGS])
 AC_SUBST([XORG_CFLAGS])
diff --git a/src/i830.h b/src/i830.h
index f0efc4e..29ed714 100644
--- a/src/i830.h
+++ b/src/i830.h
@@ -374,6 +374,13 @@ typedef enum accel_method {
     ACCEL_UXA
 } accel_method_t;
 
+enum dri_type {
+    DRI_DISABLED,
+    DRI_NONE,
+    DRI_XF86DRI,
+    DRI_DRI2
+};
+
 typedef struct _I830Rec {
    unsigned char *MMIOBase;
    unsigned char *GTTBase;
@@ -577,8 +584,7 @@ typedef struct _I830Rec {
    /* 965 render acceleration state */
    struct gen4_render_state *gen4_render_state;
 
-   Bool directRenderingDisabled;	/* DRI disabled in PreInit. */
-   Bool directRenderingEnabled;		/* DRI enabled this generation. */
+   enum dri_type directRenderingType;	/* DRI enabled this generation. */
 
 #ifdef XF86DRI
    Bool directRenderingOpen;
@@ -807,6 +813,11 @@ extern Bool I830DRISetHWS(ScrnInfoPtr pScrn);
 extern Bool I830DRIInstIrqHandler(ScrnInfoPtr pScrn);
 #endif
 
+#ifdef DRI2
+Bool I830DRI2ScreenInit(ScreenPtr pScreen);
+void I830DRI2CloseScreen(ScreenPtr pScreen);
+#endif
+
 extern Bool I830AccelInit(ScreenPtr pScreen);
 extern void I830SetupForScreenToScreenCopy(ScrnInfoPtr pScrn, int xdir,
 					   int ydir, int rop,
diff --git a/src/i830_accel.c b/src/i830_accel.c
index 386e653..4059121 100644
--- a/src/i830_accel.c
+++ b/src/i830_accel.c
@@ -138,7 +138,7 @@ I830WaitLpRing(ScrnInfoPtr pScrn, int n, int timeout_millis)
 	     i830_dump_error_state(pScrn);
 	 ErrorF("space: %d wanted %d\n", ring->space, n);
 #ifdef XF86DRI
-	 if (pI830->directRenderingEnabled) {
+	 if (pI830->directRenderingType == DRI_XF86DRI) {
 	    DRIUnlock(screenInfo.screens[pScrn->scrnIndex]);
 	    DRICloseScreen(screenInfo.screens[pScrn->scrnIndex]);
 	 }
@@ -183,7 +183,7 @@ I830Sync(ScrnInfoPtr pScrn)
 #ifdef XF86DRI
    /* VT switching tries to do this.
     */
-   if (!pI830->LockHeld && pI830->directRenderingEnabled) {
+   if (!pI830->LockHeld && pI830->directRenderingType == DRI_XF86DRI) {
       return;
    }
 #endif
@@ -194,7 +194,7 @@ I830Sync(ScrnInfoPtr pScrn)
 
    intel_batch_flush(pScrn);
 
-   if (pI830->directRenderingEnabled) {
+   if (pI830->directRenderingType > DRI_NONE) {
        struct drm_i915_irq_emit emit;
        struct drm_i915_irq_wait wait;
        int ret;
diff --git a/src/i830_batchbuffer.c b/src/i830_batchbuffer.c
index 07ea082..055d7df 100644
--- a/src/i830_batchbuffer.c
+++ b/src/i830_batchbuffer.c
@@ -120,7 +120,7 @@ intel_batch_flush(ScrnInfoPtr pScrn)
     } else {
 	dri_process_relocs(pI830->batch_bo);
 
-	if (pI830->directRenderingEnabled) {
+	if (pI830->directRenderingType > DRI_NONE) {
 	    struct drm_i915_batchbuffer batch;
 	    int ret;
 
diff --git a/src/i830_display.c b/src/i830_display.c
index cfd4e6f..3257b79 100644
--- a/src/i830_display.c
+++ b/src/i830_display.c
@@ -422,7 +422,7 @@ i830PipeSetBase(xf86CrtcPtr crtc, int x, int y)
     }
 
 #ifdef XF86DRI
-    if (pI830->directRenderingEnabled) {
+    if (pI830->directRenderingType == DRI_XF86DRI) {
 	drmI830Sarea *sPriv = (drmI830Sarea *) DRIGetSAREAPrivate(pScrn->pScreen);
 
 	if (!sPriv)
@@ -745,7 +745,7 @@ i830_use_fb_compression(xf86CrtcPtr crtc)
     return TRUE;
 }
 
-#if defined(DRM_IOCTL_MODESET_CTL) && defined(XF86DRI)
+#if defined(DRM_IOCTL_MODESET_CTL) && (defined(XF86DRI) || defined(DRI2))
 static void i830_modeset_ctl(xf86CrtcPtr crtc, int pre)
 {
     ScrnInfoPtr pScrn = crtc->scrn;
@@ -753,7 +753,7 @@ static void i830_modeset_ctl(xf86CrtcPtr crtc, int pre)
     I830CrtcPrivatePtr intel_crtc = crtc->driver_private;
     struct drm_modeset_ctl modeset;
 
-    if (!pI830-directRenderingEnabled)
+    if (pI830->directRenderingType <= DRI_NONE)
       return;
 
     modeset.crtc = intel_crtc->plane;
@@ -777,7 +777,7 @@ static void i830_modeset_ctl(xf86CrtcPtr crtc, int dpms_state)
 {
     return;
 }
-#endif /* DRM_IOCTL_MODESET_CTL && XF86DRI */
+#endif /* DRM_IOCTL_MODESET_CTL && (XF86DRI || DRI2) */
 
 /**
  * Sets the power management mode of the pipe and plane.
@@ -902,7 +902,7 @@ i830_crtc_dpms(xf86CrtcPtr crtc, int mode)
     intel_crtc->dpms_mode = mode;
 
 #ifdef XF86DRI
-    if (pI830->directRenderingEnabled) {
+    if (pI830->directRenderingType == DRI_XF86DRI) {
 	drmI830Sarea *sPriv = (drmI830Sarea *) DRIGetSAREAPrivate(pScrn->pScreen);
 	Bool enabled = crtc->enabled && mode != DPMSModeOff;
 
diff --git a/src/i830_dri.c b/src/i830_dri.c
index ca3bc62..2b4a46f 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -88,6 +88,10 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include "dristruct.h"
 
+#ifdef DRI2
+#include "dri2.h"
+#endif
+
 static Bool I830InitVisualConfigs(ScreenPtr pScreen);
 static Bool I830CreateContext(ScreenPtr pScreen, VisualPtr visual,
 			      drm_context_t hwContext, void *pVisualConfigPriv,
@@ -934,12 +938,14 @@ Bool
 I830DRIResume(ScreenPtr pScreen)
 {
    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+   I830Ptr pI830 = I830PTR(pScrn);
 
    DPRINTF(PFX, "I830DRIResume\n");
 
    I830ResumeDma(pScrn);
 
-   I830DRIInstIrqHandler(pScrn);
+   if (!pI830->memory_manager)
+      I830DRIInstIrqHandler(pScrn);
 
    return TRUE;
 }
@@ -957,7 +963,7 @@ I830DRICloseScreen(ScreenPtr pScreen)
    REGION_UNINIT(pScreen, &pI830->driRegion);
 #endif
 
-   if (pI830DRI->irq) {
+   if (!pI830->memory_manager && pI830DRI->irq) {
        drmCtlUninstHandler(pI830->drmSubFD);
        pI830DRI->irq = 0;
    }
@@ -978,7 +984,7 @@ I830DRICloseScreen(ScreenPtr pScreen)
       xfree(pI830->pVisualConfigs);
    if (pI830->pVisualConfigsPriv)
       xfree(pI830->pVisualConfigsPriv);
-   pI830->directRenderingEnabled = FALSE;
+   pI830->directRenderingType = DRI_NONE;
 }
 
 static Bool
@@ -1756,7 +1762,7 @@ I830DRISetVBlankInterrupt (ScrnInfoPtr pScrn, Bool on)
     if (!pI830->want_vblank_interrupts)
 	on = FALSE;
 
-    if (pI830->directRenderingEnabled && pI830->drmMinor >= 5) {
+    if (pI830->directRenderingType == DRI_XF86DRI && pI830->drmMinor >= 5) {
 	if (on) {
 	    if (xf86_config->num_crtc > 1 && xf86_config->crtc[1]->enabled)
 		if (pI830->drmMinor >= 6)
@@ -1782,7 +1788,7 @@ I830DRILock(ScrnInfoPtr pScrn)
 {
    I830Ptr pI830 = I830PTR(pScrn);
 
-   if (pI830->directRenderingEnabled && !pI830->LockHeld) {
+   if (pI830->directRenderingType == DRI_XF86DRI && !pI830->LockHeld) {
       DRILock(screenInfo.screens[pScrn->scrnIndex], 0);
       pI830->LockHeld = 1;
       if (!pI830->memory_manager)
@@ -1800,8 +1806,165 @@ I830DRIUnlock(ScrnInfoPtr pScrn)
 {
    I830Ptr pI830 = I830PTR(pScrn);
 
-   if (pI830->directRenderingEnabled && pI830->LockHeld) {
+   if (pI830->directRenderingType == DRI_XF86DRI && pI830->LockHeld) {
       DRIUnlock(screenInfo.screens[pScrn->scrnIndex]);
       pI830->LockHeld = 0;
    }
 }
+
+#ifdef DRI2
+
+typedef struct {
+    PixmapPtr pPixmap;
+} I830DRI2BufferPrivateRec, *I830DRI2BufferPrivatePtr;
+
+static DRI2BufferPtr
+I830DRI2CreateBuffers(DrawablePtr pDraw, unsigned int *attachments, int count)
+{
+    ScreenPtr pScreen = pDraw->pScreen;
+    DRI2BufferPtr buffers;
+    dri_bo *bo;
+    int i, depth, width, cpp;
+    I830DRI2BufferPrivatePtr privates;
+    PixmapPtr pPixmap, pDepthPixmap;
+
+    buffers = xcalloc(count, sizeof *buffers);
+    if (buffers == NULL)
+	return NULL;
+    privates = xcalloc(count, sizeof *privates);
+    if (privates == NULL) {
+	xfree(buffers);
+	return NULL;
+    }	
+
+    /* The byte rowstride for 3D buffers must be a multiple of 64 bytes. */
+    cpp = pDraw->bitsPerPixel / 8;
+    width = ((pDraw->width * cpp + 63) & ~63) / cpp;
+
+    pDepthPixmap = NULL;
+    for (i = 0; i < count; i++) {
+	if (attachments[i] == DRI2_BUFFER_FRONT_LEFT) {
+	    if (pDraw->type == DRAWABLE_PIXMAP)
+		pPixmap = (PixmapPtr) pDraw;
+	    else
+		pPixmap = (*pScreen->GetWindowPixmap)((WindowPtr) pDraw);
+	    pPixmap->refcnt++;
+	} else if (attachments[i] == DRI2_BUFFER_STENCIL && pDepthPixmap) {
+	    pPixmap = pDepthPixmap;
+	    pPixmap->refcnt++;
+	} else {
+	    pPixmap = (*pScreen->CreatePixmap)(pScreen,
+					      width,
+					      pDraw->height, 
+					      pDraw->depth, 0);
+	}
+
+	if (attachments[i] == DRI2_BUFFER_DEPTH)
+	    pDepthPixmap = pPixmap;
+
+	buffers[i].attachment = attachments[i];
+	buffers[i].pitch = pPixmap->devKind;
+	buffers[i].cpp = pPixmap->drawable.bitsPerPixel / 8;
+	buffers[i].driverPrivate = &privates[i];
+	buffers[i].flags = 0; /* not tiled */
+	privates[i].pPixmap = pPixmap;
+
+	bo = i830_get_pixmap_bo (pPixmap);
+	if (intel_bo_flink(bo, &buffers[i].name) != 0) {
+	    /* failed to name buffer */
+	}
+
+    }
+
+    return buffers;
+}
+
+static void
+I830DRI2DestroyBuffers(DrawablePtr pDraw, DRI2BufferPtr buffers, int count)
+{
+    ScreenPtr pScreen = pDraw->pScreen;
+    I830DRI2BufferPrivatePtr private;
+    int i;
+
+    for (i = 0; i < count; i++)
+    {
+	private = buffers[i].driverPrivate;
+	(*pScreen->DestroyPixmap)(private->pPixmap);
+    }
+
+    if (buffers)
+    {
+	xfree(buffers[0].driverPrivate);
+	xfree(buffers);
+    }
+}
+
+static void
+I830DRI2SwapBuffers(DrawablePtr pDraw, DRI2BufferPtr pSrcBuffer,
+		    int x, int y, int width, int height)
+{
+    I830DRI2BufferPrivatePtr private = pSrcBuffer->driverPrivate;
+    ScreenPtr pScreen = pDraw->pScreen;
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    I830Ptr pI830 = I830PTR(pScrn);
+    PixmapPtr pPixmap = private->pPixmap;
+    GCPtr pGC;
+
+    pGC = GetScratchGC(pDraw->depth, pScreen);
+    ValidateGC(pDraw, pGC);
+    (*pGC->ops->CopyArea)(&pPixmap->drawable,
+			  pDraw, pGC, x, y, width, height, x, y);
+    FreeScratchGC(pGC);
+    
+    /* We can't rely on getting into the block handler before the DRI
+     * client gets to run again so flush now. */
+    intel_batch_flush(pScrn);
+    I830EmitFlush(pScrn);
+    pI830->need_mi_flush = FALSE;
+#if ALWAYS_SYNC
+    I830Sync(pScrn);
+#endif
+    drmCommandNone(pI830->drmSubFD, DRM_I915_GEM_THROTTLE);
+}
+
+Bool I830DRI2ScreenInit(ScreenPtr pScreen)
+{
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    I830Ptr pI830 = I830PTR(pScrn);
+    DRI2InfoRec info;
+    char busId[64];
+
+    if (pI830->accel != ACCEL_UXA) {
+	xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "DRI2 requires UXA\n");
+	return FALSE;
+    }
+
+    sprintf(busId, "PCI:%d:%d:%d",
+	    ((pI830->PciInfo->domain << 8) | pI830->PciInfo->bus),
+	    pI830->PciInfo->dev, pI830->PciInfo->func);
+
+    info.driverName = IS_I965G(pI830) ? "i965" : "i915";
+    info.version = 1;
+    info.fd = drmOpen(info.driverName, busId);
+    if (info.fd < 0)
+	return FALSE;
+
+    info.CreateBuffers = I830DRI2CreateBuffers;
+    info.DestroyBuffers = I830DRI2DestroyBuffers;
+    info.SwapBuffers = I830DRI2SwapBuffers;
+
+    pI830->drmSubFD = info.fd;
+
+    return DRI2ScreenInit(pScreen, &info);
+}
+
+void I830DRI2CloseScreen(ScreenPtr pScreen)
+{
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    I830Ptr pI830 = I830PTR(pScrn);
+
+    DRI2CloseScreen(pScreen);
+    pI830->directRenderingType = DRI_NONE;
+}
+
+#endif
diff --git a/src/i830_driver.c b/src/i830_driver.c
index afce718..04f2646 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -1541,22 +1541,23 @@ I830AccelMethodInit(ScrnInfoPtr pScrn)
 	pI830->SWCursor = TRUE;
     }
 
-    pI830->directRenderingDisabled =
-	!xf86ReturnOptValBool(pI830->Options, OPTION_DRI, TRUE);
+    pI830->directRenderingType = DRI_NONE;
+    if (!xf86ReturnOptValBool(pI830->Options, OPTION_DRI, TRUE))
+	pI830->directRenderingType = DRI_DISABLED;
 
 #ifdef XF86DRI
-    if (!pI830->directRenderingDisabled) {
+    if (pI830->directRenderingType == DRI_XF86DRI) {
 	if ((pI830->accel == ACCEL_NONE) || pI830->SWCursor) {
 	    xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "DRI is disabled because it "
 		       "needs HW cursor and 2D acceleration.\n");
-	    pI830->directRenderingDisabled = TRUE;
+	    pI830->directRenderingType = DRI_DISABLED;
 	} else if (pScrn->depth != 16 && pScrn->depth != 24) {
 	    xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "DRI is disabled because it "
 		       "runs only at depths 16 and 24.\n");
-	    pI830->directRenderingDisabled = TRUE;
+	    pI830->directRenderingType = DRI_DISABLED;
 	}
 
-	if (!pI830->directRenderingDisabled) {
+	if (pI830->directRenderingType == DRI_XF86DRI) {
 	    pI830->allocate_classic_textures = TRUE;
 
 	    from = X_PROBED;
@@ -1714,7 +1715,7 @@ I830XvInit(ScrnInfoPtr pScrn)
 #endif
 #ifdef INTEL_XVMC
     pI830->XvMCEnabled = FALSE;
-    from =  (!pI830->directRenderingDisabled &&
+    from =  (!pI830->directRenderingType != DRI_DISABLED &&
 	     xf86GetOptValBool(pI830->Options, OPTION_XVMC,
 			       &pI830->XvMCEnabled)) ? X_CONFIG : X_DEFAULT;
     xf86DrvMsg(pScrn->scrnIndex, from, "Intel XvMC decoder %sabled\n",
@@ -1730,7 +1731,7 @@ I830DriOptsInit(ScrnInfoPtr pScrn)
     MessageType from = X_PROBED;
 
     pI830->allowPageFlip = FALSE;
-    from = (!pI830->directRenderingDisabled &&
+    from = (!pI830->directRenderingType != DRI_DISABLED &&
 	    xf86GetOptValBool(pI830->Options, OPTION_PAGEFLIP,
 			      &pI830->allowPageFlip)) ? X_CONFIG : X_DEFAULT;
 
@@ -1738,7 +1739,7 @@ I830DriOptsInit(ScrnInfoPtr pScrn)
 	       pI830->allowPageFlip ? "" : " not");
 
     pI830->TripleBuffer = FALSE;
-    from =  (!pI830->directRenderingDisabled &&
+    from =  (!pI830->directRenderingType != DRI_DISABLED &&
 	     xf86GetOptValBool(pI830->Options, OPTION_TRIPLEBUFFER,
 			       &pI830->TripleBuffer)) ? X_CONFIG : X_DEFAULT;
 
@@ -2007,13 +2008,21 @@ I830PreInit(ScrnInfoPtr pScrn, int flags)
 #if defined(XF86DRI)
    /* Load the dri module if requested. */
    if (xf86ReturnOptValBool(pI830->Options, OPTION_DRI, FALSE) &&
-       !pI830->directRenderingDisabled) {
+       !pI830->directRenderingType != DRI_DISABLED) {
       if (xf86LoadSubModule(pScrn, "dri")) {
 	 xf86LoaderReqSymLists(I810driSymbols, I810drmSymbols, NULL);
       }
    }
 #endif
 
+#if defined(DRI2)
+   /* Load the dri2 module if requested. */
+   if (xf86ReturnOptValBool(pI830->Options, OPTION_DRI, FALSE) &&
+       pI830->directRenderingType != DRI_DISABLED) {
+       xf86LoadSubModule(pScrn, "dri2");
+   }
+#endif
+
    pI830->preinit = FALSE;
 
    return TRUE;
@@ -2606,7 +2615,7 @@ IntelEmitInvarientState(ScrnInfoPtr pScrn)
       return;
 
 #ifdef XF86DRI
-   if (pI830->directRenderingEnabled) {
+   if (pI830->directRenderingType == DRI_XF86DRI) {
       drmI830Sarea *sarea = DRIGetSAREAPrivate(pScrn->pScreen);
 
       /* Mark that the X Server was the last holder of the context */
@@ -2752,7 +2761,7 @@ i830_try_memory_allocation(ScrnInfoPtr pScrn)
 {
     I830Ptr pI830 = I830PTR(pScrn);
     Bool tiled = pI830->tiling;
-    Bool dri = pI830->directRenderingEnabled;
+    Bool xf86dri = pI830->directRenderingType == DRI_XF86DRI;
 
     xf86DrvMsg(pScrn->scrnIndex, X_INFO,
 	    "Attempting memory allocation with %stiled buffers.\n",
@@ -2765,7 +2774,7 @@ i830_try_memory_allocation(ScrnInfoPtr pScrn)
 	if (!i830_allocate_pwrctx(pScrn))
 	    goto failed;
 
-    if (dri && !i830_allocate_3d_memory(pScrn))
+    if (xf86dri && !i830_allocate_3d_memory(pScrn))
 	goto failed;
 
     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "%siled allocation successful.\n",
@@ -2869,14 +2878,14 @@ i830_memory_init(ScrnInfoPtr pScrn)
     pI830->fb_compression = FALSE;
 
     /* Try again, but leave DRI enabled */
-    if (pI830->directRenderingEnabled) {
+    if (pI830->directRenderingType == DRI_XF86DRI) {
 	if (i830_try_memory_allocation(pScrn))
 	    return TRUE;
 	else {
 	    i830_reset_allocations(pScrn);
 	    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Couldn't allocate 3D memory, "
 		    "disabling DRI.\n");
-	    pI830->directRenderingEnabled = FALSE;
+	    pI830->directRenderingType = DRI_NONE;
 	}
     }
 
@@ -3009,7 +3018,7 @@ I830AdjustMemory(ScreenPtr pScreen)
    if (!IS_I965G(pI830) && pScrn->displayWidth > 2048) {
       xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 		 "Cannot support DRI with frame buffer width > 2048.\n");
-      pI830->directRenderingDisabled = TRUE;
+      pI830->directRenderingType = DRI_DISABLED;
    }
 }
 
@@ -3030,8 +3039,8 @@ I830SwapPipes(ScrnInfoPtr pScrn)
     * Also make sure the DRM can handle the swap.
     */
    if (I830LVDSPresent(pScrn) && !IS_I965GM(pI830) && !IS_GM45(pI830) &&
-       (!pI830->directRenderingEnabled ||
-	(pI830->directRenderingEnabled && pI830->drmMinor >= 10))) {
+       (pI830->directRenderingType != DRI_XF86DRI ||
+	(pI830->directRenderingType == DRI_XF86DRI && pI830->drmMinor >= 10))) {
        xf86DrvMsg(pScrn->scrnIndex, X_INFO, "adjusting plane->pipe mappings "
 		  "to allow for framebuffer compression\n");
        for (c = 0; c < config->num_crtc; c++) {
@@ -3115,16 +3124,17 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
        I830AdjustMemory(pScreen);
    }
 
+#ifdef DRI2
+   if (pI830->directRenderingType == DRI_NONE && I830DRI2ScreenInit(pScreen))
+       pI830->directRenderingType = DRI_DRI2;
+#endif
+
 #ifdef XF86DRI
    /* If DRI hasn't been explicitly disabled, try to initialize it.
     * It will be used by the memory allocator.
     */
-   if (!pI830->directRenderingDisabled)
-      pI830->directRenderingEnabled = I830DRIScreenInit(pScreen);
-   else
-      pI830->directRenderingEnabled = FALSE;
-#else
-   pI830->directRenderingEnabled = FALSE;
+   if (pI830->directRenderingType == DRI_NONE && I830DRIScreenInit(pScreen))
+       pI830->directRenderingType = DRI_XF86DRI;
 #endif
 
    /* Enable tiling by default */
@@ -3273,25 +3283,25 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     * InitGLXVisuals call back.
     */
 
-   if (pI830->directRenderingEnabled) {
+   if (pI830->directRenderingType == DRI_XF86DRI) {
       if (pI830->accel == ACCEL_NONE || pI830->SWCursor || (pI830->StolenOnly && I830IsPrimary(pScrn))) {
 	 xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "DRI is disabled because it "
 		    "needs HW cursor, 2D accel and AGPGART.\n");
-	 pI830->directRenderingEnabled = FALSE;
+	 pI830->directRenderingType = DRI_NONE;
       }
    }
 
-   if (pI830->directRenderingEnabled)
-       pI830->directRenderingEnabled = I830DRIDoMappings(pScreen);
+   if (pI830->directRenderingType == DRI_XF86DRI &&
+       !I830DRIDoMappings(pScreen))
+       pI830->directRenderingType = DRI_NONE;
 
    /* If we failed for any reason, free DRI memory. */
-   if (!pI830->directRenderingEnabled)
+   if (!pI830->directRenderingType != DRI_XF86DRI &&
+       pI830->back_buffer != NULL)
        i830_free_3d_memory(pScrn);
 
    if (!pI830->use_drm_mode)
        I830SwapPipes(pScrn);
-#else
-   pI830->directRenderingEnabled = FALSE;
 #endif
 
 #ifdef XF86DRI
@@ -3399,8 +3409,9 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
    /* Must be called before EnterVT, so we can acquire the DRI lock when
     * binding our memory.
     */
-   if (pI830->directRenderingEnabled)
-      pI830->directRenderingEnabled = I830DRIFinishScreenInit(pScreen);
+   if (pI830->directRenderingType == DRI_XF86DRI &&
+       !I830DRIFinishScreenInit(pScreen))
+       pI830->directRenderingType = DRI_NONE;
 #endif
 
    /* Must force it before EnterVT, so we are in control of VT and
@@ -3444,19 +3455,23 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
    /* Setup 3D engine, needed for rotation too */
    IntelEmitInvarientState(pScrn);
 
-#ifdef XF86DRI
-   if (pI830->directRenderingEnabled) {
+#if defined(XF86DRI) || defined(DRI2)
+   switch (pI830->directRenderingType) {
+   case DRI_XF86DRI:
       pI830->directRenderingOpen = TRUE;
-      xf86DrvMsg(pScrn->scrnIndex, X_INFO, "direct rendering: Enabled\n");
-   } else if (!pI830->use_drm_mode) {
-      if (pI830->directRenderingDisabled)
-	 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "direct rendering: Disabled\n");
-      else
-	 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "direct rendering: Failed\n");
-   } else {
-       xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-		  "failed to enable direct rendering, aborting\n");
-       return FALSE;
+      xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+		 "direct rendering: XF86DRI Enabled\n");
+      break;
+   case DRI_DRI2:
+      pI830->directRenderingOpen = TRUE;
+      xf86DrvMsg(pScrn->scrnIndex, X_INFO, "direct rendering: DRI2 Enabled\n");
+      break;
+   case DRI_DISABLED:
+      xf86DrvMsg(pScrn->scrnIndex, X_INFO, "direct rendering: Disabled\n");
+      break;
+   case DRI_NONE:
+      xf86DrvMsg(pScrn->scrnIndex, X_INFO, "direct rendering: Failed\n");
+      break;
    }
 #else
    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "direct rendering: Not available\n");
@@ -3541,7 +3556,8 @@ I830LeaveVT(int scrnIndex, int flags)
    }
 
 #ifdef XF86DRI
-   if (pI830->directRenderingOpen) {
+   if (pI830->directRenderingOpen &&
+       pI830->directRenderingType == DRI_XF86DRI) {
       DRILock(screenInfo.screens[pScrn->scrnIndex], 0);
 
       I830DRISetVBlankInterrupt (pScrn, FALSE);
@@ -3698,7 +3714,7 @@ I830EnterVT(int scrnIndex, int flags)
    }
 
 #ifdef XF86DRI
-   if (pI830->directRenderingEnabled) {
+   if (pI830->directRenderingType == DRI_XF86DRI) {
        /* HW status is fixed, we need to set it up before any drm
 	* operation which accessing that page, like irq install, etc.
 	*/
@@ -3709,7 +3725,7 @@ I830EnterVT(int scrnIndex, int flags)
 		   I830DRICloseScreen(pScrn->pScreen);
 		   return FALSE;
 	   }
-	   if (!I830DRIInstIrqHandler(pScrn)) {
+	   if (!pI830->memory_manager && !I830DRIInstIrqHandler(pScrn)) {
 	       I830DRICloseScreen(pScrn->pScreen);
 	       return FALSE;
 	   }
@@ -3830,7 +3846,8 @@ I830CloseScreen(int scrnIndex, ScreenPtr pScreen)
    pI830->bufmgr = NULL;
 
 #ifdef XF86DRI
-   if (pI830->directRenderingOpen) {
+   if (pI830->directRenderingOpen &&
+       pI830->directRenderingType == DRI_XF86DRI) {
 #ifdef DAMAGE
       if (pI830->pDamage) {
 	 PixmapPtr pPix = pScreen->GetScreenPixmap(pScreen);
@@ -3845,6 +3862,13 @@ I830CloseScreen(int scrnIndex, ScreenPtr pScreen)
    }
 #endif
 
+#ifdef DRI2
+   if (pI830->directRenderingOpen && pI830->directRenderingType == DRI_DRI2) {
+      pI830->directRenderingOpen = FALSE;
+      I830DRI2CloseScreen(pScreen);
+   }
+#endif
+
    if (I830IsPrimary(pScrn)) {
       xf86GARTCloseScreen(scrnIndex);
 
diff --git a/src/i830_exa.c b/src/i830_exa.c
index e73bc36..4cfbdb9 100644
--- a/src/i830_exa.c
+++ b/src/i830_exa.c
@@ -903,6 +903,7 @@ i830_uxa_init (ScreenPtr pScreen)
     i830->uxa_driver->copy = I830EXACopy;
     i830->uxa_driver->done_copy = I830EXADoneCopy;
 
+#if 0
     /* Composite */
     if (!IS_I9XX(i830)) {
     	i830->uxa_driver->check_composite = i830_check_composite;
@@ -922,6 +923,7 @@ i830_uxa_init (ScreenPtr pScreen)
  	i830->uxa_driver->composite = i965_composite;
  	i830->uxa_driver->done_composite = i830_done_composite;
     }
+#endif
 
     i830->uxa_driver->prepare_access = i830_uxa_prepare_access;
     i830->uxa_driver->finish_access = i830_uxa_finish_access;
diff --git a/src/i830_memory.c b/src/i830_memory.c
index 443cc4e..1e428d9 100644
--- a/src/i830_memory.c
+++ b/src/i830_memory.c
@@ -408,7 +408,8 @@ i830_allocator_init(ScrnInfoPtr pScrn, unsigned long offset, unsigned long size)
     pI830->memory_list = start;
 
 #ifdef XF86DRI
-    DRIQueryVersion(&dri_major, &dri_minor, &dri_patch);
+    if (pI830->directRenderingType == DRI_XF86DRI)
+	DRIQueryVersion(&dri_major, &dri_minor, &dri_patch);
 
     has_gem = 0;
     gp.param = I915_PARAM_HAS_GEM;
@@ -422,8 +423,9 @@ i830_allocator_init(ScrnInfoPtr pScrn, unsigned long offset, unsigned long size)
      * 5.4 or newer so we can rely on the lock being held after DRIScreenInit,
      * rather than after DRIFinishScreenInit.
      */
-    if (pI830->directRenderingEnabled && has_gem &&
-	(dri_major > 5 || (dri_major == 5 && dri_minor >= 4)))
+    if ((pI830->directRenderingType == DRI_XF86DRI && has_gem &&
+	 (dri_major > 5 || (dri_major == 5 && dri_minor >= 4))) ||
+	(pI830->directRenderingType == DRI_DRI2 && has_gem))
     {
 	int mmsize;
 


More information about the xorg-commit mailing list