xf86-video-intel: 19 commits - src/drmmode_display.c src/i830_accel.c src/i830_debug.c src/i830_debug.h src/i830_driver.c src/i830.h src/i830_memory.c src/i830_video.c src/i830_video.h src/i915_video.c src/i965_video.c

Eric Anholt anholt at kemper.freedesktop.org
Tue Oct 6 16:26:38 PDT 2009


 src/drmmode_display.c |    9 
 src/i830.h            |    4 
 src/i830_accel.c      |    4 
 src/i830_debug.c      |  784 -------------------
 src/i830_debug.h      |    3 
 src/i830_driver.c     |    7 
 src/i830_memory.c     |   42 -
 src/i830_video.c      | 2061 +++++++++++---------------------------------------
 src/i830_video.h      |   20 
 src/i915_video.c      |   33 
 src/i965_video.c      |   50 -
 11 files changed, 527 insertions(+), 2490 deletions(-)

New commits:
commit d26f4c493721dbb2e2cbf4efcf8d37228d1b1f3b
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Oct 5 13:31:31 2009 -0700

    Remove UMS overlay support.
    
    The replacement code is now landed, and the rest of UMS is about to disappear.

diff --git a/src/i830.h b/src/i830.h
index c84fd0c..ac8b80e 100644
--- a/src/i830.h
+++ b/src/i830.h
@@ -387,7 +387,6 @@ typedef struct _I830Rec {
    int batch_atomic_limit;
 
    /* For Xvideo */
-   i830_memory *overlay_regs;
    Bool use_drmmode_overlay;
 #ifdef INTEL_XVMC
    /* For XvMC */
diff --git a/src/i830_memory.c b/src/i830_memory.c
index 26e4cfd..3c15207 100644
--- a/src/i830_memory.c
+++ b/src/i830_memory.c
@@ -342,7 +342,6 @@ i830_reset_allocations(ScrnInfoPtr pScrn)
 	pI830->cursor_mem_argb[p] = NULL;
     }
     pI830->front_buffer = NULL;
-    pI830->overlay_regs = NULL;
     pI830->power_context = NULL;
     pI830->ring.mem = NULL;
     pI830->fake_bufmgr_mem = NULL;
@@ -974,44 +973,6 @@ i830_allocate_ringbuffer(ScrnInfoPtr pScrn)
     return TRUE;
 }
 
-/**
- * Allocate space for overlay registers.
- */
-static Bool
-i830_allocate_overlay(ScrnInfoPtr pScrn)
-{
-    I830Ptr pI830 = I830PTR(pScrn);
-    int flags = 0;
-
-    /* Only allocate if overlay is going to be enabled. */
-    if (!pI830->XvEnabled)
-	return TRUE;
-
-    if (OVERLAY_NOEXIST(pI830))
-	return TRUE;
-
-    if (!OVERLAY_NOPHYSICAL(pI830)) {
-	if (pI830->use_drm_mode)
-            return TRUE;
-	flags |= NEED_PHYSICAL_ADDR;
-    }
-
-    pI830->overlay_regs = i830_allocate_memory(pScrn, "overlay registers",
-					       OVERLAY_SIZE, PITCH_NONE, GTT_PAGE_SIZE,
-					       flags, TILE_NONE);
-    if (pI830->overlay_regs == NULL) {
-	xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
-		   "Failed to allocate Overlay register space.\n");
-	/* This failure isn't fatal. */
-    }
-
-    if (flags & NEED_PHYSICAL_ADDR)
-	if (pI830->use_drm_mode)
-	    ; /* need physical addr */
-
-    return TRUE;
-}
-
 static Bool
 IsTileable(ScrnInfoPtr pScrn, int pitch)
 {
@@ -1293,9 +1254,6 @@ i830_allocate_2d_memory(ScrnInfoPtr pScrn)
 	i830_init_bufmgr(pScrn);
     }
 
-    if (!pI830->use_drm_mode)
-	i830_allocate_overlay(pScrn);
-
     pI830->front_buffer = i830_allocate_framebuffer(pScrn);
     if (pI830->front_buffer == NULL)
 	return FALSE;
diff --git a/src/i830_video.c b/src/i830_video.c
index 5e98f27..9aab60c 100644
--- a/src/i830_video.c
+++ b/src/i830_video.c
@@ -124,75 +124,6 @@ static Atom xvSyncToVblank;
 #define OVERLAY_DEBUG if (0) ErrorF
 #endif
 
-/*
- * OCMD - Overlay Command Register
- */
-#define OCMD_REGISTER		0x30168
-#define MIRROR_MODE		(0x3<<17)
-#define MIRROR_HORIZONTAL	(0x1<<17)
-#define MIRROR_VERTICAL		(0x2<<17)
-#define MIRROR_BOTH		(0x3<<17)
-#define OV_BYTE_ORDER		(0x3<<14)
-#define UV_SWAP			(0x1<<14)
-#define Y_SWAP			(0x2<<14)
-#define Y_AND_UV_SWAP		(0x3<<14)
-#define SOURCE_FORMAT		(0xf<<10)
-#define RGB_888			(0x1<<10)
-#define	RGB_555			(0x2<<10)
-#define	RGB_565			(0x3<<10)
-#define	YUV_422			(0x8<<10)
-#define	YUV_411			(0x9<<10)
-#define	YUV_420			(0xc<<10)
-#define	YUV_422_PLANAR		(0xd<<10)
-#define	YUV_410			(0xe<<10)
-#define TVSYNC_FLIP_PARITY	(0x1<<9)
-#define TVSYNC_FLIP_ENABLE	(0x1<<7)
-#define BUF_TYPE		(0x1<<5)
-#define BUF_TYPE_FRAME		(0x0<<5)
-#define BUF_TYPE_FIELD		(0x1<<5)
-#define TEST_MODE		(0x1<<4)
-#define BUFFER_SELECT		(0x3<<2)
-#define BUFFER0			(0x0<<2)
-#define BUFFER1			(0x1<<2)
-#define FIELD_SELECT		(0x1<<1)
-#define FIELD0			(0x0<<1)
-#define FIELD1			(0x1<<1)
-#define OVERLAY_ENABLE		0x1
-
-#define OFC_UPDATE		0x1
-
-/* OCONFIG register */
-#define CC_OUT_8BIT		(0x1<<3)
-#define OVERLAY_PIPE_MASK	(0x1<<18)		
-#define OVERLAY_PIPE_A		(0x0<<18)		
-#define OVERLAY_PIPE_B		(0x1<<18)		
-#define GAMMA2_ENBL		(0x1<<16)
-#define CSC_MODE_BT709		(0x1<<5)
-#define CSC_MODE_BT601		(0x0<<5)
-#define THREE_LINE_BUFFERS	(0x1<<0)
-#define TWO_LINE_BUFFERS	(0x0<<0)
-
-/* DCLRKM register */
-#define DEST_KEY_ENABLE		(0x1<<31)
-
-/* Polyphase filter coefficients */
-#define N_HORIZ_Y_TAPS		5
-#define N_VERT_Y_TAPS		3
-#define N_HORIZ_UV_TAPS		3
-#define N_VERT_UV_TAPS		3
-#define N_PHASES		17
-#define MAX_TAPS		5
-
-/* Filter cutoff frequency limits. */
-#define MIN_CUTOFF_FREQ		1.0
-#define MAX_CUTOFF_FREQ		3.0
-
-#define RGB16ToColorKey(c) \
-(((c & 0xF800) << 8) | ((c & 0x07E0) << 5) | ((c & 0x001F) << 3))
-
-#define RGB15ToColorKey(c) \
-(((c & 0x7c00) << 9) | ((c & 0x03E0) << 6) | ((c & 0x001F) << 3))
-
 /* client libraries expect an encoding */
 static XF86VideoEncodingRec DummyEncoding[1] = {
     {
@@ -274,64 +205,6 @@ static XF86ImageRec Images[NUM_IMAGES] = {
 #endif
 };
 
-typedef struct {
-    uint32_t OBUF_0Y;
-    uint32_t OBUF_1Y;
-    uint32_t OBUF_0U;
-    uint32_t OBUF_0V;
-    uint32_t OBUF_1U;
-    uint32_t OBUF_1V;
-    uint32_t OSTRIDE;
-    uint32_t YRGB_VPH;
-    uint32_t UV_VPH;
-    uint32_t HORZ_PH;
-    uint32_t INIT_PHS;
-    uint32_t DWINPOS;
-    uint32_t DWINSZ;
-    uint32_t SWIDTH;
-    uint32_t SWIDTHSW;
-    uint32_t SHEIGHT;
-    uint32_t YRGBSCALE;
-    uint32_t UVSCALE;
-    uint32_t OCLRC0;
-    uint32_t OCLRC1;
-    uint32_t DCLRKV;
-    uint32_t DCLRKM;
-    uint32_t SCLRKVH;
-    uint32_t SCLRKVL;
-    uint32_t SCLRKEN;
-    uint32_t OCONFIG;
-    uint32_t OCMD;
-    uint32_t RESERVED1;			/* 0x6C */
-    uint32_t OSTART_0Y; 		/* for i965 */
-    uint32_t OSTART_1Y;		/* for i965 */
-    uint32_t OSTART_0U;
-    uint32_t OSTART_0V;
-    uint32_t OSTART_1U;
-    uint32_t OSTART_1V;
-    uint32_t OTILEOFF_0Y;
-    uint32_t OTILEOFF_1Y;
-    uint32_t OTILEOFF_0U;
-    uint32_t OTILEOFF_0V;
-    uint32_t OTILEOFF_1U;
-    uint32_t OTILEOFF_1V;
-    uint32_t FASTHSCALE;			/* 0xA0 */
-    uint32_t UVSCALEV;			/* 0xA4 */
-
-    uint32_t RESERVEDC[(0x200 - 0xA8) / 4];		   /* 0xA8 - 0x1FC */
-    uint16_t Y_VCOEFS[N_VERT_Y_TAPS * N_PHASES];		   /* 0x200 */
-    uint16_t RESERVEDD[0x100 / 2 - N_VERT_Y_TAPS * N_PHASES];
-    uint16_t Y_HCOEFS[N_HORIZ_Y_TAPS * N_PHASES];		   /* 0x300 */
-    uint16_t RESERVEDE[0x200 / 2 - N_HORIZ_Y_TAPS * N_PHASES];
-    uint16_t UV_VCOEFS[N_VERT_UV_TAPS * N_PHASES];		   /* 0x500 */
-    uint16_t RESERVEDF[0x100 / 2 - N_VERT_UV_TAPS * N_PHASES];
-    uint16_t UV_HCOEFS[N_HORIZ_UV_TAPS * N_PHASES];	   /* 0x600 */
-    uint16_t RESERVEDG[0x100 / 2 - N_HORIZ_UV_TAPS * N_PHASES];
-} I830OverlayRegRec, *I830OverlayRegPtr;
-
-#define I830OVERLAYREG(pI830) ((I830OverlayRegPtr)\
-			       ((pI830)->FbBase + \
-				(pI830)->overlay_regs->offset))
 #if VIDEO_DEBUG
 static void
 CompareOverlay(I830Ptr pI830, uint32_t * overlay, int size)
@@ -353,9 +226,6 @@ CompareOverlay(I830Ptr pI830, uint32_t * overlay, int size)
 }
 #endif
 
-static void
-I830SetOneLineModeRatio(ScrnInfoPtr pScrn);
-
 /* kernel modesetting overlay functions */
 static Bool
 drmmode_has_overlay(ScrnInfoPtr pScrn)
@@ -500,188 +370,6 @@ drmmode_overlay_put_image(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
 #endif
 }
 
-static void
-i830_overlay_switch_to_crtc (ScrnInfoPtr pScrn, xf86CrtcPtr crtc)
-{
-    I830Ptr		pI830 = I830PTR(pScrn);
-    I830PortPrivPtr	pPriv = GET_PORT_PRIVATE(pScrn);
-    I830CrtcPrivatePtr  intel_crtc = crtc->driver_private;
-    int			pipeconf_reg = intel_crtc->pipe == 0 ? PIPEACONF : PIPEBCONF;
-
-    /* overlay can't be used on pipe with double wide, and pipe must be enabled. */
-    if ((!IS_I965G(pI830) && (INREG(pipeconf_reg) & PIPEACONF_DOUBLE_WIDE))
-	    || (intel_crtc->dpms_mode == DPMSModeOff))
-	pPriv->overlayOK = FALSE;
-    else
-	pPriv->overlayOK = TRUE;
-
-    if (!pPriv->overlayOK)
-	return;
-
-    /* Check we have an LFP connected */
-    if (i830PipeHasType(crtc, I830_OUTPUT_LVDS)) 
-    {
-
-	int	vtotal_reg = intel_crtc->pipe == 0 ? VTOTAL_A : VTOTAL_B;
-	uint32_t size = intel_crtc->pipe ? INREG(PIPEBSRC) : INREG(PIPEASRC);
-	uint32_t active;
-	uint32_t hsize, vsize;
-
-	hsize = (size >> 16) & 0x7FF;
-	vsize = size & 0x7FF;
-	active = INREG(vtotal_reg) & 0x7FF;
-
-	if (vsize < active && hsize > 1024)
-	    I830SetOneLineModeRatio(pScrn);
-
-	if (pPriv->scaleRatio & 0xFFFE0000) 
-	{
-	    /* Possible bogus ratio, using in-accurate fallback */
-	    xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
-		       "Bogus panel fit register, Xvideo positioning may not "
-		       "be accurate.\n");
-	    xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
-		       "Using fallback ratio - was 0x%x, now 0x%x\n",
-		       pPriv->scaleRatio,
-		       (int)(((float)active * 65536)/(float)vsize));
-
-	    pPriv->scaleRatio = (int)(((float)active * 65536) / (float)vsize);
-	}
-    }
-}
-
-/*
- * This is more or less the correct way to initalise, update, and shut down
- * the overlay.
- *
- * XXX Need to make sure that the overlay engine is cleanly shutdown in
- * all modes of server exit.
- */
-
-static void
-i830_overlay_on(ScrnInfoPtr pScrn)
-{
-    I830Ptr		pI830 = I830PTR(pScrn);
-    I830OverlayRegPtr	overlay = I830OVERLAYREG(pI830);
-    I830PortPrivPtr	pPriv = pI830->adaptor->pPortPrivates[0].ptr;
-    Bool		deactivate = FALSE;
-    
-    if (pI830->overlayOn)
-	return;
-
-    /*
-     * On I830, if pipe A is off when the overlayis enabled, it will fail to
-     * turn on and blank the entire screen or lock up the ring. Light up pipe
-     * A in this case to provide a clock for the overlay hardware
-     */
-    if (pPriv->current_crtc && i830_crtc_pipe (pPriv->current_crtc) != 0)
-	deactivate = i830_pipe_a_require_activate (pScrn);
-
-    overlay->OCMD &= ~OVERLAY_ENABLE;
-    BEGIN_BATCH(6);
-    OUT_BATCH(MI_FLUSH | MI_WRITE_DIRTY_STATE);
-    OUT_BATCH(MI_NOOP);
-    OUT_BATCH(MI_OVERLAY_FLIP | MI_OVERLAY_FLIP_ON);
-    if (OVERLAY_NOPHYSICAL(pI830))
-	OUT_BATCH(pI830->overlay_regs->offset | OFC_UPDATE);
-    else
-	OUT_BATCH(pI830->overlay_regs->bus_addr | OFC_UPDATE);
-    /* Wait for the overlay to light up before attempting to use it */
-    OUT_BATCH(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP);
-    OUT_BATCH(MI_NOOP);
-    ADVANCE_BATCH();
-    I830Sync(pScrn);
-    
-    /*
-     * If we turned pipe A on up above, turn it
-     * back off
-     */
-    if (deactivate)
-	i830_pipe_a_require_deactivate (pScrn);
-
-    OVERLAY_DEBUG("overlay_on\n");
-    pI830->overlayOn = TRUE;
-
-    overlay->OCMD |= OVERLAY_ENABLE;
-}
-
-static void
-i830_overlay_continue(ScrnInfoPtr pScrn, Bool update_filter)
-{
-    I830Ptr		pI830 = I830PTR(pScrn);
-    uint32_t		flip_addr;
-    I830OverlayRegPtr	overlay = I830OVERLAYREG(pI830);
-
-    if (!pI830->overlayOn)
-	return;
-
-    if (OVERLAY_NOPHYSICAL(pI830))
-	flip_addr = pI830->overlay_regs->offset;
-    else
-	flip_addr = pI830->overlay_regs->bus_addr;
-    if (update_filter)
-	flip_addr |= OFC_UPDATE;
-    OVERLAY_DEBUG ("overlay_continue cmd 0x%08x  -> 0x%08x sta 0x%08x\n",
-		   overlay->OCMD, INREG(OCMD_REGISTER), INREG(DOVSTA));
-    BEGIN_BATCH(4);
-    OUT_BATCH(MI_FLUSH | MI_WRITE_DIRTY_STATE);
-    OUT_BATCH(MI_NOOP);
-    OUT_BATCH(MI_OVERLAY_FLIP | MI_OVERLAY_FLIP_CONTINUE);
-    OUT_BATCH(flip_addr);
-    ADVANCE_BATCH();
-    OVERLAY_DEBUG("overlay_continue\n");
-
-    I830Sync(pScrn);
-}
-
-static void
-i830_overlay_off(ScrnInfoPtr pScrn)
-{
-    I830Ptr pI830 = I830PTR(pScrn);
-    I830OverlayRegPtr	overlay = I830OVERLAYREG(pI830);
-
-    if (!pI830->overlayOn)
-	return;
-
-    /*
-     * Wait for overlay to go idle. This has to be
-     * separated from the turning off state by a Sync
-     * to ensure the overlay will not read OCMD early and
-     * disable the overlay before the commands here are
-     * executed
-     */
-    {
-	BEGIN_BATCH(2);
-	OUT_BATCH(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP);
-	OUT_BATCH(MI_NOOP);
-	ADVANCE_BATCH();
-	I830Sync(pScrn);
-    }
-    
-    /*
-     * Turn overlay off
-     */
-    {
-	overlay->OCMD &= ~OVERLAY_ENABLE;
-	OVERLAY_DEBUG ("overlay_off cmd 0x%08x -> 0x%08x sta 0x%08x\n",
-		       overlay->OCMD, INREG(OCMD_REGISTER), INREG(DOVSTA));
-	BEGIN_BATCH(6);
-	OUT_BATCH(MI_FLUSH | MI_WRITE_DIRTY_STATE);
-	OUT_BATCH(MI_NOOP);
-	OUT_BATCH(MI_OVERLAY_FLIP | MI_OVERLAY_FLIP_CONTINUE);
-	if (OVERLAY_NOPHYSICAL(pI830))
-	    OUT_BATCH(pI830->overlay_regs->offset);
-	else
-	    OUT_BATCH(pI830->overlay_regs->bus_addr);
-	OUT_BATCH(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP);
-	OUT_BATCH(MI_NOOP);
-	ADVANCE_BATCH();
-	I830Sync(pScrn);
-    }
-    pI830->overlayOn = FALSE;
-    OVERLAY_DEBUG("overlay_off\n");
-}
-
 void
 I830InitVideo(ScreenPtr pScreen)
 {
@@ -694,20 +382,6 @@ I830InitVideo(ScreenPtr pScreen)
     Bool xvmc_status = FALSE;
 #endif
 
-#if 0
-    {
-	I830OverlayRegRec tmp;
-
-	ErrorF("sizeof I830OverlayRegRec is 0x%x\n", sizeof(I830OverlayRegRec));
-	ErrorF("Reserved C, D, E, F, G are %x, %x, %x, %x, %x\n",
-	       (unsigned long)&(tmp.RESERVEDC[0]) - (unsigned long)&tmp,
-	       (unsigned long)&(tmp.RESERVEDD[0]) - (unsigned long)&tmp,
-	       (unsigned long)&(tmp.RESERVEDE[0]) - (unsigned long)&tmp,
-	       (unsigned long)&(tmp.RESERVEDF[0]) - (unsigned long)&tmp,
-	       (unsigned long)&(tmp.RESERVEDG[0]) - (unsigned long)&tmp);
-    }
-#endif
-
     num_adaptors = xf86XVListGenericAdaptors(pScrn, &adaptors);
     /* Give our adaptor list enough space for the overlay and/or texture video
      * adaptors.
@@ -744,8 +418,7 @@ I830InitVideo(ScreenPtr pScreen)
     if (!OVERLAY_NOEXIST(pI830) && pScrn->bitsPerPixel != 8)
     {
 	pI830->use_drmmode_overlay = drmmode_has_overlay(pScrn);
-	if ((!pI830->use_drm_mode  && pI830->overlay_regs != NULL)
-		|| pI830->use_drmmode_overlay) {
+	if (pI830->use_drmmode_overlay) {
 	    overlayAdaptor = I830SetupImageVideoOverlay(pScreen);
 	    if (overlayAdaptor != NULL) {
 		xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Set up overlay video\n");
@@ -787,192 +460,12 @@ I830InitVideo(ScreenPtr pScreen)
     xfree(adaptors);
 }
 
-static void
-I830ResetVideo(ScrnInfoPtr pScrn)
-{
-    I830Ptr pI830 = I830PTR(pScrn);
-    I830PortPrivPtr pPriv = pI830->adaptor->pPortPrivates[0].ptr;
-    I830OverlayRegPtr	overlay = I830OVERLAYREG(pI830);
-
-    OVERLAY_DEBUG("I830ResetVideo: base: %p, offset: 0x%lx, obase: %p\n",
-		  pI830->FbBase, pI830->overlay_regs->offset, overlay);
-    /*
-     * Default to maximum image size in YV12
-     */
-
-    memset(overlay, 0, sizeof(*overlay));
-    overlay->YRGB_VPH = 0;
-    overlay->UV_VPH = 0;
-    overlay->HORZ_PH = 0;
-    overlay->INIT_PHS = 0;
-    overlay->DWINPOS = 0;
-    overlay->DWINSZ = 0;
-    overlay->SWIDTH = 0;
-    overlay->SWIDTHSW = 0;
-    overlay->SHEIGHT = 0;
-    overlay->OCLRC0 = (pPriv->contrast << 18) | (pPriv->brightness & 0xff);
-    overlay->OCLRC1 = pPriv->saturation;
-#if 0
-    overlay->AWINPOS = 0;
-    overlay->AWINSZ = 0;
-#endif
-    overlay->FASTHSCALE = 0;
-
-    /*
-     * Enable destination color keying
-     */
-    switch (pScrn->depth) {
-    case 8:
-	overlay->DCLRKV = 0;
-	overlay->DCLRKM = 0xffffff | DEST_KEY_ENABLE;
-	break;
-    case 15:
-	overlay->DCLRKV = RGB15ToColorKey(pPriv->colorKey);
-	overlay->DCLRKM = 0x070707 | DEST_KEY_ENABLE;
-	break;
-    case 16:
-	overlay->DCLRKV = RGB16ToColorKey(pPriv->colorKey);
-	overlay->DCLRKM = 0x070307 | DEST_KEY_ENABLE;
-	break;
-    default:
-	overlay->DCLRKV = pPriv->colorKey;
-	overlay->DCLRKM = DEST_KEY_ENABLE;
-	break;
-    }
-
-    overlay->SCLRKVH = 0;
-    overlay->SCLRKVL = 0;
-    overlay->SCLRKEN = 0;		/* source color key disable */
-    overlay->OCONFIG = CC_OUT_8BIT;
-    if (IS_I965GM(pI830))
-	overlay->OCONFIG |= CSC_MODE_BT709;
-
-    /*
-     * Select which pipe the overlay is enabled on.
-     */
-    overlay->OCONFIG &= ~OVERLAY_PIPE_MASK;
-    if (i830_crtc_pipe (pPriv->current_crtc) == 0)
-	overlay->OCONFIG |= OVERLAY_PIPE_A;
-    else 
-	overlay->OCONFIG |= OVERLAY_PIPE_B;
-
-#if 0
-    /* 
-     * XXX DUMP REGISTER CODE !!!
-     * This allows us to dump the complete i845 registers and compare
-     * with warm boot situations before we upload our first copy.
-     */
-    {
-	int i;
-	for (i = 0x30000; i < 0x31000; i += 4)
-	    ErrorF("0x%x 0x%" PRIx32 "\n", i, INREG(i));
-    }
-#endif
-}
-
 #define PFIT_CONTROLS 0x61230
 #define PFIT_AUTOVSCALE_MASK 0x200
 #define PFIT_ON_MASK 0x80000000
 #define PFIT_AUTOSCALE_RATIO 0x61238
 #define PFIT_PROGRAMMED_SCALE_RATIO 0x61234
 
-static void
-I830SetOneLineModeRatio(ScrnInfoPtr pScrn)
-{
-    I830Ptr pI830 = I830PTR(pScrn);
-    I830PortPrivPtr pPriv = pI830->adaptor->pPortPrivates[0].ptr;
-    uint32_t panelFitControl = INREG(PFIT_CONTROLS);
-    int vertScale;
-
-    pPriv->scaleRatio = 0x10000;
-
-    if (panelFitControl & PFIT_ON_MASK) {
-	if (panelFitControl & PFIT_AUTOVSCALE_MASK) {
-	    vertScale = INREG(PFIT_AUTOSCALE_RATIO) >> 16;
-	} else {
-	    vertScale = INREG(PFIT_PROGRAMMED_SCALE_RATIO) >> 16;
-	}
-
-	if (vertScale != 0)
-	    pPriv->scaleRatio = ((double) 0x10000 / (double)vertScale) * 0x10000;
-
-	pPriv->oneLineMode = TRUE;
-
-	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Enabling Xvideo one-line mode\n");
-    }
-
-    if (pPriv->scaleRatio == 0x10000)
-	pPriv->oneLineMode = FALSE;
-}
-
-static uint32_t I830BoundGammaElt (uint32_t elt, uint32_t eltPrev)
-{
-    elt &= 0xff;
-    eltPrev &= 0xff;
-    if (elt < eltPrev)
-	elt = eltPrev;
-    else if ((elt - eltPrev) > 0x7e)
-	elt = eltPrev + 0x7e;
-    return elt;
-}
-
-static uint32_t I830BoundGamma (uint32_t gamma, uint32_t gammaPrev)
-{
-    return (I830BoundGammaElt (gamma >> 16, gammaPrev >> 16) << 16 |
-	    I830BoundGammaElt (gamma >>  8, gammaPrev >>  8) <<  8 |
-	    I830BoundGammaElt (gamma      , gammaPrev      ));
-}
-
-static uint32_t I830Gamma5Errata(uint32_t gamma)
-{
-    int i;
-
-    for (i = 0; i < 3; i++) {
-	if ((gamma >> i*8 & 0xff) == 0x80) {
-	    /* According to Intel docs, overlay fails if GAMMA5 is 0x80.
-	     * In this case, change the value to 0x81 */
-	    gamma += 1 << i*8;
-	}
-    }
-
-    return gamma;
-}
-
-static void
-I830UpdateGamma(ScrnInfoPtr pScrn)
-{
-    I830Ptr pI830 = I830PTR(pScrn);
-    I830PortPrivPtr pPriv = pI830->adaptor->pPortPrivates[0].ptr;
-    uint32_t gamma0 = pPriv->gamma0;
-    uint32_t gamma1 = pPriv->gamma1;
-    uint32_t gamma2 = pPriv->gamma2;
-    uint32_t gamma3 = pPriv->gamma3;
-    uint32_t gamma4 = pPriv->gamma4;
-    uint32_t gamma5 = pPriv->gamma5;
-
-#if 0
-    ErrorF ("Original gamma: 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx\n",
-	    gamma0, gamma1, gamma2, gamma3, gamma4, gamma5);
-#endif
-    gamma1 = I830BoundGamma (gamma1, gamma0);
-    gamma2 = I830BoundGamma (gamma2, gamma1);
-    gamma3 = I830BoundGamma (gamma3, gamma2);
-    gamma4 = I830BoundGamma (gamma4, gamma3);
-    gamma5 = I830BoundGamma (gamma5, gamma4);
-    gamma5 = I830Gamma5Errata(gamma5);
-#if 0
-    ErrorF ("Bounded  gamma: 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx\n",
-	    gamma0, gamma1, gamma2, gamma3, gamma4, gamma5);
-#endif
-
-    OUTREG(OGAMC5, gamma5);
-    OUTREG(OGAMC4, gamma4);
-    OUTREG(OGAMC3, gamma3);
-    OUTREG(OGAMC2, gamma2);
-    OUTREG(OGAMC1, gamma1);
-    OUTREG(OGAMC0, gamma0);
-}
-
 static XF86VideoAdaptorPtr
 I830SetupImageVideoOverlay(ScreenPtr pScreen)
 {
@@ -1089,12 +582,7 @@ I830SetupImageVideoOverlay(ScreenPtr pScreen)
 	xvGamma5 = MAKE_ATOM("XV_GAMMA5");
     }
 
-    if (pI830->use_drmmode_overlay)
-	drmmode_overlay_update_attrs(pScrn);
-    else {
-	I830ResetVideo(pScrn);
-	I830UpdateGamma(pScrn);
-    }
+    drmmode_overlay_update_attrs(pScrn);
 
     return adapt;
 }
@@ -1193,16 +681,9 @@ i830_free_video_buffers(I830PortPrivPtr pPriv)
 }
 
 static void
-ums_overlay_off(ScrnInfoPtr pScrn)
-{
-    i830_overlay_off (pScrn);
-}
-
-static void
 I830StopVideo(ScrnInfoPtr pScrn, pointer data, Bool shutdown)
 {
     I830PortPrivPtr pPriv = (I830PortPrivPtr) data;
-    I830Ptr pI830 = I830PTR(pScrn);
 
     if (pPriv->textured)
 	return;
@@ -1212,12 +693,8 @@ I830StopVideo(ScrnInfoPtr pScrn, pointer data, Bool shutdown)
     REGION_EMPTY(pScrn->pScreen, &pPriv->clip);
 
     if (shutdown) {
-	if (pPriv->videoStatus & CLIENT_VIDEO_ON) {
-	    if (pI830->use_drmmode_overlay)
-		drmmode_overlay_off(pScrn);
-	    else
-		ums_overlay_off(pScrn);
-	}
+	if (pPriv->videoStatus & CLIENT_VIDEO_ON)
+	    drmmode_overlay_off(pScrn);
 
 	i830_free_video_buffers(pPriv);
 	pPriv->videoStatus = 0;
@@ -1256,35 +733,6 @@ I830SetPortAttributeTextured(ScrnInfoPtr pScrn,
     }
 }
 
-static void
-ums_overlay_update_attrs(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv)
-{
-    I830Ptr pI830 = I830PTR(pScrn);
-    I830OverlayRegPtr overlay;
-
-    overlay = I830OVERLAYREG(pI830);
-
-    overlay->OCLRC0 = (pPriv->contrast << 18) | (pPriv->brightness & 0xff);
-    overlay->OCLRC0 = (pPriv->contrast << 18) | (pPriv->brightness & 0xff);
-    overlay->OCLRC1 = pPriv->saturation;
-
-    switch (pScrn->depth) {
-    case 16:
-	overlay->DCLRKV = RGB16ToColorKey(pPriv->colorKey);
-	break;
-    case 15:
-	overlay->DCLRKV = RGB15ToColorKey(pPriv->colorKey);
-	break;
-    default:
-	overlay->DCLRKV = pPriv->colorKey;
-	break;
-    }
-
-    I830UpdateGamma(pScrn);
-
-    i830_overlay_continue(pScrn, FALSE);
-}
-
 static int
 I830SetPortAttributeOverlay(ScrnInfoPtr pScrn,
 		     Atom attribute, INT32 value, pointer data)
@@ -1345,10 +793,7 @@ I830SetPortAttributeOverlay(ScrnInfoPtr pScrn,
 	OVERLAY_DEBUG("GAMMA\n");
     }
 
-    if (pI830->use_drmmode_overlay)
-	drmmode_overlay_update_attrs(pScrn);
-    else
-	ums_overlay_update_attrs(pScrn, pPriv);
+    drmmode_overlay_update_attrs(pScrn);
 
     if (attribute == xvColorKey)
 	REGION_EMPTY(pScrn->pScreen, &pPriv->clip);
@@ -1638,130 +1083,6 @@ typedef struct {
     uint8_t exponent;
 } coeffRec, *coeffPtr;
 
-static Bool
-SetCoeffRegs(double *coeff, int mantSize, coeffPtr pCoeff, int pos)
-{
-    int maxVal, icoeff, res;
-    int sign;
-    double c;
-
-    sign = 0;
-    maxVal = 1 << mantSize;
-    c = *coeff;
-    if (c < 0.0) {
-	sign = 1;
-	c = -c;
-    }
-
-    res = 12 - mantSize;
-    if ((icoeff = (int)(c * 4 * maxVal + 0.5)) < maxVal) {
-	pCoeff[pos].exponent = 3;
-	pCoeff[pos].mantissa = icoeff << res;
-	*coeff = (double)icoeff / (double)(4 * maxVal);
-    } else if ((icoeff = (int)(c * 2 * maxVal + 0.5)) < maxVal) {
-	pCoeff[pos].exponent = 2;
-	pCoeff[pos].mantissa = icoeff << res;
-	*coeff = (double)icoeff / (double)(2 * maxVal);
-    } else if ((icoeff = (int)(c * maxVal + 0.5)) < maxVal) {
-	pCoeff[pos].exponent = 1;
-	pCoeff[pos].mantissa = icoeff << res;
-	*coeff = (double)icoeff / (double)(maxVal);
-    } else if ((icoeff = (int)(c * maxVal * 0.5 + 0.5)) < maxVal) {
-	pCoeff[pos].exponent = 0;
-	pCoeff[pos].mantissa = icoeff << res;
-	*coeff = (double)icoeff / (double)(maxVal / 2);
-    } else {
-	/* Coeff out of range */
-	return FALSE;
-    }
-
-    pCoeff[pos].sign = sign;
-    if (sign)
-	*coeff = -(*coeff);
-    return TRUE;
-}
-
-static void
-UpdateCoeff(int taps, double fCutoff, Bool isHoriz, Bool isY, coeffPtr pCoeff)
-{
-    int i, j, j1, num, pos, mantSize;
-    double pi = 3.1415926535, val, sinc, window, sum;
-    double rawCoeff[MAX_TAPS * 32], coeffs[N_PHASES][MAX_TAPS];
-    double diff;
-    int tapAdjust[MAX_TAPS], tap2Fix;
-    Bool isVertAndUV;
-
-    if (isHoriz)
-	mantSize = 7;
-    else
-	mantSize = 6;
-
-    isVertAndUV = !isHoriz && !isY;
-    num = taps * 16;
-    for (i = 0; i < num  * 2; i++) {
-	val = (1.0 / fCutoff) * taps * pi * (i - num) / (2 * num);
-	if (val == 0.0)
-	    sinc = 1.0;
-	else
-	    sinc = sin(val) / val;
-
-	/* Hamming window */
-	window = (0.5 - 0.5 * cos(i * pi / num));
-	rawCoeff[i] = sinc * window;
-    }
-
-    for (i = 0; i < N_PHASES; i++) {
-	/* Normalise the coefficients. */
-	sum = 0.0;
-	for (j = 0; j < taps; j++) {
-	    pos = i + j * 32;
-	    sum += rawCoeff[pos];
-	}
-	for (j = 0; j < taps; j++) {
-	    pos = i + j * 32;
-	    coeffs[i][j] = rawCoeff[pos] / sum;
-	}
-
-	/* Set the register values. */
-	for (j = 0; j < taps; j++) {
-	    pos = j + i * taps;
-	    if ((j == (taps - 1) / 2) && !isVertAndUV)
-		SetCoeffRegs(&coeffs[i][j], mantSize + 2, pCoeff, pos);
-	    else
-		SetCoeffRegs(&coeffs[i][j], mantSize, pCoeff, pos);
-	}
-
-	tapAdjust[0] = (taps - 1) / 2;
-	for (j = 1, j1 = 1; j <= tapAdjust[0]; j++, j1++) {
-	    tapAdjust[j1] = tapAdjust[0] - j;
-	    tapAdjust[++j1] = tapAdjust[0] + j;
-	}
-
-	/* Adjust the coefficients. */
-	sum = 0.0;
-	for (j = 0; j < taps; j++)
-	    sum += coeffs[i][j];
-	if (sum != 1.0) {
-	    for (j1 = 0; j1 < taps; j1++) {
-		tap2Fix = tapAdjust[j1];
-		diff = 1.0 - sum;
-		coeffs[i][tap2Fix] += diff;
-		pos = tap2Fix + i * taps;
-		if ((tap2Fix == (taps - 1) / 2) && !isVertAndUV)
-		    SetCoeffRegs(&coeffs[i][tap2Fix], mantSize + 2, pCoeff, pos);
-		else
-		    SetCoeffRegs(&coeffs[i][tap2Fix], mantSize, pCoeff, pos);
-
-		sum = 0.0;
-		for (j = 0; j < taps; j++)
-		    sum += coeffs[i][j];
-		if (sum == 1.0)
-		    break;
-	    }
-	}
-    }
-}
-
 static void
 i830_box_intersect (BoxPtr dest, BoxPtr a, BoxPtr b)
 {
@@ -1843,52 +1164,6 @@ i830_covering_crtc (ScrnInfoPtr pScrn,
     return best_crtc;
 }
 
-static int
-i830_swidth (I830Ptr pI830, unsigned int offset,
-	     unsigned int width, unsigned int mask, int shift)
-{
-    int	swidth = ((offset + width + mask) >> shift) - (offset >> shift);
-    if (IS_I9XX(pI830))
-	swidth <<= 1;
-    swidth -= 1;
-    return swidth << 2;
-}
-
-static void
-i830_calc_src_regs(I830Ptr pI830, int planar, short width, short height,
-	uint32_t *swidth_out, uint32_t *swidthsw_out, uint32_t *sheigth_out)
-{
-    unsigned int	mask, shift, offsety, offsetu;
-    unsigned int	swidth, swidthy, swidthuv;
-    I830PortPrivPtr	pPriv = pI830->adaptor->pPortPrivates[0].ptr;
-
-    if (IS_I9XX(pI830)) {
-	shift = 6;
-	mask = 0x3f;
-    } else {
-	shift = 5;
-	mask = 0x1f;
-    }
-
-    offsety = pPriv->YBufOffset;
-    offsetu = pPriv->UBufOffset;
-
-    if (planar) {
-	*swidth_out = width | ((width/2 & 0x7ff) << 16);
-	swidthy  = i830_swidth (pI830, offsety, width, mask, shift);
-	swidthuv = i830_swidth (pI830, offsetu, width/2, mask, shift);
-	*swidthsw_out = (swidthy) | (swidthuv << 16);
-	*sheigth_out = height | ((height / 2) << 16);
-    } else {
-	*swidth_out = width;
-	swidth = i830_swidth (pI830, offsety, width << 1, mask, shift);
-	*swidthsw_out = swidth;
-	*sheigth_out = height;
-    }
-
-    return;
-}
-
 static void
 i830_update_dst_box_to_crtc_coords(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
 		BoxPtr dstBox)
@@ -1941,172 +1216,6 @@ i830_update_dst_box_to_crtc_coords(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
     return;
 }
 
-static void
-i830_store_coeffs_in_overlay_regs(uint16_t *reg_coeffs, coeffPtr new_coeffs,
-	int max_taps)
-{
-    int i, j, pos;
-
-    for (i = 0; i < N_PHASES; i++) {
-	for (j = 0; j < max_taps; j++) {
-	    pos = i * max_taps + j;
-	    reg_coeffs[pos] = (new_coeffs[pos].sign << 15 |
-				      new_coeffs[pos].exponent << 12 |
-				      new_coeffs[pos].mantissa);
-	}
-    }
-}
-
-static uint32_t
-i830_overlay_cmd(int id, int planar)
-{
-    uint32_t OCMD = OVERLAY_ENABLE;
-
-    if (planar) {
-	OVERLAY_DEBUG("YUV420\n");
-	OCMD &= ~SOURCE_FORMAT;
-	OCMD &= ~OV_BYTE_ORDER;
-	OCMD |= YUV_420;
-    } else {
-	OVERLAY_DEBUG("YUV422\n");
-	OCMD &= ~SOURCE_FORMAT;
-	OCMD |= YUV_422;
-	OCMD &= ~OV_BYTE_ORDER;
-	if (id == FOURCC_UYVY)
-	    OCMD |= Y_SWAP;
-    }
-
-    OCMD &= ~(BUFFER_SELECT | FIELD_SELECT);
-    OCMD |= BUFFER0;
-
-    OVERLAY_DEBUG("OCMD is 0x%x\n", OCMD);
-
-    return OCMD;
-}
-
-static double
-i830_limit_coeff(double coeff)
-{
-    /* Limit to between 1.0 and 3.0. */
-    if (coeff < MIN_CUTOFF_FREQ)
-	coeff = MIN_CUTOFF_FREQ;
-    if (coeff > MAX_CUTOFF_FREQ)
-	coeff = MAX_CUTOFF_FREQ;
-
-    return coeff;
-}
-
-static void
-i830_update_polyphase_coeffs(I830OverlayRegPtr	overlay,
-	int xscaleFract, int xscaleFractUV)
-{
-    /*
-     * Only Horizontal coefficients so far.
-     */
-    double fCutoffY;
-    double fCutoffUV;
-    coeffRec xcoeffY[N_HORIZ_Y_TAPS * N_PHASES];
-    coeffRec xcoeffUV[N_HORIZ_UV_TAPS * N_PHASES];
-
-    fCutoffY = xscaleFract / 4096.0;
-    fCutoffUV = xscaleFractUV / 4096.0;
-
-    fCutoffUV = i830_limit_coeff(fCutoffUV);
-    fCutoffY = i830_limit_coeff(fCutoffY);
-
-    UpdateCoeff(N_HORIZ_Y_TAPS, fCutoffY, TRUE, TRUE, xcoeffY);
-    UpdateCoeff(N_HORIZ_UV_TAPS, fCutoffUV, TRUE, FALSE, xcoeffUV);
-
-    i830_store_coeffs_in_overlay_regs(overlay->Y_HCOEFS, xcoeffY,
-		    N_HORIZ_Y_TAPS);
-    i830_store_coeffs_in_overlay_regs(overlay->UV_HCOEFS, xcoeffUV,
-		    N_HORIZ_UV_TAPS);
-}
-
-/*
- * Calculate horizontal and vertical scaling factors and polyphase
- * coefficients.
- */
-
-static Bool
-i830_update_scaling_factors(I830OverlayRegPtr overlay,
-	short src_w, short src_h, short drw_w, short drw_h)
-{
-    int xscaleInt, xscaleFract, yscaleInt, yscaleFract;
-    int xscaleIntUV, xscaleFractUV;
-    int yscaleIntUV, yscaleFractUV;
-    uint32_t newval;
-    Bool scaleChanged = FALSE;
-
-    /*
-     * Y down-scale factor as a multiple of 4096.
-     */
-    xscaleFract = ((src_w - 1) << 12) / drw_w;
-    yscaleFract = ((src_h - 1) << 12) / drw_h;
-
-    /* Calculate the UV scaling factor.
-     * UV is half the size of Y -- YUV420 */
-    xscaleFractUV = xscaleFract / 2;
-    yscaleFractUV = yscaleFract / 2;
-
-    /*
-     * To keep the relative Y and UV ratios exact, round the Y scales
-     * to a multiple of the Y/UV ratio.
-     */
-    xscaleFract = xscaleFractUV * 2;
-    yscaleFract = yscaleFractUV * 2;
-
-    /* Integer (un-multiplied) values. */
-    xscaleInt = xscaleFract >> 12;
-    yscaleInt = yscaleFract >> 12;
-
-    xscaleIntUV = xscaleFractUV >> 12;
-    yscaleIntUV = yscaleFractUV >> 12;
-
-    OVERLAY_DEBUG("xscale: %x.%03x, yscale: %x.%03x\n", xscaleInt,
-		  xscaleFract & 0xFFF, yscaleInt, yscaleFract & 0xFFF);
-    OVERLAY_DEBUG("UV xscale: %x.%03x, UV yscale: %x.%03x\n", xscaleIntUV,
-		  xscaleFractUV & 0xFFF, yscaleIntUV, yscaleFractUV & 0xFFF);
-
-    /* shouldn't get here */
-    if (xscaleInt > 7) {
-	OVERLAY_DEBUG("xscale: bad scale\n");
-	return FALSE;
-    }
-
-    /* shouldn't get here */
-    if (xscaleIntUV > 7) {
-	OVERLAY_DEBUG("xscaleUV: bad scale\n");
-	return FALSE;
-    }
-
-    newval = (xscaleInt << 16) |
-    ((xscaleFract & 0xFFF) << 3) | ((yscaleFract & 0xFFF) << 20);
-    if (newval != overlay->YRGBSCALE) {
-	scaleChanged = TRUE;
-	overlay->YRGBSCALE = newval;
-    }
-
-    newval = (xscaleIntUV << 16) | ((xscaleFractUV & 0xFFF) << 3) |
-    ((yscaleFractUV & 0xFFF) << 20);
-    if (newval != overlay->UVSCALE) {
-	scaleChanged = TRUE;
-	overlay->UVSCALE = newval;
-    }
-
-    newval = yscaleInt << 16 | yscaleIntUV;
-    if (newval != overlay->UVSCALEV) {
-	scaleChanged = TRUE;
-	overlay->UVSCALEV = newval;
-    }
-
-    if (scaleChanged) {
-	i830_update_polyphase_coeffs(overlay, xscaleFract, xscaleFractUV);
-    }
-
-    return scaleChanged;
-}
-
 int
 is_planar_fourcc(int id)
 {
@@ -2137,112 +1246,6 @@ xvmc_passthrough(int id, Rotation rotation)
 }
 
 static Bool
-ums_overlay_put_image(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
-		   int id, short width, short height,
-		   int dstPitch, int x1, int y1, int x2, int y2, BoxPtr dstBox,
-		   short src_w, short src_h, short drw_w, short drw_h)
-{
-    I830Ptr		pI830 = I830PTR(pScrn);
-    I830PortPrivPtr	pPriv = pI830->adaptor->pPortPrivates[0].ptr;
-    I830OverlayRegPtr	overlay = I830OVERLAYREG(pI830);
-    int			planar;
-    uint32_t		swidth, swidthsw, sheigth;
-    Bool		scaleChanged;
-    drm_intel_bo	*tmp_buf;
-
-    if (crtc != pPriv->current_crtc)
-    {
-	/* this may adjust pPriv->oneLineMode */
-	i830_overlay_switch_to_crtc (pScrn, crtc);
-	if (pPriv->overlayOK) {
-	    pPriv->current_crtc = crtc;
-	    I830ResetVideo (pScrn);
-	}
-    }
-
-    if (!pPriv->overlayOK)
-	return TRUE;
-
-    if (pPriv->oneLineMode) {
-	/* change the coordinates with panel fitting active */
-	dstBox->y1 = (((dstBox->y1 - 1) * pPriv->scaleRatio) >> 16) + 1;
-	dstBox->y2 = ((dstBox->y2 * pPriv->scaleRatio) >> 16) + 1;
-
-	/* Now, alter the height, so we scale to the correct size */
-	drw_h = ((drw_h * pPriv->scaleRatio) >> 16) + 1;
-    }
-
-    planar = is_planar_fourcc(id);
-
-    i830_calc_src_regs(pI830, planar, width, height,
-	    &swidth, &swidthsw, &sheigth);
-
-    overlay->SWIDTH = swidth;
-    overlay->SWIDTHSW = swidthsw;
-    overlay->SHEIGHT = sheigth;
-
-    overlay->DWINPOS = (dstBox->y1 << 16) | dstBox->x1;
-
-    overlay->DWINSZ = (((dstBox->y2 - dstBox->y1) << 16) |
-		       (dstBox->x2 - dstBox->x1));
-
-    OVERLAY_DEBUG("dstBox: x1: %d, y1: %d, x2: %d, y2: %d\n",
-		  dstBox->x1, dstBox->y1, dstBox->x2, dstBox->y2);
-
-    /* buffer locations */
-    if (xvmc_passthrough(id, pPriv->rotation)) {
-	overlay->OBUF_0Y = pPriv->YBufOffset;
-	overlay->OBUF_0U = pPriv->UBufOffset;
-	overlay->OBUF_0V = pPriv->VBufOffset;
-    } else {
-	if (drm_intel_bo_pin(pPriv->buf, GTT_PAGE_SIZE) != 0)
-	    return FALSE;
-	overlay->OBUF_0Y = pPriv->YBufOffset + pPriv->buf->offset;
-	overlay->OBUF_0U = pPriv->UBufOffset + pPriv->buf->offset;
-	overlay->OBUF_0V = pPriv->VBufOffset + pPriv->buf->offset;
-    }
-
-    OVERLAY_DEBUG("pos: 0x%x, size: 0x%x\n",
-		  overlay->DWINPOS, overlay->DWINSZ);
-    OVERLAY_DEBUG("dst: %d x %d, src: %d x %d\n", drw_w, drw_h, src_w, src_h);
-
-    scaleChanged = i830_update_scaling_factors(overlay,
-	    src_w, src_h, drw_w, drw_h);
-
-    if (planar) {
-#if 0
-	/* set UV vertical phase to -0.25 */
-	overlay->UV_VPH = 0x30003000;
-#endif
-	overlay->OSTRIDE = (dstPitch * 2) | (dstPitch << 16);
-	OVERLAY_DEBUG("UV stride is %d, Y stride is %d\n",
-		      dstPitch, dstPitch * 2);
-    } else
-	overlay->OSTRIDE = dstPitch;
-
-    overlay->OCMD = i830_overlay_cmd(id, planar);
-
-    /* make sure the overlay is on */
-    i830_overlay_on (pScrn);
-    /* and show this frame */
-    i830_overlay_continue (pScrn, scaleChanged);
-
-    if (xvmc_passthrough(id, pPriv->rotation))
-	return TRUE;
-
-    /* unpin the old buffer and exchange buffers */
-    if (pPriv->oldBuf_pinned) {
-	drm_intel_bo_unpin(pPriv->oldBuf);
-    }
-    tmp_buf = pPriv->buf;
-    pPriv->buf = pPriv->oldBuf;
-    pPriv->oldBuf = tmp_buf;
-    pPriv->oldBuf_pinned = TRUE;
-
-    return TRUE;
-}
-
-static Bool
 i830_display_overlay(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
 		   int id, short width, short height,
 		   int dstPitch, int x1, int y1, int x2, int y2, BoxPtr dstBox,
@@ -2265,10 +1268,7 @@ i830_display_overlay(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
     if (!crtc)
     {
 	pPriv->current_crtc = NULL;
-	if (pI830->use_drmmode_overlay)
-	    drmmode_overlay_off(pScrn);
-	else
-	    ums_overlay_off(pScrn);
+	drmmode_overlay_off(pScrn);
 
 	return TRUE;
     }
@@ -2287,12 +1287,9 @@ i830_display_overlay(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
 	src_h = tmp;
     }
 
-    if (pI830->use_drmmode_overlay)
-	return drmmode_overlay_put_image(pScrn, crtc, id, width, height, dstPitch,
-		x1, y1, x2, y2, dstBox, src_w, src_h, drw_w, drw_h);
-    else
-	return ums_overlay_put_image(pScrn, crtc, id, width, height, dstPitch,
-		x1, y1, x2, y2, dstBox, src_w, src_h, drw_w, drw_h);
+    return drmmode_overlay_put_image(pScrn, crtc, id, width, height, dstPitch,
+				     x1, y1, x2, y2, dstBox,
+				     src_w, src_h, drw_w, drw_h);
 }
 
 static Bool
@@ -2801,10 +1798,7 @@ I830VideoBlockHandler(int i, pointer blockData, pointer pTimeout,
 		/* Turn off the overlay */
 		OVERLAY_DEBUG("BLOCKHANDLER\n");
 
-		if (pI830->use_drmmode_overlay)
-		    drmmode_overlay_off(pScrn);
-		else
-		    ums_overlay_off (pScrn);
+		drmmode_overlay_off(pScrn);
 
 		pPriv->videoStatus = FREE_TIMER;
 		pPriv->freeTime = now + FREE_DELAY;
commit 33c488e83676d26e69145ea615f75ca52768f400
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Oct 5 10:38:05 2009 -0700

    Remove error state dumping code.
    
    This is replaced by intel_gpu_dump, and would no longer be used once UMS is
    gone.

diff --git a/src/i830_accel.c b/src/i830_accel.c
index abefa55..08e84f7 100644
--- a/src/i830_accel.c
+++ b/src/i830_accel.c
@@ -105,10 +105,6 @@ I830WaitLpRing(ScrnInfoPtr pScrn, int n, int timeout_millis)
       } else if (now - start > timeout_millis) {
 	 ErrorF("Error in I830WaitLpRing(), timeout for %d seconds\n",
 		timeout_millis/1000);
-	 if (IS_I965G(pI830))
-	     i965_dump_error_state(pScrn);
-	 else
-	     i830_dump_error_state(pScrn);
 	 ErrorF("space: %d wanted %d\n", ring->space, n);
 	 pI830->uxa_driver = NULL;
 	 FatalError("lockup\n");
diff --git a/src/i830_debug.c b/src/i830_debug.c
index eae141b..68ff860 100644
--- a/src/i830_debug.c
+++ b/src/i830_debug.c
@@ -1754,787 +1754,3 @@ void i830DumpRegs (ScrnInfoPtr pScrn)
     }
     xf86DrvMsg (pScrn->scrnIndex, X_INFO, "DumpRegsEnd\n");
 }
-
-#ifndef REG_DUMPER
-
-static char *mi_cmds[0x40] = {
-    "MI_NOOP",		    /* 00 */
-    "Reserved 01",
-    "MI_USER_INTERRUPT",
-    "MI_WAIT_FOR_EVENT",
-    
-    "MI_FLUSH",		    /* 04 */
-    "MI_ARB_CHECK",
-    NULL,
-    "MI_REPORT_HEAD",
-
-    NULL,		    /* 08 */
-    NULL,
-    "MI_BATCH_BUFFER_END",
-    NULL,
-
-    NULL,		    /* 0c */
-    NULL,
-    NULL,
-    NULL,
-
-    NULL,		    /* 10 */
-    "MI_OVERLAY_FLIP",
-    "MI_LOAD_SCAN_LINES_INCL",
-    "MI_LOAD_SCAN_LINES_EXCL",
-
-    "MI_DISPLAY_BUFFER_INFO",	/* 14 */
-    NULL,
-    NULL,
-    NULL,
-
-    "MI_SET_CONTEXT",		/* 18 */
-    NULL,
-    NULL,
-    NULL,
-
-    NULL,			/* 1c */
-    NULL,
-    NULL,
-    NULL,
-    
-    "MI_STORE_DATA_IMM",	/* 20 */
-    "MI_STORE_DATA_INDEX",
-    "MI_LOAD_REGISTER_IMM",
-    NULL,
-
-    "MI_STORE_REGISTER_MEM",	/* 24 */
-    NULL,
-    NULL,
-    NULL,
-
-    NULL,			/* 28 */
-    NULL,
-    NULL,
-    NULL,
-
-    NULL,			/* 2c */
-    NULL,
-    NULL,
-    NULL,
-    
-    NULL,			/* 30 */
-    "MI_BATCH_BUFFER_START",
-    NULL,
-    NULL,
-
-    NULL,			/* 34 */
-    NULL,
-    NULL,
-    NULL,
-
-    NULL,			/* 38 */
-    NULL,
-    NULL,
-    NULL,
-
-    NULL,			/* 3c */
-    NULL,
-    NULL,
-    NULL,
-};
-
-static char *_2d_cmds[0x80] = {
-    NULL,			/* 00 */
-    "XY_SETUP_BLT",
-    NULL,
-    "XY_SETUP_CLIP_BLT",
-
-    NULL,			/* 04 */
-    NULL,
-    NULL,
-    NULL,
-
-    NULL,			/* 08 */
-    NULL,
-    NULL,
-    NULL,
-
-    NULL,			/* 0c */
-    NULL,
-    NULL,
-    NULL,
-    
-    NULL,			/* 10 */
-    "XY_SETUP_MONO_PATTERN_SL_BLT",
-    NULL,
-    NULL,
-
-    NULL,			/* 14 */
-    NULL,
-    NULL,
-    NULL,
-
-    NULL,			/* 18 */
-    NULL,
-    NULL,
-    NULL,
-
-    NULL,			/* 1c */
-    NULL,
-    NULL,
-    NULL,
-    
-    NULL,			/* 20 */
-    NULL,
-    NULL,
-    NULL,
-
-    "XY_PIXEL_BLT",    		/* 24 */
-    "XY_SCANLINE_BLT",
-    "XY_TEXT_BLT",
-    NULL,
-
-    NULL,			/* 28 */
-    NULL,
-    NULL,
-    NULL,
-
-    NULL,			/* 2c */
-    NULL,
-    NULL,
-    NULL,
-    
-    NULL,			/* 30 */
-    "XY_TEXT_IMMEDIATE_BLT",
-    NULL,
-    NULL,
-
-    NULL,			/* 34 */
-    NULL,
-    NULL,
-    NULL,
-
-    NULL,			/* 38 */
-    NULL,
-    NULL,
-    NULL,
-
-    NULL,			/* 3c */
-    NULL,
-    NULL,
-    NULL,
-    
-    "COLOR_BLT",    		/* 40 */
-    NULL,
-    NULL,
-    "SRC_COPY_BLT",
-
-    NULL,			/* 44 */
-    NULL,
-    NULL,
-    NULL,
-
-    NULL,			/* 48 */
-    NULL,
-    NULL,
-    NULL,
-
-    NULL,			/* 4c */
-    NULL,
-    NULL,
-    NULL,
-    
-    "XY_COLOR_BLT",    		/* 50 */
-    "XY_PAT_BLT",
-    "XY_MONO_PAT_BLT",
-    "XY_SRC_COPY_BLT",
-
-    "XY_MONO_SRC_COPY_BLT",    	/* 54 */
-    "XY_FULL_BLT",
-    "XY_FULL_MONO_SRC_BLT",
-    "XY_FULL_MONO_PATTERN_BLT",
-
-    "XY_FULL_MONO_PATTERN_MONO_SRC_BLT", /* 58 */
-    "XY_MONO_PAT_FIXED_BLT",
-    NULL,
-    NULL,
-
-    NULL,			/* 5c */
-    NULL,
-    NULL,
-    NULL,
-    
-    NULL,			/* 60 */
-    NULL,
-    NULL,
-    NULL,
-
-    NULL,			/* 64 */
-    NULL,
-    NULL,
-    NULL,
-
-    NULL,			/* 68 */
-    NULL,
-    NULL,
-    NULL,
-
-    NULL,			/* 6c */
-    NULL,
-    NULL,
-    NULL,
-    
-    NULL,			/* 70 */
-    "XY_MONO_SRC_COPY_IMMEDIATE_BLT",
-    "XY_PAT_BLT_IMMEDIATE",
-    "XY_SRC_COPY_CHROMA_BLT",
-
-    "XY_FULL_IMMEDIATE_PATTERN_BLT", /* 74 */
-    "XY_FULL_MONO_SRC_IMMEDIATE_PATTERN_BLT",
-    "XY_PAT_CHROMA_BLT",
-    "XY_PAT_CHROMA_BLT_IMMEDIATE",
-
-    NULL,			/* 78 */
-    NULL,
-    NULL,
-    NULL,
-
-    NULL,			/* 7c */
-    NULL,
-    NULL,
-    NULL,
-    
-};
-
-#define _3D_ONE_WORD	1
-
-static struct {
-    char    *name;
-    int	    flags;
-} _3d_cmds[0x4][0x8][0x100] = {
-    {		/* Pipeline Type 00 (Common) */
-	{	    /* Opcode 0 */
-	    { "URB_FENCE", 0 },			/* 00 */
-	    { "CS_URB_STATE", 0 },
-	    { "CONSTANT_BUFFER", 0 },
-	    { "STATE_PREFETCH", 0 },
-	},
-	{	    /* Opcode 1 */
-	    { NULL, 0 },				/* 00 */
-	    { "STATE_BASE_ADDRESS", 0 },
-	    { "STATE_SIP", 0 },
-	    { NULL, 0 },
-
-	    { "PIPELINE_SELECT", _3D_ONE_WORD },	/* 04 */
-	},
-    },
-    {		/* Pipeline Type 01 (Single DW) */
-	{	    /* Opcode 0 */
-	},
-	{	    /* Opcode 1 */
-	    { NULL, 0 },				/* 00 */
-	    { NULL, 0 },
-	    { NULL, 0 },
-	    { NULL, 0 },
-
-	    { "PIPELINE_SELECT", 0 },			/* 04 */
-	    { NULL, 0 },
-	    { NULL, 0 },
-	    { NULL, 0 },
-	},
-    },
-    {		/* Pipeline Type 02 (Media) */
-	{	    /* Opcode 0 */
-	    { "MEDIA_STATE_POINTERS", 0 },		/* 00 */
-	},
-	{	    /* Opcode 1 */
-	    { "MEDIA_OBJECT", 0 },			/* 00 */
-	    { "MEDIA_OBJECT_EX", 0 },
-	    { "MEDIA_OBJECT_PTR", 0 },
-	},
-    },
-    {		/* Pipeline Type 03 (3D) */
-	{	    /* Opcode 0 */
-	    { "3DSTATE_PIPELINED_POINTERS", 0 },	/* 00 */
-	    { "3DSTATE_BINDING_TABLE_POINTERS", 0 },
-	    { NULL, 0 },
-	    { NULL, 0 },
-
-	    { NULL, 0 },				/* 04 */
-	    { "3DSTATE_URB", 0 },
-	    { NULL, 0 },
-	    { NULL, 0 },
-
-	    { "3DSTATE_VERTEX_BUFFERS", 0 },		/* 08 */
-	    { "3DSTATE_VERTEX_ELEMENTS", 0 },
-	    { "3DSTATE_INDEX_BUFFER", 0 },
-	    { "3DSTATE_VF_STATISTICS", _3D_ONE_WORD },
-
-	    { NULL, 0 },				/* 0c */
-	    { "3DSTATE_VIEWPORT_STATE_POINTERS", 0 },
-	},
-	{	    /* Opcode 1 */
-	    { "3DSTATE_DRAWING_RECTANGLE", 0 },	/* 00 */
-	    { "3DSTATE_CONSTANT_COLOR", 0 },
-	    { "3DSTATE_SAMPLER_PALETTE_LOAD0", 0 },
-	    { NULL, 0 },
-
-	    { "3DSTATE_CHROMA_KEY", 0 },		/* 04 */
-	    { "3DSTATE_DEPTH_BUFFER", 0 },
-	    { "3DSTATE_POLY_STIPPLE_OFFSET", 0 },
-	    { "3DSTATE_POLY_STIPPLE_PATTERN", 0 },
-	    
-	    { "3DSTATE_LINE_STIPPLE", 0 },		/* 08 */
-	    { "3DSTATE_GLOBAL_DEPTH_OFFSET_CLAMP", 0 },
-	},
-	{	    /* Opcode 2 */
-	    { "PIPE_CONTROL", 0 },			/* 00 */
-	},
-	{	    /* Opcode 3 */
-	    { "3DPRIMITIVE", 0 },			/* 00 */
-	},
-    },
-};
-
-static int
-i830_valid_command (uint32_t cmd)
-{
-    uint32_t	type = (cmd >> 29) & 0x7;
-    uint32_t	pipeline_type;
-    uint32_t	opcode;
-    uint32_t	subopcode;
-    uint32_t	count;
-    
-    switch (type) {
-    case 0:			    /* Memory Interface */
-	opcode = (cmd >> 23) & 0x3f;
-	if (opcode < 0x10)
-	    count = 1;
-	else
-	    count = (cmd & 0x3f) + 2;
-	if (opcode == 0x00 && cmd != 0x00000000)
-	    return -1;
-	if (!mi_cmds[opcode])
-	    return -1;
-	break;
-    case 1:
-	return -1;
-    case 2:			    /* 2D */
-	count = (cmd & 0x1f) + 2;
-	opcode = (cmd >> 22) & 0x7f;
-	if (!_2d_cmds[opcode])
-	    return -1;
-	break;
-    case 3:			    /* 3D */
-	pipeline_type = (cmd >> 27) & 0x3;
-	opcode = (cmd >> 24) & 0x7;
-	subopcode = (cmd >> 16) & 0xff;
-	if (_3d_cmds[pipeline_type][opcode][subopcode].flags & _3D_ONE_WORD)
-	    count = 1;
-	else
-	    count = (cmd & 0xff) + 2;
-	if (!_3d_cmds[pipeline_type][opcode][subopcode].name)
-	    return -1;
-	break;
-    default:
-	return -1;
-    }
-    return count;
-}
-
-static int
-i830_dump_cmd (uint32_t cmd, int count)
-{
-    uint32_t	type = (cmd >> 29) & 0x7;
-    uint32_t	pipeline_type;
-    uint32_t	opcode;
-    uint32_t	subopcode;
-    int		ret = 1;
-    
-    ErrorF ("\t");
-    switch (type) {
-    case 0:			    /* Memory Interface */
-	opcode = (cmd >> 23) & 0x3f;
-	if (mi_cmds[opcode])
-	    ErrorF ("%-40.40s %d\n", mi_cmds[opcode], count);
-	else
-	    ErrorF ("Memory Interface Reserved\n");
-	break;
-    case 1:
-	break;
-    case 2:			    /* 2D */
-	opcode = (cmd >> 22) & 0x7f;
-	if (_2d_cmds[opcode])
-	    ErrorF ("%-40.40s %d\n", _2d_cmds[opcode], count);
-	else
-	    ErrorF ("2D Reserved\n");
-	break;
-    case 3:			    /* 3D */
-	pipeline_type = (cmd >> 27) & 0x3;
-	opcode = (cmd >> 24) & 0x7;
-	subopcode = (cmd >> 16) & 0xff;
-	if (_3d_cmds[pipeline_type][opcode][subopcode].name) {
-	    ErrorF ("%-40.40s %d\n",
-		    _3d_cmds[pipeline_type][opcode][subopcode].name,
-		    count);
-	} else {
-	    ErrorF ("3D/Media Reserved (pipe %d op %d sub %d)\n", pipeline_type, opcode, subopcode);
-	}
-	break;
-    default:
-	ErrorF ("Reserved\n");
-	break;
-    }
-    return ret;
-}
-
-static int
-i830_valid_chain (ScrnInfoPtr pScrn, unsigned int ring, unsigned int end)
-{
-    I830Ptr pI830 = I830PTR(pScrn);
-    unsigned int head, tail, mask;
-    volatile unsigned char *virt;
-    uint32_t		data;
-    int			count;
-    volatile uint32_t	*ptr;
-    
-    head = (INREG (LP_RING + RING_HEAD)) & I830_HEAD_MASK;
-    tail = INREG (LP_RING + RING_TAIL) & I830_TAIL_MASK;
-    mask = pI830->ring.tail_mask;
-    
-    virt = pI830->ring.virtual_start;
-    ErrorF ("Ring at virtual %p head 0x%x tail 0x%x count %d\n",
-	    virt, head, tail, (((tail + mask + 1) - head) & mask) >> 2);
-
-    for (;;)
-    {
-	ptr = (volatile uint32_t *) (virt + ring);
-	data = *ptr;
-	count = i830_valid_command (data);
-	if (count < 0)
-	    return 0;
-	while (count > 0 && ring != end) 
-	{
-	    ring = (ring + 4) & mask;
-	    count--;
-	}
-	if (ring == end) {
-	    if (count == 0)
-		return 1;
-	    else
-		return 0;
-	}
-    }
-}
-
-static void
-i830_dump_cmds (ScrnInfoPtr		pScrn,
-		volatile unsigned char	*virt,
-		uint32_t		start,
-		uint32_t		stop,
-		uint32_t		mask,
-		uint32_t		acthd)
-{
-    I830Ptr		pI830 = I830PTR(pScrn);
-    uint32_t		ring = start;
-    uint32_t		cmd = start;
-    uint32_t		data;
-    uint32_t		batch_start_mask = ((0x7 << 29) |
-					    (0x3f << 23) |
-					    (0x7ff << 12) |
-					    (1 << 11) |
-					    (1 << 7) |
-					    (1 << 6) |
-					    (0x3f << 0));
-    uint32_t		batch_start_cmd  = ((0x0 << 29) |
-					    (0x31 << 23) |
-					    (0x00 << 12) |
-					    (0 << 11) |
-					    (1 << 7) |
-					    (0 << 6) |
-					    (0 << 0));
-    int			count;
-    volatile uint32_t	*ptr;
-
-    while (ring != stop)
-    {
-	if (ring == acthd)
-	    ErrorF ("****");
-	ErrorF ("\t%08x: %08x", ring, *(volatile unsigned int *) (virt + ring));
-	if (ring == cmd)
-	{
-	    ptr = (volatile uint32_t *) (virt + ring);
-	    data = *ptr;
-	    count = i830_valid_command (data);
-	    i830_dump_cmd (data, count);
-
-	    /* check for MI_BATCH_BUFFER_END */
-	    if (data == (0x0a << 23))
-		stop = (ring + 4) & mask;
-	    /* check for MI_BATCH_BUFFER_START */
-	    if ((data & batch_start_mask) == batch_start_cmd)
-	    {
-		uint32_t    batch = ptr[1] & ~3;
-		if (batch < pI830->FbMapSize) {
-		    ErrorF ("\t%08x: %08x\n", (ring + 4) & mask, batch);
-		    ErrorF ("Batch buffer at 0x%08x {\n", batch);
-		    i830_dump_cmds (pScrn, pI830->FbBase, batch,
-				    batch + 256, 0xffffffff, acthd);
-		    ErrorF ("}\n");
-		    ring = (ring + (count - 1) * 4) & mask;
-		}
-	    }
-	    cmd = (cmd + count * 4) & mask;
-	} else
-	     ErrorF ("\n");
-	ring = (ring + 4) & mask;
-    }
-}
-
-static void
-i830_dump_ring(ScrnInfoPtr pScrn, uint32_t acthd)
-{
-    I830Ptr pI830 = I830PTR(pScrn);
-    unsigned int head, tail, mask, cmd;
-    volatile unsigned char *virt;
-    
-    head = (INREG (LP_RING + RING_HEAD)) & I830_HEAD_MASK;
-    tail = INREG (LP_RING + RING_TAIL) & I830_TAIL_MASK;
-    mask = pI830->ring.tail_mask;
-    
-    virt = pI830->ring.virtual_start;
-    ErrorF ("Ring at virtual %p head 0x%x tail 0x%x count %d acthd 0x%x\n",
-	    virt, head, tail, (((tail + mask + 1) - head) & mask) >> 2, acthd);
-
-    /* walk back by instructions */
-    for (cmd = (head - 256) & mask;
-	 cmd != (head & mask);
-	 cmd = (cmd + 4) & mask)
-    {
-	if (i830_valid_chain (pScrn, cmd, (head & mask)))
-	    break;
-    }
-
-    i830_dump_cmds (pScrn, virt, cmd, head, mask, acthd);
-
-    ErrorF ("Ring end\n");
-}
-
-/* Famous last words
- */
-void
-i830_dump_error_state(ScrnInfoPtr pScrn)
-{
-    I830Ptr pI830 = I830PTR(pScrn);
-
-    ErrorF("pgetbl_ctl: 0x%08x getbl_err: 0x%08x\n",
-	   INREG(PGETBL_CTL), INREG(PGE_ERR));
-
-    ErrorF("ipeir: 0x%08x iphdr: 0x%08x\n", INREG(IPEIR), INREG(IPEHR));
-
-    ErrorF("LP ring tail: 0x%08x head: 0x%08x len: 0x%08x start 0x%08x\n",
-	   INREG(LP_RING + RING_TAIL),
-	   INREG(LP_RING + RING_HEAD) & HEAD_ADDR,
-	   INREG(LP_RING + RING_LEN),
-	   INREG(LP_RING + RING_START));
-
-    ErrorF("eir: 0x%04x esr: 0x%04x emr: 0x%04x\n",
-	   INREG16(EIR), INREG16(ESR), INREG16(EMR));
-
-    ErrorF("instdone: 0x%04x instpm: 0x%04x\n",
-	   INREG16(INST_DONE), INREG8(INST_PM));
-
-    ErrorF("memmode: 0x%08x instps: 0x%08x\n",
-	   INREG(MEMMODE), INREG(INST_PS));
-
-    ErrorF("hwstam: 0x%04x ier: 0x%04x imr: 0x%04x iir: 0x%04x\n",
-	   INREG16(HWSTAM), INREG16(IER), INREG16(IMR), INREG16(IIR));
-    i830_dump_ring (pScrn, INREG(ACTHD));
-}
-
-void
-i965_dump_error_state(ScrnInfoPtr pScrn)
-{
-    I830Ptr pI830 = I830PTR(pScrn);
-    uint32_t	acthd;
-
-    ErrorF("pgetbl_ctl: 0x%08x pgetbl_err: 0x%08x\n",
-	   INREG(PGETBL_CTL), INREG(PGE_ERR));
-
-    ErrorF("ipeir: 0x%08x iphdr: 0x%08x\n",
-	   INREG(IPEIR_I965), INREG(IPEHR_I965));
-
-    ErrorF("LP ring tail: 0x%08x head: %x len: 0x%08x start 0x%08x\n",
-	   INREG(LP_RING + RING_TAIL),
-	   INREG(LP_RING + RING_HEAD) & HEAD_ADDR,
-	   INREG(LP_RING + RING_LEN),
-	   INREG(LP_RING + RING_START));
-
-    ErrorF("Err ID (eir): 0x%08x\n"
-	   "Err Status (esr): 0x%08x\n"
-	   "Err Mask (emr): 0x%08x\n",
-	   INREG(EIR), INREG(ESR), INREG(EMR));
-
-    ErrorF("instdone: 0x%08x instdone_1: 0x%08x\n",
-	   INREG(INST_DONE_I965), INREG(INST_DONE_1));
-    ErrorF("instpm: 0x%08x\n", INREG(INST_PM));
-
-    ErrorF("memmode: 0x%08x instps: 0x%08x\n",
-	   INREG(MEMMODE), INREG(INST_PS_I965));
-
-    ErrorF("HW Status mask (hwstam): 0x%08x\nIRQ enable (ier): 0x%08x "
-	   "imr: 0x%08x iir: 0x%08x\n",
-	   INREG(HWSTAM), INREG(IER), INREG(IMR), INREG(IIR));
-
-    acthd = INREG(ACTHD_I965);
-    ErrorF("acthd: 0x%08x dma_fadd_p: 0x%08x\n",
-	   acthd, INREG(DMA_FADD_P));
-    ErrorF("ecoskpd: 0x%08x excc: 0x%08x\n",
-	   INREG(ECOSKPD), INREG(EXCC));
-
-    ErrorF("cache_mode: 0x%08x/0x%08x\n", INREG(CACHE_MODE_0),
-	   INREG(CACHE_MODE_1));
-    ErrorF("mi_arb_state: 0x%08x\n", INREG(MI_ARB_STATE));
-
-    ErrorF("IA_VERTICES_COUNT_QW 0x%08x/0x%08x\n",
-	   INREG(IA_VERTICES_COUNT_QW),
-	   INREG(IA_VERTICES_COUNT_QW+4));
-    ErrorF("IA_PRIMITIVES_COUNT_QW 0x%08x/0x%08x\n",
-	   INREG(IA_PRIMITIVES_COUNT_QW),
-	   INREG(IA_PRIMITIVES_COUNT_QW+4));
-
-    ErrorF("VS_INVOCATION_COUNT_QW 0x%08x/0x%08x\n",
-	   INREG(VS_INVOCATION_COUNT_QW),
-	   INREG(VS_INVOCATION_COUNT_QW+4));
-
-    ErrorF("GS_INVOCATION_COUNT_QW 0x%08x/0x%08x\n",
-	   INREG(GS_INVOCATION_COUNT_QW),
-	   INREG(GS_INVOCATION_COUNT_QW+4));
-    ErrorF("GS_PRIMITIVES_COUNT_QW 0x%08x/0x%08x\n",
-	   INREG(GS_PRIMITIVES_COUNT_QW),
-	   INREG(GS_PRIMITIVES_COUNT_QW+4));
-
-    ErrorF("CL_INVOCATION_COUNT_QW 0x%08x/0x%08x\n",
-	   INREG(CL_INVOCATION_COUNT_QW),
-	   INREG(CL_INVOCATION_COUNT_QW+4));
-    ErrorF("CL_PRIMITIVES_COUNT_QW 0x%08x/0x%08x\n",
-	   INREG(CL_PRIMITIVES_COUNT_QW),
-	   INREG(CL_PRIMITIVES_COUNT_QW+4));
-
-    ErrorF("PS_INVOCATION_COUNT_QW 0x%08x/0x%08x\n",
-	   INREG(PS_INVOCATION_COUNT_QW),
-	   INREG(PS_INVOCATION_COUNT_QW+4));
-    ErrorF("PS_DEPTH_COUNT_QW 0x%08x/0x%08x\n",
-	   INREG(PS_DEPTH_COUNT_QW),
-	   INREG(PS_DEPTH_COUNT_QW+4));
-
-    ErrorF("WIZ_CTL 0x%08x\n", INREG(WIZ_CTL));
-    ErrorF("TS_CTL 0x%08x  TS_DEBUG_DATA 0x%08x\n", INREG(TS_CTL),
-	   INREG(TS_DEBUG_DATA));
-    ErrorF("TD_CTL 0x%08x / 0x%08x\n",
-	   INREG(TD_CTL), INREG(TD_CTL2));
-    i830_dump_ring (pScrn, acthd);
-}
-
-/**
- * Checks the hardware error state bits.
- *
- * \return TRUE if any errors were found.
- */
-Bool
-i830_check_error_state(ScrnInfoPtr pScrn)
-{
-    I830Ptr pI830 = I830PTR(pScrn);
-    int errors = 0;
-    unsigned long temp, head, tail;
-
-    temp = INREG16(ESR);
-    if (temp != 0) {
-	Bool vertex_max = !IS_I965G(pI830) && (temp & ERR_VERTEX_MAX);
-	Bool pgtbl = temp & ERR_PGTBL_ERROR;
-	Bool underrun = !IS_I965G(pI830) &&
-	    (temp & ERR_DISPLAY_OVERLAY_UNDERRUN);
-	Bool instruction = !IS_I965G(pI830) && (temp & ERR_INSTRUCTION_ERROR);
-
-	xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
-		   "ESR is 0x%08lx%s%s%s%s\n", temp,
-		   vertex_max ? ", max vertices exceeded" : "",
-		   pgtbl ? ", page table error" : "",
-		   underrun ? ", display/overlay underrun" : "",
-		   instruction ? ", instruction error" : "");
-	errors++;
-    }
-    /* Check first for page table errors */
-    if (!IS_I9XX(pI830)) {
-	temp = INREG(PGE_ERR);
-	if (temp != 0) {
-	    xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
-		       "PGTBL_ER is 0x%08lx\n", temp);
-	    errors++;
-	}
-    } else {
-	temp = INREG(PGTBL_ER);
-	if (temp != 0) {
-	    xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
-		       "PGTBL_ER is 0x%08lx"
-		       "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", temp,
-		       temp & PGTBL_ERR_HOST_GTT_PTE ? ", host gtt pte" : "",
-		       temp & PGTBL_ERR_HOST_PTE_DATA ? ", host pte data" : "",
-		       temp & PGTBL_ERR_DISPA_GTT_PTE ? ", display A pte" : "",
-		       temp & PGTBL_ERR_DISPA_TILING ?
-		       ", display A tiling" : "",
-		       temp & PGTBL_ERR_DISPB_GTT_PTE ? ", display B pte" : "",
-		       temp & PGTBL_ERR_DISPB_TILING ?
-		       ", display B tiling" : "",
-		       temp & PGTBL_ERR_DISPC_GTT_PTE ? ", display C pte" : "",
-		       temp & PGTBL_ERR_DISPC_TILING ?
-		       ", display C tiling" : "",
-		       temp & PGTBL_ERR_OVERLAY_GTT_PTE ?
-		       ", overlay GTT PTE" : "",
-		       temp & PGTBL_ERR_OVERLAY_TILING ?
-		       ", overlay tiling" : "",
-		       temp & PGTBL_ERR_CS_GTT ? ", CS GTT" : "",
-		       temp & PGTBL_ERR_CS_INSTRUCTION_GTT_PTE ?
-		       ", CS instruction GTT PTE" : "",
-		       temp & PGTBL_ERR_CS_VERTEXDATA_GTT_PTE ?
-		       ", CS vertex data GTT PTE" : "",
-		       temp & PGTBL_ERR_BIN_INSTRUCTION_GTT_PTE ?
-		       ", BIN instruction GTT PTE" : "",
-		       temp & PGTBL_ERR_BIN_VERTEXDATA_GTT_PTE ?
-		       ", BIN vertex data GTT PTE" : "",
-		       temp & PGTBL_ERR_LC_GTT_PTE ? ", LC pte" : "",
-		       temp & PGTBL_ERR_LC_TILING ? ", LC tiling" : "",
-		       temp & PGTBL_ERR_MT_GTT_PTE ? ", MT pte" : "",
-		       temp & PGTBL_ERR_MT_TILING ? ", MT tiling" : "");
-	    errors++;
-	}
-    }
-    temp = INREG(PGETBL_CTL);
-    if (!(temp & 1)) {
-	xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
-		   "PGTBL_CTL (0x%08lx) indicates GTT is disabled\n", temp);
-	errors++;
-    }
-    temp = INREG(LP_RING + RING_LEN);
-    if (!pI830->have_gem && (temp & 1)) {
-	xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
-		   "PRB0_CTL (0x%08lx) indicates ring buffer enabled\n", temp);
-	errors++;
-    }
-    head = INREG(LP_RING + RING_HEAD);
-    tail = INREG(LP_RING + RING_TAIL);
-    if ((tail & I830_TAIL_MASK) != (head & I830_HEAD_MASK)) {
-	xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
-		   "PRB0_HEAD (0x%08lx) and PRB0_TAIL (0x%08lx) indicate "
-		   "ring buffer not flushed\n", head, tail);
-	errors++;
-    }
-
-#if 0
-    if (errors) {
-	if (IS_I965G(pI830))
-	    i965_dump_error_state(pScrn);
-	else
-	    i830_dump_error_state(pScrn);
-    }
-#endif
-
-    return (errors != 0);
-}
-#endif /* !REG_DUMPER */
diff --git a/src/i830_debug.h b/src/i830_debug.h
index 2d2e72b..6ccd29a 100644
--- a/src/i830_debug.h
+++ b/src/i830_debug.h
@@ -28,7 +28,4 @@
 void i830TakeRegSnapshot(ScrnInfoPtr pScrn);
 void i830CompareRegsToSnapshot(ScrnInfoPtr pScrn, char *where);
 void i830DumpRegs (ScrnInfoPtr pScrn);
-void i830_dump_error_state(ScrnInfoPtr pScrn);
-void i965_dump_error_state(ScrnInfoPtr pScrn);
-Bool i830_check_error_state(ScrnInfoPtr pScrn);
 
diff --git a/src/i830_driver.c b/src/i830_driver.c
index 585eb81..f43c476 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -2992,11 +2992,6 @@ I830EnterVT(int scrnIndex, int flags)
       gen4_render_state_init(pScrn);
 
    if (!pI830->use_drm_mode) {
-       if (i830_check_error_state(pScrn)) {
-	   xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
-		      "Existing errors found in hardware state.\n");
-       }
-
        /* Re-set up the ring. */
        if (!pI830->have_gem) {
 	   i830_stop_ring(pScrn, FALSE);
diff --git a/src/i965_video.c b/src/i965_video.c
index 423d48c..aa0a501 100644
--- a/src/i965_video.c
+++ b/src/i965_video.c
@@ -1242,7 +1242,7 @@ I965DisplayVideoTextured(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv, int id,
     drm_intel_bo_unreference(bind_bo);
 
 #if WATCH_STATS
-    i830_dump_error_state(pScrn);
+    /* i830_dump_error_state(pScrn); */
 #endif
 }
 
commit 2370af32fe31bed8e5715639023635bdb3b83b1b
Author: Daniel Vetter <daniel.vetter at ffwll.ch>
Date:   Tue Aug 11 16:06:47 2009 +0200

    Implement drmmode overlay
    
    This does not restore the overlay on EnterVT/disable it on LeaveVT.
    Does not look like this is necessary.
    
    Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
    [anholt: Hacked in avoiding the actual kernel calls with
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index e8a6c01..00b17dc 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -1415,3 +1415,12 @@ drmmode_get_pipe_from_crtc_id(drm_intel_bufmgr *bufmgr, xf86CrtcPtr crtc)
 
 	return drm_intel_get_pipe_from_crtc_id (bufmgr, drmmode_crtc->mode_crtc->crtc_id);
 }
+
+/* for the drmmode overlay */
+int
+drmmode_crtc_id(xf86CrtcPtr crtc)
+{
+	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+
+	return drmmode_crtc->mode_crtc->crtc_id;
+}
diff --git a/src/i830.h b/src/i830.h
index 009641a..c84fd0c 100644
--- a/src/i830.h
+++ b/src/i830.h
@@ -388,7 +388,7 @@ typedef struct _I830Rec {
 
    /* For Xvideo */
    i830_memory *overlay_regs;
-   void *offscreenImages;          /**< remembered memory block for release */
+   Bool use_drmmode_overlay;
 #ifdef INTEL_XVMC
    /* For XvMC */
    Bool XvMCEnabled;
@@ -693,6 +693,7 @@ void I830DRI2CloseScreen(ScreenPtr pScreen);
 extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, int fd, int cpp);
 extern int drmmode_get_pipe_from_crtc_id(drm_intel_bufmgr *bufmgr, xf86CrtcPtr crtc);
 extern int drmmode_output_dpms_status(xf86OutputPtr output);
+extern int drmmode_crtc_id(xf86CrtcPtr crtc);
 void
 drmmode_crtc_set_cursor_bo(xf86CrtcPtr crtc, dri_bo *cursor);
 
diff --git a/src/i830_driver.c b/src/i830_driver.c
index 316a1fa..585eb81 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -3088,8 +3088,6 @@ I830CloseScreen(int scrnIndex, ScreenPtr pScreen)
    i830_allocator_fini(pScrn);
 
    i965_free_video(pScrn);
-   free(pI830->offscreenImages);
-   pI830->offscreenImages = NULL;
 
    pScreen->CloseScreen = pI830->CloseScreen;
    (*pScreen->CloseScreen) (scrnIndex, pScreen);
diff --git a/src/i830_video.c b/src/i830_video.c
index 80f7303..5e98f27 100644
--- a/src/i830_video.c
+++ b/src/i830_video.c
@@ -356,6 +356,150 @@ CompareOverlay(I830Ptr pI830, uint32_t * overlay, int size)
 static void
 I830SetOneLineModeRatio(ScrnInfoPtr pScrn);
 
+/* kernel modesetting overlay functions */
+static Bool
+drmmode_has_overlay(ScrnInfoPtr pScrn)
+{
+#ifdef DRM_MODE_OVERLAY_LANDED
+    I830Ptr p830 = I830PTR(pScrn);
+    struct drm_i915_getparam gp;
+    int has_overlay = 0;
+
+    gp.param = I915_PARAM_HAS_OVERLAY;
+    gp.value = &has_overlay;
+    drmCommandWriteRead(p830->drmSubFD, DRM_I915_GETPARAM,
+			      &gp, sizeof(gp));
+
+    return has_overlay ? TRUE : FALSE;
+#else
+    return FALSE;
+#endif
+}
+
+static void
+drmmode_overlay_update_attrs(ScrnInfoPtr pScrn)
+{
+#ifdef DRM_MODE_OVERLAY_LANDED
+    I830Ptr p830 = I830PTR(pScrn);
+    I830PortPrivPtr pPriv = GET_PORT_PRIVATE(pScrn);
+    struct drm_intel_overlay_attrs attrs;
+    int ret;
+
+    attrs.flags = I915_OVERLAY_UPDATE_ATTRS;
+    attrs.brightness = pPriv->brightness;
+    attrs.contrast = pPriv->contrast;
+    attrs.saturation = pPriv->saturation;
+    attrs.color_key = pPriv->colorKey;
+    attrs.gamma0 = pPriv->gamma0;
+    attrs.gamma1 = pPriv->gamma1;
+    attrs.gamma2 = pPriv->gamma2;
+    attrs.gamma3 = pPriv->gamma3;
+    attrs.gamma4 = pPriv->gamma4;
+    attrs.gamma5 = pPriv->gamma5;
+
+    ret = drmCommandWriteRead(p830->drmSubFD, DRM_I915_OVERLAY_ATTRS,
+			      &attrs, sizeof(attrs));
+
+    if (ret != 0)
+	    OVERLAY_DEBUG("overlay attrs ioctl failed: %i\n", ret);
+#endif
+}
+
+static void
+drmmode_overlay_off(ScrnInfoPtr pScrn)
+{
+#ifdef DRM_MODE_OVERLAY_LANDED
+    I830Ptr p830 = I830PTR(pScrn);
+    struct drm_intel_overlay_put_image request;
+    int ret;
+
+    request.flags = 0;
+
+    ret = drmCommandWrite(p830->drmSubFD, DRM_I915_OVERLAY_PUT_IMAGE,
+			      &request, sizeof(request));
+
+    if (ret != 0)
+	    OVERLAY_DEBUG("overlay switch-off ioctl failed: %i\n", ret);
+#endif
+}
+
+static Bool
+drmmode_overlay_put_image(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
+		   int id, short width, short height,
+		   int dstPitch, int x1, int y1, int x2, int y2, BoxPtr dstBox,
+		   short src_w, short src_h, short drw_w, short drw_h)
+{
+#ifdef DRM_MODE_OVERLAY_LANDED
+    I830Ptr p830 = I830PTR(pScrn);
+    I830PortPrivPtr pPriv = GET_PORT_PRIVATE(pScrn);
+    struct drm_intel_overlay_put_image request;
+    int ret;
+    int planar = is_planar_fourcc(id);
+    float scale;
+
+    request.flags = I915_OVERLAY_ENABLE;
+
+    request.bo_handle = pPriv->buf->handle;
+    if (planar) {
+	    request.stride_Y = dstPitch*2;
+	    request.stride_UV = dstPitch;
+    } else {
+	    request.stride_Y = dstPitch;
+	    request.stride_UV = 0;
+    }
+    request.offset_Y = pPriv->YBufOffset;
+    request.offset_U = pPriv->UBufOffset;
+    request.offset_V = pPriv->VBufOffset;
+    OVERLAY_DEBUG("off_Y: %i, off_U: %i, off_V: %i\n", request.offset_Y,
+		    request.offset_U, request.offset_V);
+
+    request.crtc_id = drmmode_crtc_id(crtc);
+    request.dst_x = dstBox->x1;
+    request.dst_y = dstBox->y1;
+    request.dst_width = dstBox->x2 - dstBox->x1;
+    request.dst_height = dstBox->y2 - dstBox->y1;
+
+    request.src_width = width;
+    request.src_height = height;
+    /* adjust src dimensions */
+    if (request.dst_height > 1) {
+	scale = ((float) request.dst_height - 1) / ((float) drw_h - 1);
+	request.src_scan_height = src_h * scale;
+    } else
+	request.src_scan_height = 1;
+
+    if (request.dst_width > 1) {
+	scale = ((float) request.dst_width - 1) / ((float) drw_w - 1);
+	request.src_scan_width = src_w * scale;
+    } else
+	request.src_scan_width = 1;
+
+    if (planar) {
+	request.flags |= I915_OVERLAY_YUV_PLANAR | I915_OVERLAY_YUV420;
+    } else {
+	request.flags |= I915_OVERLAY_YUV_PACKED | I915_OVERLAY_YUV422;
+	if (id == FOURCC_UYVY)
+	    request.flags |= I915_OVERLAY_Y_SWAP;
+    }
+
+    ret = drmCommandWrite(p830->drmSubFD, DRM_I915_OVERLAY_PUT_IMAGE,
+			      &request, sizeof(request));
+
+    /* drop the newly displaying buffer right away */
+    drm_intel_bo_disable_reuse(pPriv->buf);
+    drm_intel_bo_unreference(pPriv->buf);
+    pPriv->buf = NULL;
+
+    if (ret != 0) {
+	OVERLAY_DEBUG("overlay put-image ioctl failed: %i\n", ret);
+	return FALSE;
+    } else
+	return TRUE;
+#else
+    return FALSE;
+#endif
+}
+
 static void
 i830_overlay_switch_to_crtc (ScrnInfoPtr pScrn, xf86CrtcPtr crtc)
 {
@@ -597,15 +741,18 @@ I830InitVideo(ScreenPtr pScreen)
     }
 
     /* Set up overlay video if we can do it at this depth. */
-    if (!OVERLAY_NOEXIST(pI830) && pScrn->bitsPerPixel != 8 &&
-	!pI830->use_drm_mode && pI830->overlay_regs != NULL)
+    if (!OVERLAY_NOEXIST(pI830) && pScrn->bitsPerPixel != 8)
     {
-	overlayAdaptor = I830SetupImageVideoOverlay(pScreen);
-	if (overlayAdaptor != NULL) {
-	    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Set up overlay video\n");
-	} else {
-	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-		       "Failed to set up overlay video\n");
+	pI830->use_drmmode_overlay = drmmode_has_overlay(pScrn);
+	if ((!pI830->use_drm_mode  && pI830->overlay_regs != NULL)
+		|| pI830->use_drmmode_overlay) {
+	    overlayAdaptor = I830SetupImageVideoOverlay(pScreen);
+	    if (overlayAdaptor != NULL) {
+		xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Set up overlay video\n");
+	    } else {
+		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+			   "Failed to set up overlay video\n");
+	    }
 	}
     }
 
@@ -942,9 +1089,12 @@ I830SetupImageVideoOverlay(ScreenPtr pScreen)
 	xvGamma5 = MAKE_ATOM("XV_GAMMA5");
     }
 
-    /* XXX These two access the overlay regs, dont call with drmmode */
-    I830ResetVideo(pScrn);
-    I830UpdateGamma(pScrn);
+    if (pI830->use_drmmode_overlay)
+	drmmode_overlay_update_attrs(pScrn);
+    else {
+	I830ResetVideo(pScrn);
+	I830UpdateGamma(pScrn);
+    }
 
     return adapt;
 }
@@ -1052,6 +1202,7 @@ static void
 I830StopVideo(ScrnInfoPtr pScrn, pointer data, Bool shutdown)
 {
     I830PortPrivPtr pPriv = (I830PortPrivPtr) data;
+    I830Ptr pI830 = I830PTR(pScrn);
 
     if (pPriv->textured)
 	return;
@@ -1062,7 +1213,10 @@ I830StopVideo(ScrnInfoPtr pScrn, pointer data, Bool shutdown)
 
     if (shutdown) {
 	if (pPriv->videoStatus & CLIENT_VIDEO_ON) {
-	    ums_overlay_off(pScrn);
+	    if (pI830->use_drmmode_overlay)
+		drmmode_overlay_off(pScrn);
+	    else
+		ums_overlay_off(pScrn);
 	}
 
 	i830_free_video_buffers(pPriv);
@@ -1191,7 +1345,10 @@ I830SetPortAttributeOverlay(ScrnInfoPtr pScrn,
 	OVERLAY_DEBUG("GAMMA\n");
     }
 
-    ums_overlay_update_attrs(pScrn, pPriv);
+    if (pI830->use_drmmode_overlay)
+	drmmode_overlay_update_attrs(pScrn);
+    else
+	ums_overlay_update_attrs(pScrn, pPriv);
 
     if (attribute == xvColorKey)
 	REGION_EMPTY(pScrn->pScreen, &pPriv->clip);
@@ -2108,7 +2265,11 @@ i830_display_overlay(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
     if (!crtc)
     {
 	pPriv->current_crtc = NULL;
-	ums_overlay_off(pScrn);
+	if (pI830->use_drmmode_overlay)
+	    drmmode_overlay_off(pScrn);
+	else
+	    ums_overlay_off(pScrn);
+
 	return TRUE;
     }
 
@@ -2126,8 +2287,12 @@ i830_display_overlay(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
 	src_h = tmp;
     }
 
-    return ums_overlay_put_image(pScrn, crtc, id, width, height, dstPitch,
-	    x1, y1, x2, y2, dstBox, src_w, src_h, drw_w, drw_h);
+    if (pI830->use_drmmode_overlay)
+	return drmmode_overlay_put_image(pScrn, crtc, id, width, height, dstPitch,
+		x1, y1, x2, y2, dstBox, src_w, src_h, drw_w, drw_h);
+    else
+	return ums_overlay_put_image(pScrn, crtc, id, width, height, dstPitch,
+		x1, y1, x2, y2, dstBox, src_w, src_h, drw_w, drw_h);
 }
 
 static Bool
@@ -2636,7 +2801,10 @@ I830VideoBlockHandler(int i, pointer blockData, pointer pTimeout,
 		/* Turn off the overlay */
 		OVERLAY_DEBUG("BLOCKHANDLER\n");
 
-		ums_overlay_off (pScrn);
+		if (pI830->use_drmmode_overlay)
+		    drmmode_overlay_off(pScrn);
+		else
+		    ums_overlay_off (pScrn);
 
 		pPriv->videoStatus = FREE_TIMER;
 		pPriv->freeTime = now + FREE_DELAY;
commit 99230864050ea2f26c2412c4c87c50947fc3cbe1
Author: Daniel Vetter <daniel.vetter at ffwll.ch>
Date:   Tue Aug 11 16:06:46 2009 +0200

    Xv: introduce an overlay hal
    
    This is the last preparatory step for overlay support with drmmode.
    Safe two (specially marked) function calls in the setup code, all
    hw accessing code goes now through these three new functions with
    the ums_overlay prefix.
    
    Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/src/i830_video.c b/src/i830_video.c
index 15ada0f..80f7303 100644
--- a/src/i830_video.c
+++ b/src/i830_video.c
@@ -942,8 +942,8 @@ I830SetupImageVideoOverlay(ScreenPtr pScreen)
 	xvGamma5 = MAKE_ATOM("XV_GAMMA5");
     }
 
+    /* XXX These two access the overlay regs, dont call with drmmode */
     I830ResetVideo(pScrn);
-
     I830UpdateGamma(pScrn);
 
     return adapt;
@@ -1043,6 +1043,12 @@ i830_free_video_buffers(I830PortPrivPtr pPriv)
 }
 
 static void
+ums_overlay_off(ScrnInfoPtr pScrn)
+{
+    i830_overlay_off (pScrn);
+}
+
+static void
 I830StopVideo(ScrnInfoPtr pScrn, pointer data, Bool shutdown)
 {
     I830PortPrivPtr pPriv = (I830PortPrivPtr) data;
@@ -1056,7 +1062,7 @@ I830StopVideo(ScrnInfoPtr pScrn, pointer data, Bool shutdown)
 
     if (shutdown) {
 	if (pPriv->videoStatus & CLIENT_VIDEO_ON) {
-	    i830_overlay_off(pScrn);
+	    ums_overlay_off(pScrn);
 	}
 
 	i830_free_video_buffers(pPriv);
@@ -1089,7 +1095,6 @@ I830SetPortAttributeTextured(ScrnInfoPtr pScrn,
     } else if (attribute == xvSyncToVblank) {
         if ((value < -1) || (value > 1))
             return BadValue;
-        
         pPriv->SyncToVblank = value;
         return Success;
     } else {
@@ -1097,36 +1102,56 @@ I830SetPortAttributeTextured(ScrnInfoPtr pScrn,
     }
 }
 
+static void
+ums_overlay_update_attrs(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv)
+{
+    I830Ptr pI830 = I830PTR(pScrn);
+    I830OverlayRegPtr overlay;
+
+    overlay = I830OVERLAYREG(pI830);
+
+    overlay->OCLRC0 = (pPriv->contrast << 18) | (pPriv->brightness & 0xff);
+    overlay->OCLRC0 = (pPriv->contrast << 18) | (pPriv->brightness & 0xff);
+    overlay->OCLRC1 = pPriv->saturation;
+
+    switch (pScrn->depth) {
+    case 16:
+	overlay->DCLRKV = RGB16ToColorKey(pPriv->colorKey);
+	break;
+    case 15:
+	overlay->DCLRKV = RGB15ToColorKey(pPriv->colorKey);
+	break;
+    default:
+	overlay->DCLRKV = pPriv->colorKey;
+	break;
+    }
+
+    I830UpdateGamma(pScrn);
+
+    i830_overlay_continue(pScrn, FALSE);
+}
+
 static int
 I830SetPortAttributeOverlay(ScrnInfoPtr pScrn,
 		     Atom attribute, INT32 value, pointer data)
 {
     I830PortPrivPtr pPriv = (I830PortPrivPtr) data;
     I830Ptr pI830 = I830PTR(pScrn);
-    I830OverlayRegPtr overlay;
-
-    overlay = I830OVERLAYREG(pI830);
 
     if (attribute == xvBrightness) {
 	if ((value < -128) || (value > 127))
 	    return BadValue;
 	pPriv->brightness = value;
-	overlay->OCLRC0 = (pPriv->contrast << 18) | (pPriv->brightness & 0xff);
 	OVERLAY_DEBUG("BRIGHTNESS\n");
-	i830_overlay_continue (pScrn, FALSE);
     } else if (attribute == xvContrast) {
 	if ((value < 0) || (value > 255))
 	    return BadValue;
 	pPriv->contrast = value;
-	overlay->OCLRC0 = (pPriv->contrast << 18) | (pPriv->brightness & 0xff);
 	OVERLAY_DEBUG("CONTRAST\n");
-	i830_overlay_continue (pScrn, FALSE);
     } else if (attribute == xvSaturation) {
 	if ((value < 0) || (value > 1023))
 	    return BadValue;
 	pPriv->saturation = value;
-	overlay->OCLRC1 = pPriv->saturation;
-	i830_overlay_continue (pScrn, FALSE);
     } else if (attribute == xvPipe) {
 	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
 	if ((value < -1) || (value > xf86_config->num_crtc))
@@ -1139,7 +1164,7 @@ I830SetPortAttributeOverlay(ScrnInfoPtr pScrn,
 	 * Leave this to be updated at the next frame
 	 */
     } else if (attribute == xvGamma0 && (IS_I9XX(pI830))) {
-	pPriv->gamma0 = value; 
+	pPriv->gamma0 = value;
     } else if (attribute == xvGamma1 && (IS_I9XX(pI830))) {
 	pPriv->gamma1 = value;
     } else if (attribute == xvGamma2 && (IS_I9XX(pI830))) {
@@ -1152,20 +1177,7 @@ I830SetPortAttributeOverlay(ScrnInfoPtr pScrn,
 	pPriv->gamma5 = value;
     } else if (attribute == xvColorKey) {
 	pPriv->colorKey = value;
-	switch (pScrn->depth) {
-	case 16:
-	    overlay->DCLRKV = RGB16ToColorKey(pPriv->colorKey);
-	    break;
-	case 15:
-	    overlay->DCLRKV = RGB15ToColorKey(pPriv->colorKey);
-	    break;
-	default:
-	    overlay->DCLRKV = pPriv->colorKey;
-	    break;
-	}
 	OVERLAY_DEBUG("COLORKEY\n");
-	i830_overlay_continue (pScrn, FALSE);
-	REGION_EMPTY(pScrn->pScreen, &pPriv->clip);
     } else
 	return BadMatch;
 
@@ -1177,9 +1189,13 @@ I830SetPortAttributeOverlay(ScrnInfoPtr pScrn,
 	 attribute == xvGamma4 ||
 	 attribute == xvGamma5) && (IS_I9XX(pI830))) {
 	OVERLAY_DEBUG("GAMMA\n");
-	I830UpdateGamma(pScrn);
     }
 
+    ums_overlay_update_attrs(pScrn, pPriv);
+
+    if (attribute == xvColorKey)
+	REGION_EMPTY(pScrn->pScreen, &pPriv->clip);
+
     return Success;
 }
 
@@ -1964,7 +1980,7 @@ xvmc_passthrough(int id, Rotation rotation)
 }
 
 static Bool
-i830_display_overlay(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
+ums_overlay_put_image(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
 		   int id, short width, short height,
 		   int dstPitch, int x1, int y1, int x2, int y2, BoxPtr dstBox,
 		   short src_w, short src_h, short drw_w, short drw_h)
@@ -1974,29 +1990,12 @@ i830_display_overlay(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
     I830OverlayRegPtr	overlay = I830OVERLAYREG(pI830);
     int			planar;
     uint32_t		swidth, swidthsw, sheigth;
-    int			tmp;
     Bool		scaleChanged;
     drm_intel_bo	*tmp_buf;
 
-    OVERLAY_DEBUG("I830DisplayVideo: %dx%d (pitch %d)\n", width, height,
-		  dstPitch);
-
-#if VIDEO_DEBUG
-    CompareOverlay(pI830, (uint32_t *) overlay, 0x100);
-#endif
-    
-    /*
-     * If the video isn't visible on any CRTC, turn it off
-     */
-    if (!crtc)
-    {
-	pPriv->current_crtc = NULL;
-	i830_overlay_off (pScrn);
-	return TRUE;
-    }
-    
     if (crtc != pPriv->current_crtc)
     {
+	/* this may adjust pPriv->oneLineMode */
 	i830_overlay_switch_to_crtc (pScrn, crtc);
 	if (pPriv->overlayOK) {
 	    pPriv->current_crtc = crtc;
@@ -2007,20 +2006,6 @@ i830_display_overlay(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
     if (!pPriv->overlayOK)
 	return TRUE;
 
-    i830_update_dst_box_to_crtc_coords(pScrn, crtc, dstBox);
-
-    if (crtc->rotation & (RR_Rotate_90 | RR_Rotate_270)) {
-	tmp = width;
-	width = height;
-	height = tmp;
-	tmp = drw_w;
-	drw_w = drw_h;
-	drw_h = tmp;
-	tmp = src_w;
-	src_w = src_h;
-	src_h = tmp;
-    }
-
     if (pPriv->oneLineMode) {
 	/* change the coordinates with panel fitting active */
 	dstBox->y1 = (((dstBox->y1 - 1) * pPriv->scaleRatio) >> 16) + 1;
@@ -2101,6 +2086,51 @@ i830_display_overlay(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
 }
 
 static Bool
+i830_display_overlay(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
+		   int id, short width, short height,
+		   int dstPitch, int x1, int y1, int x2, int y2, BoxPtr dstBox,
+		   short src_w, short src_h, short drw_w, short drw_h)
+{
+    I830Ptr		pI830 = I830PTR(pScrn);
+    I830PortPrivPtr	pPriv = pI830->adaptor->pPortPrivates[0].ptr;
+    int			tmp;
+
+    OVERLAY_DEBUG("I830DisplayVideo: %dx%d (pitch %d)\n", width, height,
+		  dstPitch);
+
+#if VIDEO_DEBUG
+    CompareOverlay(pI830, (uint32_t *) overlay, 0x100);
+#endif
+
+    /*
+     * If the video isn't visible on any CRTC, turn it off
+     */
+    if (!crtc)
+    {
+	pPriv->current_crtc = NULL;
+	ums_overlay_off(pScrn);
+	return TRUE;
+    }
+
+    i830_update_dst_box_to_crtc_coords(pScrn, crtc, dstBox);
+
+    if (crtc->rotation & (RR_Rotate_90 | RR_Rotate_270)) {
+	tmp = width;
+	width = height;
+	height = tmp;
+	tmp = drw_w;
+	drw_w = drw_h;
+	drw_h = tmp;
+	tmp = src_w;
+	src_w = src_h;
+	src_h = tmp;
+    }
+
+    return ums_overlay_put_image(pScrn, crtc, id, width, height, dstPitch,
+	    x1, y1, x2, y2, dstBox, src_w, src_h, drw_w, drw_h);
+}
+
+static Bool
 i830_clip_video_helper (ScrnInfoPtr pScrn,
 			I830PortPrivPtr pPriv,
 			xf86CrtcPtr *crtc_ret,
@@ -2606,7 +2636,7 @@ I830VideoBlockHandler(int i, pointer blockData, pointer pTimeout,
 		/* Turn off the overlay */
 		OVERLAY_DEBUG("BLOCKHANDLER\n");
 
-		i830_overlay_off (pScrn);
+		ums_overlay_off (pScrn);
 
 		pPriv->videoStatus = FREE_TIMER;
 		pPriv->freeTime = now + FREE_DELAY;
commit bb04e184fdc55325a362ebf291e16a7c112a5f1d
Author: Daniel Vetter <daniel.vetter at ffwll.ch>
Date:   Tue Aug 11 16:06:45 2009 +0200

    Xv: rework overlay buffer management
    
    The basic idea is to only pin the buffer into the gtt when
    the overlay hw is actually using it. This results in a few changes:
    
    - Unify data copied/buffer handling with textured video. Now offsets
      are always buffer relative and we just use drm_bo_map to access a
      buffer.
    - Implement double buffering using two bo's. This is necessary because
      we can't pin the same buffer to the gtt and map it as normal memory.
    - Kill XV_DOUBLE_BUFFER. With the above changes, overlay video is always
      doubel buffered.
    
    There is still the XvMC passthrough case, which makes the code slightly
    ugly. Unfortunately we can't get at the bo behind this buffer.
    
    Changes since the last review-round:
    - Don't overallocate by a factor of 2.
    - Prevent possible use-after-free issue.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/src/i830_video.c b/src/i830_video.c
index 8592750..15ada0f 100644
--- a/src/i830_video.c
+++ b/src/i830_video.c
@@ -103,7 +103,7 @@ static int I830QueryImageAttributes(ScrnInfoPtr, int, unsigned short *,
 
 #define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, TRUE)
 
-static Atom xvBrightness, xvContrast, xvSaturation, xvColorKey, xvPipe, xvDoubleBuffer;
+static Atom xvBrightness, xvContrast, xvSaturation, xvColorKey, xvPipe;
 static Atom xvGamma0, xvGamma1, xvGamma2, xvGamma3, xvGamma4, xvGamma5;
 static Atom xvSyncToVblank;
 
@@ -214,13 +214,12 @@ static XF86AttributeRec CloneAttributes[CLONE_ATTRIBUTES] = {
     {XvSettable | XvGettable, -1, 1, "XV_PIPE"}
 };
 
-#define NUM_ATTRIBUTES 5
+#define NUM_ATTRIBUTES 4
 static XF86AttributeRec Attributes[NUM_ATTRIBUTES] = {
     {XvSettable | XvGettable, 0, (1 << 24) - 1, "XV_COLORKEY"},
     {XvSettable | XvGettable, -128, 127, "XV_BRIGHTNESS"},
     {XvSettable | XvGettable, 0, 255, "XV_CONTRAST"},
-    {XvSettable | XvGettable, 0, 1023, "XV_SATURATION"},
-    {XvSettable | XvGettable, 0, 1, "XV_DOUBLE_BUFFER"}
+    {XvSettable | XvGettable, 0, 1023, "XV_SATURATION"}
 };
 
 #define NUM_TEXTURED_ATTRIBUTES 3
@@ -487,6 +486,8 @@ i830_overlay_continue(ScrnInfoPtr pScrn, Bool update_filter)
     OUT_BATCH(flip_addr);
     ADVANCE_BATCH();
     OVERLAY_DEBUG("overlay_continue\n");
+
+    I830Sync(pScrn);
 }
 
 static void
@@ -895,14 +896,14 @@ I830SetupImageVideoOverlay(ScreenPtr pScreen)
     pPriv->current_crtc = NULL;
     pPriv->desired_crtc = NULL;
     pPriv->buf = NULL;
-    pPriv->currentBuf = 0;
+    pPriv->oldBuf = NULL;
+    pPriv->oldBuf_pinned = FALSE;
     pPriv->gamma5 = 0xc0c0c0;
     pPriv->gamma4 = 0x808080;
     pPriv->gamma3 = 0x404040;
     pPriv->gamma2 = 0x202020;
     pPriv->gamma1 = 0x101010;
     pPriv->gamma0 = 0x080808;
-    pPriv->doubleBuffer = 1;
 
     pPriv->rotation = RR_Rotate_0;
 
@@ -928,7 +929,6 @@ I830SetupImageVideoOverlay(ScreenPtr pScreen)
     xvBrightness = MAKE_ATOM("XV_BRIGHTNESS");
     xvContrast = MAKE_ATOM("XV_CONTRAST");
     xvSaturation = MAKE_ATOM("XV_SATURATION");
-    xvDoubleBuffer = MAKE_ATOM("XV_DOUBLE_BUFFER");
 
     /* Allow the pipe to be switched from pipe A to B when in clone mode */
     xvPipe = MAKE_ATOM("XV_PIPE");
@@ -1008,8 +1008,8 @@ I830SetupImageVideoTextured(ScreenPtr pScreen)
 	pPriv->textured = TRUE;
 	pPriv->videoStatus = 0;
 	pPriv->buf = NULL;
-	pPriv->currentBuf = 0;
-	pPriv->doubleBuffer = 0;
+	pPriv->oldBuf = NULL;
+	pPriv->oldBuf_pinned = FALSE;
 
 	pPriv->rotation = RR_Rotate_0;
 	pPriv->SyncToVblank = 1;
@@ -1026,6 +1026,23 @@ I830SetupImageVideoTextured(ScreenPtr pScreen)
 }
 
 static void
+i830_free_video_buffers(I830PortPrivPtr pPriv)
+{
+    if (pPriv->buf) {
+	drm_intel_bo_unreference(pPriv->buf);
+	pPriv->buf = NULL;
+    }
+
+    if (pPriv->oldBuf) {
+	if (pPriv->oldBuf_pinned)
+	    drm_intel_bo_unpin(pPriv->oldBuf);
+	drm_intel_bo_unreference(pPriv->oldBuf);
+	pPriv->oldBuf = NULL;
+	pPriv->oldBuf_pinned = FALSE;
+    }
+}
+
+static void
 I830StopVideo(ScrnInfoPtr pScrn, pointer data, Bool shutdown)
 {
     I830PortPrivPtr pPriv = (I830PortPrivPtr) data;
@@ -1042,12 +1059,8 @@ I830StopVideo(ScrnInfoPtr pScrn, pointer data, Bool shutdown)
 	    i830_overlay_off(pScrn);
 	}
 
-	if (pPriv->buf) {
-	    drm_intel_bo_unpin(pPriv->buf);
-	    drm_intel_bo_unreference(pPriv->buf);
-	    pPriv->buf = NULL;
-	    pPriv->videoStatus = 0;
-	}
+	i830_free_video_buffers(pPriv);
+	pPriv->videoStatus = 0;
     } else {
 	if (pPriv->videoStatus & CLIENT_VIDEO_ON) {
 	    pPriv->videoStatus |= OFF_TIMER;
@@ -1153,12 +1166,6 @@ I830SetPortAttributeOverlay(ScrnInfoPtr pScrn,
 	OVERLAY_DEBUG("COLORKEY\n");
 	i830_overlay_continue (pScrn, FALSE);
 	REGION_EMPTY(pScrn->pScreen, &pPriv->clip);
-    } else if(attribute == xvDoubleBuffer) {
-	if ((value < 0) || (value > 1))
-	    return BadValue;
-	/* Do not allow buffer change while playing video */
-	if(!pI830->overlayOn)
-	    pPriv->doubleBuffer = value;
     } else
 	return BadMatch;
 
@@ -1212,8 +1219,6 @@ I830GetPortAttribute(ScrnInfoPtr pScrn,
 	*value = pPriv->gamma5;
     } else if (attribute == xvColorKey) {
 	*value = pPriv->colorKey;
-    } else if (attribute == xvDoubleBuffer) {
-	*value = pPriv->doubleBuffer;
     } else if (attribute == xvSyncToVblank) {
         *value = pPriv->SyncToVblank;
     } else
@@ -1239,12 +1244,11 @@ I830QueryBestSize(ScrnInfoPtr pScrn,
 }
 
 static void
-I830CopyPackedData(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
+I830CopyPackedData(I830PortPrivPtr pPriv,
 		   unsigned char *buf,
 		   int srcPitch,
 		   int dstPitch, int top, int left, int h, int w)
 {
-    I830Ptr pI830 = I830PTR(pScrn);
     unsigned char *src, *dst, *dst_base;
     int i,j;
     unsigned char *s;
@@ -1257,13 +1261,8 @@ I830CopyPackedData(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
 
     src = buf + (top * srcPitch) + (left << 1);
 
-    if (pPriv->textured) {
-	drm_intel_bo_map(pPriv->buf, TRUE);
-	dst_base = pPriv->buf->virtual;
-    } else {
-	drm_intel_gem_bo_start_gtt_access(pPriv->buf, TRUE);
-	dst_base = pI830->FbBase;
-    }
+    drm_intel_bo_map(pPriv->buf, TRUE);
+    dst_base = pPriv->buf->virtual;
 
     dst = dst_base + pPriv->YBufOffset;
 
@@ -1339,8 +1338,7 @@ I830CopyPackedData(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
 	break;
     }
 
-    if (pPriv->textured)
-	drm_intel_bo_unmap(pPriv->buf);
+    drm_intel_bo_unmap(pPriv->buf);
 }
 
 static void i830_memcpy_plane(unsigned char *dst, unsigned char *src,
@@ -1393,12 +1391,11 @@ static void i830_memcpy_plane(unsigned char *dst, unsigned char *src,
 }
 
 static void
-I830CopyPlanarData(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
+I830CopyPlanarData(I830PortPrivPtr pPriv,
 		   unsigned char *buf, int srcPitch,
 		   int srcPitch2, int dstPitch, int srcH, int top, int left,
 		   int h, int w, int id)
 {
-    I830Ptr pI830 = I830PTR(pScrn);
     unsigned char *src1, *src2, *src3, *dst_base, *dst1, *dst2, *dst3;
     int dstPitch2 = dstPitch << 1;
 
@@ -1416,13 +1413,8 @@ I830CopyPlanarData(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
 	   (unsigned long)src1 - (unsigned long)buf);
 #endif
 
-    if (pPriv->textured) {
-	drm_intel_bo_map(pPriv->buf, TRUE);
-	dst_base = pPriv->buf->virtual;
-    } else {
-	drm_intel_gem_bo_start_gtt_access(pPriv->buf, TRUE);
-	dst_base = pI830->FbBase;
-    }
+    drm_intel_bo_map(pPriv->buf, TRUE);
+    dst_base = pPriv->buf->virtual;
 
     dst1 = dst_base + pPriv->YBufOffset;
 
@@ -1464,8 +1456,7 @@ I830CopyPlanarData(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
     i830_memcpy_plane(dst3, src3, h/2, w/2,
 		    dstPitch, srcPitch2, pPriv->rotation);
 
-    if (pPriv->textured)
-	drm_intel_bo_unmap(pPriv->buf);
+    drm_intel_bo_unmap(pPriv->buf);
 }
 
 typedef struct {
@@ -1972,7 +1963,7 @@ xvmc_passthrough(int id, Rotation rotation)
 #endif
 }
 
-static void
+static Bool
 i830_display_overlay(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
 		   int id, short width, short height,
 		   int dstPitch, int x1, int y1, int x2, int y2, BoxPtr dstBox,
@@ -1985,6 +1976,7 @@ i830_display_overlay(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
     uint32_t		swidth, swidthsw, sheigth;
     int			tmp;
     Bool		scaleChanged;
+    drm_intel_bo	*tmp_buf;
 
     OVERLAY_DEBUG("I830DisplayVideo: %dx%d (pitch %d)\n", width, height,
 		  dstPitch);
@@ -2000,7 +1992,7 @@ i830_display_overlay(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
     {
 	pPriv->current_crtc = NULL;
 	i830_overlay_off (pScrn);
-	return;
+	return TRUE;
     }
     
     if (crtc != pPriv->current_crtc)
@@ -2013,7 +2005,7 @@ i830_display_overlay(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
     }
 
     if (!pPriv->overlayOK)
-	return;
+	return TRUE;
 
     i830_update_dst_box_to_crtc_coords(pScrn, crtc, dstBox);
 
@@ -2056,9 +2048,17 @@ i830_display_overlay(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
 		  dstBox->x1, dstBox->y1, dstBox->x2, dstBox->y2);
 
     /* buffer locations */
-    overlay->OBUF_0Y = pPriv->YBufOffset;
-    overlay->OBUF_0U = pPriv->UBufOffset;
-    overlay->OBUF_0V = pPriv->VBufOffset;
+    if (xvmc_passthrough(id, pPriv->rotation)) {
+	overlay->OBUF_0Y = pPriv->YBufOffset;
+	overlay->OBUF_0U = pPriv->UBufOffset;
+	overlay->OBUF_0V = pPriv->VBufOffset;
+    } else {
+	if (drm_intel_bo_pin(pPriv->buf, GTT_PAGE_SIZE) != 0)
+	    return FALSE;
+	overlay->OBUF_0Y = pPriv->YBufOffset + pPriv->buf->offset;
+	overlay->OBUF_0U = pPriv->UBufOffset + pPriv->buf->offset;
+	overlay->OBUF_0V = pPriv->VBufOffset + pPriv->buf->offset;
+    }
 
     OVERLAY_DEBUG("pos: 0x%x, size: 0x%x\n",
 		  overlay->DWINPOS, overlay->DWINSZ);
@@ -2084,6 +2084,20 @@ i830_display_overlay(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
     i830_overlay_on (pScrn);
     /* and show this frame */
     i830_overlay_continue (pScrn, scaleChanged);
+
+    if (xvmc_passthrough(id, pPriv->rotation))
+	return TRUE;
+
+    /* unpin the old buffer and exchange buffers */
+    if (pPriv->oldBuf_pinned) {
+	drm_intel_bo_unpin(pPriv->oldBuf);
+    }
+    tmp_buf = pPriv->buf;
+    pPriv->buf = pPriv->oldBuf;
+    pPriv->oldBuf = tmp_buf;
+    pPriv->oldBuf_pinned = TRUE;
+
+    return TRUE;
 }
 
 static Bool
@@ -2209,31 +2223,18 @@ i830_setup_video_buffer(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
     I830Ptr pI830 = I830PTR(pScrn);
     /* Free the current buffer if we're going to have to reallocate */
     if (pPriv->buf && pPriv->buf->size < alloc_size) {
-	if (!pPriv->textured)
-	    drm_intel_bo_unpin(pPriv->buf);
 	drm_intel_bo_unreference(pPriv->buf);
 	pPriv->buf = NULL;
     }
 
     if (xvmc_passthrough(id, pPriv->rotation)) {
-        if (pPriv->buf) {
-            assert(pPriv->textured);
-            drm_intel_bo_unreference(pPriv->buf);
-            pPriv->buf = NULL;
-        }
+	i830_free_video_buffers(pPriv);
     } else {
         if (pPriv->buf == NULL) {
             pPriv->buf = drm_intel_bo_alloc(pI830->bufmgr,
                                          "xv buffer", alloc_size, 4096);
             if (pPriv->buf == NULL)
                 return FALSE;
-            if (!pPriv->textured && drm_intel_bo_pin(pPriv->buf, 4096) != 0) {
-                drm_intel_bo_unreference(pPriv->buf);
-                pPriv->buf = NULL;
-                xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-                           "Failed to pin xv buffer\n");
-                return FALSE;
-            }
         }
     }
 
@@ -2315,7 +2316,6 @@ i830_copy_video_data(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
     I830Ptr pI830 = I830PTR(pScrn);
     int srcPitch = 0, srcPitch2 = 0;
     int top, left, npixels, nlines, size;
-    int alloc_size;
 
     if (is_planar_fourcc(id)) {
 	srcPitch = (width + 0x3) & ~0x3;
@@ -2327,11 +2327,7 @@ i830_copy_video_data(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
     i830_dst_pitch_and_size(pScrn, pPriv, width, height, dstPitch, dstPitch2,
 	    &size, id);
 
-    alloc_size = size;
-    if (pPriv->doubleBuffer)
-	alloc_size *= 2;
-
-    if (!i830_setup_video_buffer(pScrn, pPriv, alloc_size, id))
+    if (!i830_setup_video_buffer(pScrn, pPriv, size, id))
 	return FALSE;
 
     /* fixup pointers */
@@ -2342,20 +2338,7 @@ i830_copy_video_data(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
 	pPriv->UBufOffset = pPriv->VBufOffset + (*dstPitch * height / 2);
     } else {
 #endif
-	if (pPriv->textured)
-	    pPriv->YBufOffset = 0;
-	else
-	    pPriv->YBufOffset = pPriv->buf->offset;
-
-	/* switch buffers if double buffered */
-	if (!pPriv->textured && pPriv->doubleBuffer) {
-	    if (pPriv->currentBuf == 0)
-		pPriv->currentBuf = 1;
-	    else
-		pPriv->currentBuf = 0;
-
-	    pPriv->YBufOffset += size*pPriv->currentBuf;
-	}
+	pPriv->YBufOffset = 0;
 
 	if (pPriv->rotation & (RR_Rotate_90 | RR_Rotate_270)) {
 	    pPriv->UBufOffset = pPriv->YBufOffset + (*dstPitch * 2 * width);
@@ -2377,12 +2360,12 @@ i830_copy_video_data(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
 	if (!xvmc_passthrough(id, pPriv->rotation)) {
 	    top &= ~1;
 	    nlines = ((((y2 + 0xffff) >> 16) + 1) & ~1) - top;
-	    I830CopyPlanarData(pScrn, pPriv, buf, srcPitch, srcPitch2, *dstPitch,
+	    I830CopyPlanarData(pPriv, buf, srcPitch, srcPitch2, *dstPitch,
 		    height, top, left, nlines, npixels, id);
 	}
     } else {
 	nlines = ((y2 + 0xffff) >> 16) - top;
-	I830CopyPackedData(pScrn, pPriv, buf, srcPitch, *dstPitch, top, left,
+	I830CopyPackedData(pPriv, buf, srcPitch, *dstPitch, top, left,
 			   nlines, npixels);
     }
 
@@ -2475,9 +2458,10 @@ I830PutImage(ScrnInfoPtr pScrn,
 	return BadAlloc;
 
     if (!pPriv->textured) {
-	i830_display_overlay(pScrn, crtc, id, width, height, dstPitch,
+	if (!i830_display_overlay(pScrn, crtc, id, width, height, dstPitch,
 			   x1, y1, x2, y2, &dstBox, src_w, src_h,
-			   drw_w, drw_h);
+			   drw_w, drw_h))
+	    return BadAlloc;
 	
 	/* update cliplist */
 	if (!REGION_EQUAL(pScrn->pScreen, &pPriv->clip, clipBoxes)) {
@@ -2629,10 +2613,7 @@ I830VideoBlockHandler(int i, pointer blockData, pointer pTimeout,
 	    }
 	} else {				/* FREE_TIMER */
 	    if (pPriv->freeTime < now) {
-		if (!pPriv->textured)
-		    drm_intel_bo_unpin(pPriv->buf);
-		drm_intel_bo_unreference(pPriv->buf);
-		pPriv->buf = NULL;
+		i830_free_video_buffers(pPriv);
 		pPriv->videoStatus = 0;
 	    }
 	}
diff --git a/src/i830_video.h b/src/i830_video.h
index 9093d5d..cdccd16 100644
--- a/src/i830_video.h
+++ b/src/i830_video.h
@@ -32,14 +32,11 @@ typedef struct {
    uint32_t UBufOffset;
    uint32_t VBufOffset;
 
-   unsigned char currentBuf;
-
    int brightness;
    int contrast;
    int saturation;
    xf86CrtcPtr current_crtc;
    xf86CrtcPtr desired_crtc;
-   int doubleBuffer;
 
    RegionRec clip;
    uint32_t colorKey;
@@ -54,7 +51,10 @@ typedef struct {
    uint32_t videoStatus;
    Time offTime;
    Time freeTime;
-   drm_intel_bo *buf; /** YUV data buffer */
+   /** YUV data buffers */
+   drm_intel_bo *buf; /* current buffer to draw into */
+   drm_intel_bo *oldBuf; /* old buffer, may be in use by the overlay hw */
+   Bool oldBuf_pinned; /* only actually pinned when in use by the overlay hw */
 
    Bool overlayOK;
    int oneLineMode;
commit 60462eb5b5c1931beecc1ed2d32f91090f64174c
Author: Daniel Vetter <daniel.vetter at ffwll.ch>
Date:   Tue Aug 11 16:06:44 2009 +0200

    Xv: create xvmc_passthrough helper
    
    This way all thes strange special cases make much more sense.
    
    Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/src/i830_video.c b/src/i830_video.c
index 5e2db6c..8592750 100644
--- a/src/i830_video.c
+++ b/src/i830_video.c
@@ -1962,6 +1962,16 @@ is_planar_fourcc(int id)
     }
 }
 
+static int
+xvmc_passthrough(int id, Rotation rotation)
+{
+#ifdef INTEL_XVMC
+    return id == FOURCC_XVMC && rotation == RR_Rotate_0;
+#else
+    return 0;
+#endif
+}
+
 static void
 i830_display_overlay(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
 		   int id, short width, short height,
@@ -2205,16 +2215,13 @@ i830_setup_video_buffer(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
 	pPriv->buf = NULL;
     }
 
-#ifdef INTEL_XVMC
-    if (id == FOURCC_XVMC &&
-        pPriv->rotation == RR_Rotate_0) {
+    if (xvmc_passthrough(id, pPriv->rotation)) {
         if (pPriv->buf) {
             assert(pPriv->textured);
             drm_intel_bo_unreference(pPriv->buf);
             pPriv->buf = NULL;
         }
     } else {
-#endif
         if (pPriv->buf == NULL) {
             pPriv->buf = drm_intel_bo_alloc(pI830->bufmgr,
                                          "xv buffer", alloc_size, 4096);
@@ -2228,9 +2235,8 @@ i830_setup_video_buffer(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
                 return FALSE;
             }
         }
-#ifdef INTEL_XVMC
     }
-#endif
+
     return TRUE;
 }
 
@@ -2368,8 +2374,7 @@ i830_copy_video_data(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
     npixels = ((((x2 + 0xffff) >> 16) + 1) & ~1) - left;
 
     if (is_planar_fourcc(id)) {
-	if (id != FOURCC_XVMC
-		|| pPriv->rotation != RR_Rotate_0) {
+	if (!xvmc_passthrough(id, pPriv->rotation)) {
 	    top &= ~1;
 	    nlines = ((((y2 + 0xffff) >> 16) + 1) & ~1) - top;
 	    I830CopyPlanarData(pScrn, pPriv, buf, srcPitch, srcPitch2, *dstPitch,
@@ -2485,13 +2490,11 @@ I830PutImage(ScrnInfoPtr pScrn,
         }
 
         if (IS_I965G(pI830)) {
-#ifdef INTEL_XVMC
-            if (id == FOURCC_XVMC && pPriv->rotation == RR_Rotate_0) {
+            if (xvmc_passthrough(id, pPriv->rotation)) {
                 pPriv->YBufOffset = buf -  pI830->FbBase;
                 pPriv->UBufOffset = pPriv->YBufOffset + height*width;
                 pPriv->VBufOffset = pPriv->UBufOffset + height*width/4;
             }
-#endif
             I965DisplayVideoTextured(pScrn, pPriv, id, clipBoxes, width, height,
                                      dstPitch, x1, y1, x2, y2,
                                      src_w, src_h, drw_w, drw_h, pPixmap);
commit 71276dff9415322f75792a46c1a1cc0b900588b9
Author: Daniel Vetter <daniel.vetter at ffwll.ch>
Date:   Tue Aug 11 16:06:43 2009 +0200

    Xv: scrap overlay offscreen pixmap support
    
    The code looks like it's been bitrotting since being copied over
    from the i810 driver. Furthermore painting rgb pixmaps with the overlay
    engine is in these days of modern compositing X an absolute no-go. And
    textured video doesn't support it neither, so its likely never ever
    used by applications.
    
    Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/src/i830_video.c b/src/i830_video.c
index c8da46d..5e2db6c 100644
--- a/src/i830_video.c
+++ b/src/i830_video.c
@@ -86,8 +86,6 @@
 
 #define TIMER_MASK      (OFF_TIMER | FREE_TIMER)
 
-static void I830InitOffscreenImages(ScreenPtr);
-
 static XF86VideoAdaptorPtr I830SetupImageVideoOverlay(ScreenPtr);
 static XF86VideoAdaptorPtr I830SetupImageVideoTextured(ScreenPtr);
 static void I830StopVideo(ScrnInfoPtr, pointer, Bool);
@@ -608,7 +606,6 @@ I830InitVideo(ScreenPtr pScreen)
 	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 		       "Failed to set up overlay video\n");
 	}
-	I830InitOffscreenImages(pScreen);
     }
 
     if (overlayAdaptor && pI830->XvPreferOverlay)
@@ -2639,192 +2636,6 @@ I830VideoBlockHandler(int i, pointer blockData, pointer pTimeout,
     }
 }
 
-/***************************************************************************
- * Offscreen Images
- ***************************************************************************/
-
-typedef struct {
-    Bool isOn;
-} OffscreenPrivRec, *OffscreenPrivPtr;
-
-static int
-I830AllocateSurface(ScrnInfoPtr pScrn,
-		    int id,
-		    unsigned short w,
-		    unsigned short h, XF86SurfacePtr surface)
-{
-    int pitch, fbpitch, size;
-    OffscreenPrivPtr pPriv;
-    I830Ptr pI830 = I830PTR(pScrn);
-
-    OVERLAY_DEBUG("I830AllocateSurface\n");
-
-    if (IS_845G(pI830) || IS_I830(pI830)) {
-	if ((w > IMAGE_MAX_WIDTH_LEGACY) || (h > IMAGE_MAX_HEIGHT_LEGACY))
-	    return BadAlloc;
-    } else {
-	if ((w > IMAGE_MAX_WIDTH) || (h > IMAGE_MAX_HEIGHT))
-	    return BadAlloc;
-    }
-
-    if (!(surface->pitches = xalloc(sizeof(int))))
-	return BadAlloc;
-    if (!(surface->offsets = xalloc(sizeof(int)))) {
-	xfree(surface->pitches);
-	return BadAlloc;
-    }
-    if (!(pPriv = xalloc(sizeof(OffscreenPrivRec)))) {
-	xfree(surface->pitches);
-	xfree(surface->offsets);
-	return BadAlloc;
-    }
-
-    w = (w + 1) & ~1;
-    pitch = ((w << 1) + 15) & ~15;
-    fbpitch = pI830->cpp * pScrn->displayWidth;
-    size = pitch * h;
-
-    surface->width = w;
-    surface->height = h;
-
-    pPriv->isOn = FALSE;
-
-    surface->pScrn = pScrn;
-    surface->id = id;
-    surface->pitches[0] = pitch;
-    surface->offsets[0] = 0;
-    surface->devPrivate.ptr = (pointer) pPriv;
-
-    return Success;
-}
-
-static int
-I830StopSurface(XF86SurfacePtr surface)
-{
-    OffscreenPrivPtr pPriv = (OffscreenPrivPtr) surface->devPrivate.ptr;
-    ScrnInfoPtr pScrn = surface->pScrn;
-
-    if (pPriv->isOn) {
-	OVERLAY_DEBUG("StopSurface\n");
-
-	i830_overlay_off (pScrn);
-
-	pPriv->isOn = FALSE;
-    }
-
-    return Success;
-}
-
-static int
-I830FreeSurface(XF86SurfacePtr surface)
-{
-    I830StopSurface(surface);
-    xfree(surface->pitches);
-    xfree(surface->offsets);
-    xfree(surface->devPrivate.ptr);
-
-    return Success;
-}
-
-static int
-I830GetSurfaceAttribute(ScrnInfoPtr pScrn, Atom attribute, INT32 * value)
-{
-    return I830GetPortAttribute(pScrn, attribute, value, NULL);
-}
-
-static int
-I830SetSurfaceAttribute(ScrnInfoPtr pScrn, Atom attribute, INT32 value)
-{
-    return I830SetPortAttributeOverlay(pScrn, attribute, value, NULL);
-}
-
-static int
-I830DisplaySurface(XF86SurfacePtr surface,
-		   short src_x, short src_y,
-		   short drw_x, short drw_y,
-		   short src_w, short src_h,
-		   short drw_w, short drw_h, RegionPtr clipBoxes)
-{
-    OffscreenPrivPtr pPriv = (OffscreenPrivPtr) surface->devPrivate.ptr;
-    ScrnInfoPtr pScrn = surface->pScrn;
-    ScreenPtr pScreen = screenInfo.screens[pScrn->scrnIndex];
-    I830PortPrivPtr pI830Priv = GET_PORT_PRIVATE(pScrn);
-    INT32 x1, y1, x2, y2;
-    BoxRec dstBox;
-    xf86CrtcPtr crtc;
-
-    OVERLAY_DEBUG("I830DisplaySurface\n");
-
-    x1 = src_x;
-    x2 = src_x + src_w;
-    y1 = src_y;
-    y2 = src_y + src_h;
-
-    dstBox.x1 = drw_x;
-    dstBox.x2 = drw_x + drw_w;
-    dstBox.y1 = drw_y;
-    dstBox.y2 = drw_y + drw_h;
-
-    if (!i830_clip_video_helper (pScrn, pI830Priv, &crtc, &dstBox,
-				 &x1, &x2, &y1, &y2, clipBoxes,
-				 surface->width, surface->height))
-	return Success;
-
-    /* fixup pointers */
-    pI830Priv->YBufOffset = surface->offsets[0];
-
-    i830_display_overlay(pScrn, crtc, surface->id, surface->width, surface->height,
-		     surface->pitches[0], x1, y1, x2, y2, &dstBox,
-		     src_w, src_h, drw_w, drw_h);
-
-    i830_fill_colorkey (pScreen, pI830Priv->colorKey, clipBoxes);
-
-    pPriv->isOn = TRUE;
-    /* we've prempted the XvImage stream so set its free timer */
-    if (pI830Priv->videoStatus & CLIENT_VIDEO_ON) {
-	REGION_EMPTY(pScrn->pScreen, &pI830Priv->clip);
-	UpdateCurrentTime();
-	pI830Priv->videoStatus = FREE_TIMER;
-	pI830Priv->freeTime = currentTime.milliseconds + FREE_DELAY;
-    }
-
-    return Success;
-}
-
-static void
-I830InitOffscreenImages(ScreenPtr pScreen)
-{
-    XF86OffscreenImagePtr offscreenImages;
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    I830Ptr pI830 = I830PTR(pScrn);
-
-    if (!(offscreenImages = xalloc(sizeof(XF86OffscreenImageRec)))) {
-	return;
-    }
-
-    pI830->offscreenImages = offscreenImages;
-
-    offscreenImages[0].image = &Images[0];
-    offscreenImages[0].flags = VIDEO_OVERLAID_IMAGES /*| VIDEO_CLIP_TO_VIEWPORT*/;
-    offscreenImages[0].alloc_surface = I830AllocateSurface;
-    offscreenImages[0].free_surface = I830FreeSurface;
-    offscreenImages[0].display = I830DisplaySurface;
-    offscreenImages[0].stop = I830StopSurface;
-    offscreenImages[0].setAttribute = I830SetSurfaceAttribute;
-    offscreenImages[0].getAttribute = I830GetSurfaceAttribute;
-    if (IS_845G(pI830) || IS_I830(pI830)) {
-	offscreenImages[0].max_width = IMAGE_MAX_WIDTH_LEGACY;
-	offscreenImages[0].max_height = IMAGE_MAX_HEIGHT_LEGACY;
-    } else {
-	offscreenImages[0].max_width = IMAGE_MAX_WIDTH;
-	offscreenImages[0].max_height = IMAGE_MAX_HEIGHT; 
-    }
-    offscreenImages[0].num_attributes = 1;
-    offscreenImages[0].attributes = Attributes;
-
-    xf86XVRegisterOffscreenImages(pScreen, offscreenImages, 1);
-}
-
 void
 i830_crtc_dpms_video(xf86CrtcPtr crtc, Bool on)
 {
commit 99afdf985fa9f763fda4bc49ccd8111960a4ae0f
Author: Daniel Vetter <daniel.vetter at ffwll.ch>
Date:   Tue Aug 11 16:06:42 2009 +0200

    Xv: small cleanups in I830PutImage
    
    - scrap unused variable overlay
    - scrap an superflous if and attach the code to the preceeding else
    - tiny layout fix.
    
    Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/src/i830_video.c b/src/i830_video.c
index 8dfa2dd..c8da46d 100644
--- a/src/i830_video.c
+++ b/src/i830_video.c
@@ -2414,7 +2414,6 @@ I830PutImage(ScrnInfoPtr pScrn,
     I830Ptr pI830 = I830PTR(pScrn);
     I830PortPrivPtr pPriv = (I830PortPrivPtr) data;
     ScreenPtr pScreen = screenInfo.screens[pScrn->scrnIndex];
-    I830OverlayRegPtr overlay;
     PixmapPtr pPixmap = get_drawable_pixmap(pDraw);;
     INT32 x1, x2, y1, y2;
     int dstPitch;
@@ -2422,11 +2421,6 @@ I830PutImage(ScrnInfoPtr pScrn,
     BoxRec dstBox;
     xf86CrtcPtr	crtc;
 
-    if (pPriv->textured)
-	overlay = NULL;
-    else
-	overlay = I830OVERLAYREG(pI830);
-
 #if 0
     ErrorF("I830PutImage: src: (%d,%d)(%d,%d), dst: (%d,%d)(%d,%d)\n"
 	   "width %d, height %d\n", src_x, src_y, src_w, src_h, drw_x, drw_y,
@@ -2462,7 +2456,7 @@ I830PutImage(ScrnInfoPtr pScrn,
 				width, height))
 	return Success;
 
-     if (!pPriv->textured) {
+    if (!pPriv->textured) {
 	 /* texture video handles rotation differently. */
 	if (crtc)
 	    pPriv->rotation = crtc->rotation;
@@ -2471,14 +2465,13 @@ I830PutImage(ScrnInfoPtr pScrn,
 		    "Fail to clip video to any crtc!\n");
 	    return Success;
 	}
-     }
+    }
 
     if (!i830_copy_video_data(pScrn, pPriv, width, height,
 		&dstPitch, &dstPitch2,
 		x1, y1, x2, y2, id, buf))
 	return BadAlloc;
 
-
     if (!pPriv->textured) {
 	i830_display_overlay(pScrn, crtc, id, width, height, dstPitch,
 			   x1, y1, x2, y2, &dstBox, src_w, src_h,
@@ -2510,8 +2503,7 @@ I830PutImage(ScrnInfoPtr pScrn,
                                      dstPitch, dstPitch2, x1, y1, x2, y2,
                                      src_w, src_h, drw_w, drw_h, pPixmap);
         }
-    }
-    if (pPriv->textured) {
+
 	DamageDamageRegion(pDraw, clipBoxes);
     }
 
commit d598456f1fe013c250530730c57ad720d38cde3a
Author: Daniel Vetter <daniel.vetter at ffwll.ch>
Date:   Tue Aug 11 16:06:41 2009 +0200

    Xv I830PutImage splitup: extract i830_wait_for scanline
    
    Also scrap the unecessary variable sync in I830PutImage and the
    accompanying obfuscated logic.
    
    Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/src/i830_video.c b/src/i830_video.c
index 97b05db..8dfa2dd 100644
--- a/src/i830_video.c
+++ b/src/i830_video.c
@@ -2157,6 +2157,44 @@ i830_fill_colorkey (ScreenPtr pScreen, uint32_t key, RegionPtr clipboxes)
    FreeScratchGC (gc);
 }
 
+static void
+i830_wait_for_scanline(ScrnInfoPtr pScrn, PixmapPtr pPixmap,
+	xf86CrtcPtr crtc, RegionPtr clipBoxes)
+{
+    I830Ptr pI830 = I830PTR(pScrn);
+    BoxPtr box;
+    pixman_box16_t box_in_crtc_coordinates;
+    int pipe = -1, event, load_scan_lines_pipe;
+
+    if (pixmap_is_scanout(pPixmap))
+	pipe = i830_crtc_to_pipe(crtc);
+
+    if (pipe >= 0) {
+	if (pipe == 0) {
+	    event = MI_WAIT_FOR_PIPEA_SCAN_LINE_WINDOW;
+	    load_scan_lines_pipe = MI_LOAD_SCAN_LINES_DISPLAY_PIPEA;
+	} else {
+	    event = MI_WAIT_FOR_PIPEB_SCAN_LINE_WINDOW;
+	    load_scan_lines_pipe = MI_LOAD_SCAN_LINES_DISPLAY_PIPEB;
+	}
+
+	box = REGION_EXTENTS(unused, clipBoxes);
+	box_in_crtc_coordinates = *box;
+	if (crtc->transform_in_use)
+	    pixman_f_transform_bounds (&crtc->f_framebuffer_to_crtc, &box_in_crtc_coordinates);
+
+	BEGIN_BATCH(5);
+	/* The documentation says that the LOAD_SCAN_LINES command
+	 * always comes in pairs. Don't ask me why. */
+	OUT_BATCH(MI_LOAD_SCAN_LINES_INCL | load_scan_lines_pipe);
+	OUT_BATCH((box_in_crtc_coordinates.y1 << 16) | box_in_crtc_coordinates.y2);
+	OUT_BATCH(MI_LOAD_SCAN_LINES_INCL | load_scan_lines_pipe);
+	OUT_BATCH((box_in_crtc_coordinates.y1 << 16) | box_in_crtc_coordinates.y2);
+	OUT_BATCH(MI_WAIT_FOR_EVENT | event);
+	ADVANCE_BATCH();
+    }
+}
+
 static Bool
 i830_setup_video_buffer(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
 	int alloc_size, int id)
@@ -2452,46 +2490,8 @@ I830PutImage(ScrnInfoPtr pScrn,
 	    i830_fill_colorkey (pScreen, pPriv->colorKey, clipBoxes);
 	}
     } else {
-        Bool sync = TRUE;
-        
-        if (crtc == NULL) {
-            sync = FALSE;
-        } else if (pPriv->SyncToVblank == 0) {
-            sync = FALSE;
-        }
-
-        if (sync) {
-	    BoxPtr box;
-	    pixman_box16_t box_in_crtc_coordinates;
-	    int pipe = -1, event, load_scan_lines_pipe;
-
-	    if (pixmap_is_scanout(pPixmap))
-		pipe = i830_crtc_to_pipe(crtc);
-
-	    if (pipe >= 0) {
-		if (pipe == 0) {
-		    event = MI_WAIT_FOR_PIPEA_SCAN_LINE_WINDOW;
-		    load_scan_lines_pipe = MI_LOAD_SCAN_LINES_DISPLAY_PIPEA;
-		} else {
-		    event = MI_WAIT_FOR_PIPEB_SCAN_LINE_WINDOW;
-		    load_scan_lines_pipe = MI_LOAD_SCAN_LINES_DISPLAY_PIPEB;
-		}
-
-		box = REGION_EXTENTS(unused, clipBoxes);
-		box_in_crtc_coordinates = *box;
-		if (crtc->transform_in_use)
-		    pixman_f_transform_bounds (&crtc->f_framebuffer_to_crtc, &box_in_crtc_coordinates);
-
-		BEGIN_BATCH(5);
-		/* The documentation says that the LOAD_SCAN_LINES command
-		 * always comes in pairs. Don't ask me why. */
-		OUT_BATCH(MI_LOAD_SCAN_LINES_INCL | load_scan_lines_pipe);
-		OUT_BATCH((box_in_crtc_coordinates.y1 << 16) | box_in_crtc_coordinates.y2);
-		OUT_BATCH(MI_LOAD_SCAN_LINES_INCL | load_scan_lines_pipe);
-		OUT_BATCH((box_in_crtc_coordinates.y1 << 16) | box_in_crtc_coordinates.y2);
-		OUT_BATCH(MI_WAIT_FOR_EVENT | event);
-		ADVANCE_BATCH();
-	    }
+        if (crtc && pPriv->SyncToVblank != 0) {
+	    i830_wait_for_scanline(pScrn, pPixmap, crtc, clipBoxes);
         }
 
         if (IS_I965G(pI830)) {
commit 2ba03fa78197d1cb10d6401ad02cfe9edd2623b3
Author: Daniel Vetter <daniel.vetter at ffwll.ch>
Date:   Tue Aug 11 16:06:40 2009 +0200

    Xv I830PutImage splitup: extract i830_copy_video_data
    
    Just moves the code and passes back allocation failures.
    
    Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/src/i830_video.c b/src/i830_video.c
index 8ecd388..97b05db 100644
--- a/src/i830_video.c
+++ b/src/i830_video.c
@@ -2265,6 +2265,90 @@ i830_dst_pitch_and_size(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv, short width,
 #endif
 }
 
+static Bool
+i830_copy_video_data(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
+	     short width, short height, int *dstPitch, int *dstPitch2,
+	     INT32 x1, INT32 y1, INT32 x2, INT32 y2,
+	     int id, unsigned char *buf)
+{
+    I830Ptr pI830 = I830PTR(pScrn);
+    int srcPitch = 0, srcPitch2 = 0;
+    int top, left, npixels, nlines, size;
+    int alloc_size;
+
+    if (is_planar_fourcc(id)) {
+	srcPitch = (width + 0x3) & ~0x3;
+	srcPitch2 = ((width >> 1) + 0x3) & ~0x3;
+    } else {
+	srcPitch = width << 1;
+    }
+
+    i830_dst_pitch_and_size(pScrn, pPriv, width, height, dstPitch, dstPitch2,
+	    &size, id);
+
+    alloc_size = size;
+    if (pPriv->doubleBuffer)
+	alloc_size *= 2;
+
+    if (!i830_setup_video_buffer(pScrn, pPriv, alloc_size, id))
+	return FALSE;
+
+    /* fixup pointers */
+#ifdef INTEL_XVMC
+    if (id == FOURCC_XVMC && IS_I915(pI830)) {
+	pPriv->YBufOffset = (uint32_t)((uintptr_t)buf);
+	pPriv->VBufOffset = pPriv->YBufOffset + (*dstPitch2 * height);
+	pPriv->UBufOffset = pPriv->VBufOffset + (*dstPitch * height / 2);
+    } else {
+#endif
+	if (pPriv->textured)
+	    pPriv->YBufOffset = 0;
+	else
+	    pPriv->YBufOffset = pPriv->buf->offset;
+
+	/* switch buffers if double buffered */
+	if (!pPriv->textured && pPriv->doubleBuffer) {
+	    if (pPriv->currentBuf == 0)
+		pPriv->currentBuf = 1;
+	    else
+		pPriv->currentBuf = 0;
+
+	    pPriv->YBufOffset += size*pPriv->currentBuf;
+	}
+
+	if (pPriv->rotation & (RR_Rotate_90 | RR_Rotate_270)) {
+	    pPriv->UBufOffset = pPriv->YBufOffset + (*dstPitch * 2 * width);
+	    pPriv->VBufOffset = pPriv->UBufOffset + (*dstPitch * width / 2);
+	} else {
+	    pPriv->UBufOffset = pPriv->YBufOffset + (*dstPitch * 2 * height);
+	    pPriv->VBufOffset = pPriv->UBufOffset + (*dstPitch * height / 2);
+	}
+#ifdef INTEL_XVMC
+    }
+#endif
+
+    /* copy data */
+    top = y1 >> 16;
+    left = (x1 >> 16) & ~1;
+    npixels = ((((x2 + 0xffff) >> 16) + 1) & ~1) - left;
+
+    if (is_planar_fourcc(id)) {
+	if (id != FOURCC_XVMC
+		|| pPriv->rotation != RR_Rotate_0) {
+	    top &= ~1;
+	    nlines = ((((y2 + 0xffff) >> 16) + 1) & ~1) - top;
+	    I830CopyPlanarData(pScrn, pPriv, buf, srcPitch, srcPitch2, *dstPitch,
+		    height, top, left, nlines, npixels, id);
+	}
+    } else {
+	nlines = ((y2 + 0xffff) >> 16) - top;
+	I830CopyPackedData(pScrn, pPriv, buf, srcPitch, *dstPitch, top, left,
+			   nlines, npixels);
+    }
+
+    return TRUE;
+}
+
 /*
  * The source rectangle of the video is defined by (src_x, src_y, src_w, src_h).
  * The dest rectangle of the video is defined by (drw_x, drw_y, drw_w, drw_h).
@@ -2295,11 +2379,9 @@ I830PutImage(ScrnInfoPtr pScrn,
     I830OverlayRegPtr overlay;
     PixmapPtr pPixmap = get_drawable_pixmap(pDraw);;
     INT32 x1, x2, y1, y2;
-    int srcPitch = 0, srcPitch2 = 0, dstPitch;
+    int dstPitch;
     int dstPitch2 = 0;
-    int top, left, npixels, nlines, size;
     BoxRec dstBox;
-    int alloc_size;
     xf86CrtcPtr	crtc;
 
     if (pPriv->textured)
@@ -2353,75 +2435,11 @@ I830PutImage(ScrnInfoPtr pScrn,
 	}
      }
 
-    if (is_planar_fourcc(id)) {
-	srcPitch = (width + 0x3) & ~0x3;
-	srcPitch2 = ((width >> 1) + 0x3) & ~0x3;
-    } else {
-	srcPitch = width << 1;
-    }
-
-    i830_dst_pitch_and_size(pScrn, pPriv, width, height, &dstPitch, &dstPitch2,
-	    &size, id);
-
-    alloc_size = size;
-    if (pPriv->doubleBuffer)
-	alloc_size *= 2;
-
-    if (!i830_setup_video_buffer(pScrn, pPriv, alloc_size, id))
+    if (!i830_copy_video_data(pScrn, pPriv, width, height,
+		&dstPitch, &dstPitch2,
+		x1, y1, x2, y2, id, buf))
 	return BadAlloc;
 
-    /* fixup pointers */
-#ifdef INTEL_XVMC
-    if (id == FOURCC_XVMC && IS_I915(pI830)) {
-	pPriv->YBufOffset = (uint32_t)((uintptr_t)buf);
-	pPriv->VBufOffset = pPriv->YBufOffset + (dstPitch2 * height);
-	pPriv->UBufOffset = pPriv->VBufOffset + (dstPitch * height / 2);
-    } else {
-#endif
-	if (pPriv->textured)
-	    pPriv->YBufOffset = 0;
-	else
-	    pPriv->YBufOffset = pPriv->buf->offset;
-
-	/* switch buffers if double buffered */
-	if (!pPriv->textured && pPriv->doubleBuffer) {
-	    if (pPriv->currentBuf == 0)
-		pPriv->currentBuf = 1;
-	    else
-		pPriv->currentBuf = 0;
-
-	    pPriv->YBufOffset += size*pPriv->currentBuf;
-	}
-
-	if (pPriv->rotation & (RR_Rotate_90 | RR_Rotate_270)) {
-	    pPriv->UBufOffset = pPriv->YBufOffset + (dstPitch * 2 * width);
-	    pPriv->VBufOffset = pPriv->UBufOffset + (dstPitch * width / 2);
-	} else {
-	    pPriv->UBufOffset = pPriv->YBufOffset + (dstPitch * 2 * height);
-	    pPriv->VBufOffset = pPriv->UBufOffset + (dstPitch * height / 2);
-	}
-#ifdef INTEL_XVMC
-    }
-#endif
-
-    /* copy data */
-    top = y1 >> 16;
-    left = (x1 >> 16) & ~1;
-    npixels = ((((x2 + 0xffff) >> 16) + 1) & ~1) - left;
-
-    if (is_planar_fourcc(id)) {
-	if (id != FOURCC_XVMC
-		|| pPriv->rotation != RR_Rotate_0) {
-	    top &= ~1;
-	    nlines = ((((y2 + 0xffff) >> 16) + 1) & ~1) - top;
-	    I830CopyPlanarData(pScrn, pPriv, buf, srcPitch, srcPitch2, dstPitch,
-		    height, top, left, nlines, npixels, id);
-	}
-    } else {
-	nlines = ((y2 + 0xffff) >> 16) - top;
-	I830CopyPackedData(pScrn, pPriv, buf, srcPitch, dstPitch, top, left,
-			   nlines, npixels);
-    }
 
     if (!pPriv->textured) {
 	i830_display_overlay(pScrn, crtc, id, width, height, dstPitch,
commit 81fc74cc4ce81b9be8b9ba3bcacf1284c47ce80c
Author: Daniel Vetter <daniel.vetter at ffwll.ch>
Date:   Tue Aug 11 16:06:39 2009 +0200

    Xv I830PutImage splitup: extract i830_setup_video_buffer
    
    Just move the code and pass back allocation failures.
    
    Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/src/i830_video.c b/src/i830_video.c
index e72eda6..8ecd388 100644
--- a/src/i830_video.c
+++ b/src/i830_video.c
@@ -2157,6 +2157,48 @@ i830_fill_colorkey (ScreenPtr pScreen, uint32_t key, RegionPtr clipboxes)
    FreeScratchGC (gc);
 }
 
+static Bool
+i830_setup_video_buffer(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
+	int alloc_size, int id)
+{
+    I830Ptr pI830 = I830PTR(pScrn);
+    /* Free the current buffer if we're going to have to reallocate */
+    if (pPriv->buf && pPriv->buf->size < alloc_size) {
+	if (!pPriv->textured)
+	    drm_intel_bo_unpin(pPriv->buf);
+	drm_intel_bo_unreference(pPriv->buf);
+	pPriv->buf = NULL;
+    }
+
+#ifdef INTEL_XVMC
+    if (id == FOURCC_XVMC &&
+        pPriv->rotation == RR_Rotate_0) {
+        if (pPriv->buf) {
+            assert(pPriv->textured);
+            drm_intel_bo_unreference(pPriv->buf);
+            pPriv->buf = NULL;
+        }
+    } else {
+#endif
+        if (pPriv->buf == NULL) {
+            pPriv->buf = drm_intel_bo_alloc(pI830->bufmgr,
+                                         "xv buffer", alloc_size, 4096);
+            if (pPriv->buf == NULL)
+                return FALSE;
+            if (!pPriv->textured && drm_intel_bo_pin(pPriv->buf, 4096) != 0) {
+                drm_intel_bo_unreference(pPriv->buf);
+                pPriv->buf = NULL;
+                xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+                           "Failed to pin xv buffer\n");
+                return FALSE;
+            }
+        }
+#ifdef INTEL_XVMC
+    }
+#endif
+    return TRUE;
+}
+
 static void
 i830_dst_pitch_and_size(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv, short width,
 	short height, int *dstPitch, int *dstPitch2, int *size, int id)
@@ -2325,40 +2367,8 @@ I830PutImage(ScrnInfoPtr pScrn,
     if (pPriv->doubleBuffer)
 	alloc_size *= 2;
 
-    /* Free the current buffer if we're going to have to reallocate */
-    if (pPriv->buf && pPriv->buf->size < alloc_size) {
-	if (!pPriv->textured)
-	    drm_intel_bo_unpin(pPriv->buf);
-	drm_intel_bo_unreference(pPriv->buf);
-	pPriv->buf = NULL;
-    }
-
-#ifdef INTEL_XVMC
-    if (id == FOURCC_XVMC && 
-        pPriv->rotation == RR_Rotate_0) {
-        if (pPriv->buf) {
-            assert(pPriv->textured);
-            drm_intel_bo_unreference(pPriv->buf);
-            pPriv->buf = NULL;
-        }
-    } else {
-#endif
-        if (pPriv->buf == NULL) {
-            pPriv->buf = drm_intel_bo_alloc(pI830->bufmgr,
-                                         "xv buffer", alloc_size, 4096);
-            if (pPriv->buf == NULL)
-                return BadAlloc;
-            if (!pPriv->textured && drm_intel_bo_pin(pPriv->buf, 4096) != 0) {
-                drm_intel_bo_unreference(pPriv->buf);
-                pPriv->buf = NULL;
-                xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-                           "Failed to pin xv buffer\n");
-                return BadAlloc;
-            }
-        }
-#ifdef INTEL_XVMC
-    }
-#endif
+    if (!i830_setup_video_buffer(pScrn, pPriv, alloc_size, id))
+	return BadAlloc;
 
     /* fixup pointers */
 #ifdef INTEL_XVMC
commit 0bf4cc5130482ee0f3924f34e37fa5fc988119b3
Author: Daniel Vetter <daniel.vetter at ffwll.ch>
Date:   Tue Aug 11 16:06:38 2009 +0200

    Xv I830PutImage splitup: extract i830_dst_pitch_and_size
    
    Just moves the code.
    
    Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/src/i830_video.c b/src/i830_video.c
index 22d729f..e72eda6 100644
--- a/src/i830_video.c
+++ b/src/i830_video.c
@@ -2157,6 +2157,72 @@ i830_fill_colorkey (ScreenPtr pScreen, uint32_t key, RegionPtr clipboxes)
    FreeScratchGC (gc);
 }
 
+static void
+i830_dst_pitch_and_size(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv, short width,
+	short height, int *dstPitch, int *dstPitch2, int *size, int id)
+{
+    I830Ptr pI830 = I830PTR(pScrn);
+    int pitchAlignMask;
+
+    /* Only needs to be DWORD-aligned for textured on i915, but overlay has
+     * stricter requirements.
+     */
+    if (pPriv->textured) {
+	pitchAlignMask = 3;
+#ifdef INTEL_XVMC
+	/* for i915 xvmc, hw requires at least 1kb aligned surface */
+	if ((id == FOURCC_XVMC) && IS_I915(pI830))
+	    pitchAlignMask = 0x3ff;
+#endif
+    } else {
+	if (IS_I965G(pI830))
+	    pitchAlignMask = 255;
+	else
+	    pitchAlignMask = 63;
+    }
+
+    /* Determine the desired destination pitch (representing the chroma's pitch,
+     * in the planar case.
+     */
+    switch (id) {
+    case FOURCC_YV12:
+    case FOURCC_I420:
+	if (pPriv->rotation & (RR_Rotate_90 | RR_Rotate_270)) {
+	    *dstPitch = ((height / 2) + pitchAlignMask) & ~pitchAlignMask;
+	    *size = *dstPitch * width * 3;
+	} else {
+	    *dstPitch = ((width / 2) + pitchAlignMask) & ~pitchAlignMask;
+	    *size = *dstPitch * height * 3;
+	}
+	break;
+    case FOURCC_UYVY:
+    case FOURCC_YUY2:
+
+	if (pPriv->rotation & (RR_Rotate_90 | RR_Rotate_270)) {
+	    *dstPitch = ((height << 1) + pitchAlignMask) & ~pitchAlignMask;
+	    *size = *dstPitch * width;
+	} else {
+	    *dstPitch = ((width << 1) + pitchAlignMask) & ~pitchAlignMask;
+	    *size = *dstPitch * height;
+	}
+	break;
+#ifdef INTEL_XVMC
+    case FOURCC_XVMC:
+	*dstPitch = ((width / 2) + pitchAlignMask ) & ~pitchAlignMask;
+	*dstPitch2 = (width + pitchAlignMask ) & ~pitchAlignMask;
+	*size = 0;
+	break;
+#endif
+    default:
+	*dstPitch = 0;
+	*size = 0;
+	break;
+    }
+#if 0
+    ErrorF("srcPitch: %d, dstPitch: %d, size: %d\n", srcPitch, *dstPitch, size);
+#endif
+}
+
 /*
  * The source rectangle of the video is defined by (src_x, src_y, src_w, src_h).
  * The dest rectangle of the video is defined by (drw_x, drw_y, drw_w, drw_h).
@@ -2191,7 +2257,6 @@ I830PutImage(ScrnInfoPtr pScrn,
     int dstPitch2 = 0;
     int top, left, npixels, nlines, size;
     BoxRec dstBox;
-    int pitchAlignMask;
     int alloc_size;
     xf86CrtcPtr	crtc;
 
@@ -2253,63 +2318,8 @@ I830PutImage(ScrnInfoPtr pScrn,
 	srcPitch = width << 1;
     }
 
-    /* Only needs to be DWORD-aligned for textured on i915, but overlay has
-     * stricter requirements.
-     */
-    if (pPriv->textured) {
-	pitchAlignMask = 3;
-#ifdef INTEL_XVMC
-	/* for i915 xvmc, hw requires at least 1kb aligned surface */
-	if ((id == FOURCC_XVMC) && IS_I915(pI830))
-	    pitchAlignMask = 0x3ff;
-#endif
-    } else {
-	if (IS_I965G(pI830))
-	    pitchAlignMask = 255;
-	else
-	    pitchAlignMask = 63;
-    }
-
-    /* Determine the desired destination pitch (representing the chroma's pitch,
-     * in the planar case.
-     */
-    switch (id) {
-    case FOURCC_YV12:
-    case FOURCC_I420:
-	if (pPriv->rotation & (RR_Rotate_90 | RR_Rotate_270)) {
-	    dstPitch = ((height / 2) + pitchAlignMask) & ~pitchAlignMask;
-	    size = dstPitch * width * 3;
-	} else {
-	    dstPitch = ((width / 2) + pitchAlignMask) & ~pitchAlignMask;
-	    size = dstPitch * height * 3;
-	}
-	break;
-    case FOURCC_UYVY:
-    case FOURCC_YUY2:
-
-	if (pPriv->rotation & (RR_Rotate_90 | RR_Rotate_270)) {
-	    dstPitch = ((height << 1) + pitchAlignMask) & ~pitchAlignMask;
-	    size = dstPitch * width;
-	} else {
-	    dstPitch = ((width << 1) + pitchAlignMask) & ~pitchAlignMask;
-	    size = dstPitch * height;
-	}
-	break;
-#ifdef INTEL_XVMC
-    case FOURCC_XVMC:
-	dstPitch = ((width / 2) + pitchAlignMask ) & ~pitchAlignMask;
-	dstPitch2 = (width + pitchAlignMask ) & ~pitchAlignMask;
-	size = 0;
-	break;
-#endif
-    default:
-	dstPitch = 0;
-	size = 0;
-	break;
-    }
-#if 0
-    ErrorF("srcPitch: %d, dstPitch: %d, size: %d\n", srcPitch, dstPitch, size);
-#endif
+    i830_dst_pitch_and_size(pScrn, pPriv, width, height, &dstPitch, &dstPitch2,
+	    &size, id);
 
     alloc_size = size;
     if (pPriv->doubleBuffer)
commit c20ef591931b5efc5745d00c06f296c89cf32745
Author: Daniel Vetter <daniel.vetter at ffwll.ch>
Date:   Tue Aug 11 16:06:37 2009 +0200

    Xv: kill destId in I830PutImage
    
    It's only used to remember that XvMC has ỲV12 as output. is_planar_fourcc
    already takes care of that in all necessary cases.
    
    Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/src/i830_video.c b/src/i830_video.c
index c5ad05e..22d729f 100644
--- a/src/i830_video.c
+++ b/src/i830_video.c
@@ -2187,7 +2187,7 @@ I830PutImage(ScrnInfoPtr pScrn,
     I830OverlayRegPtr overlay;
     PixmapPtr pPixmap = get_drawable_pixmap(pDraw);;
     INT32 x1, x2, y1, y2;
-    int srcPitch = 0, srcPitch2 = 0, dstPitch, destId;
+    int srcPitch = 0, srcPitch2 = 0, dstPitch;
     int dstPitch2 = 0;
     int top, left, npixels, nlines, size;
     BoxRec dstBox;
@@ -2246,7 +2246,6 @@ I830PutImage(ScrnInfoPtr pScrn,
 	}
      }
 
-    destId = id;
     if (is_planar_fourcc(id)) {
 	srcPitch = (width + 0x3) & ~0x3;
 	srcPitch2 = ((width >> 1) + 0x3) & ~0x3;
@@ -2274,7 +2273,7 @@ I830PutImage(ScrnInfoPtr pScrn,
     /* Determine the desired destination pitch (representing the chroma's pitch,
      * in the planar case.
      */
-    switch (destId) {
+    switch (id) {
     case FOURCC_YV12:
     case FOURCC_I420:
 	if (pPriv->rotation & (RR_Rotate_90 | RR_Rotate_270)) {
@@ -2357,7 +2356,6 @@ I830PutImage(ScrnInfoPtr pScrn,
 	pPriv->YBufOffset = (uint32_t)((uintptr_t)buf);
 	pPriv->VBufOffset = pPriv->YBufOffset + (dstPitch2 * height);
 	pPriv->UBufOffset = pPriv->VBufOffset + (dstPitch * height / 2);
-	destId = FOURCC_YV12;
     } else {
 #endif
 	if (pPriv->textured)
@@ -2406,7 +2404,7 @@ I830PutImage(ScrnInfoPtr pScrn,
     }
 
     if (!pPriv->textured) {
-	i830_display_overlay(pScrn, crtc, destId, width, height, dstPitch,
+	i830_display_overlay(pScrn, crtc, id, width, height, dstPitch,
 			   x1, y1, x2, y2, &dstBox, src_w, src_h,
 			   drw_w, drw_h);
 	
@@ -2466,11 +2464,11 @@ I830PutImage(ScrnInfoPtr pScrn,
                 pPriv->VBufOffset = pPriv->UBufOffset + height*width/4;
             }
 #endif
-            I965DisplayVideoTextured(pScrn, pPriv, destId, clipBoxes, width, height,
+            I965DisplayVideoTextured(pScrn, pPriv, id, clipBoxes, width, height,
                                      dstPitch, x1, y1, x2, y2,
                                      src_w, src_h, drw_w, drw_h, pPixmap);
         } else {
-            I915DisplayVideoTextured(pScrn, pPriv, destId, clipBoxes, width, height,
+            I915DisplayVideoTextured(pScrn, pPriv, id, clipBoxes, width, height,
                                      dstPitch, dstPitch2, x1, y1, x2, y2,
                                      src_w, src_h, drw_w, drw_h, pPixmap);
         }
commit 5ce944994d57176d0ddf6f6d7c7779fdfcf39cb8
Author: Daniel Vetter <daniel.vetter at ffwll.ch>
Date:   Tue Aug 11 16:06:36 2009 +0200

    Xv: kill hw double buffering logic
    
    The idea for the hw double buffering support is to program two fixed
    buffers and then only switch buffers in the OCMD register. But the driver
    as-is always programs the new buffer address (in both register sets
    when double buffered). Therefore we gain nothing by using this hw
    capability. Scrap the software support for it.
    
    When double buffered, we now allocate just a buffer of size 2*size and
    switch between the two parts purely in software.
    
    To make reviewing this easier, I'll shortly explain the differences of how
    double-buffering (i.e. tear-free video) is achieved before and after this
    change:
    
    - When double buffer, allocate a buffer twice the size (unchanged).
    - Depending upon the currently shown buffer-half, copy the new frame into
      the other buffer-half. In the old code this is done by using the right
      set of buffer offsets, either *Buf0Offset or *Buf1Offset. The new code
      simply programs the offset for the right buffer-half into the single set
      of offsets. The end-result is unchanged.
    
    Now the big difference in hw-programming:
    
    Old: Programm new buffer offset into both sets of _hw_ buffer offset
    registers. Depending upon the current _sw_ buffer, select the _hw_ buffer
    and program this into the OCMD register. This just complicates matters
    unnecessarly.
    
    New: Just always use the hw buffer 0.
    
    And then it's again the same story in both old and new code:
    
    - Execute an overlay flip (MI_OVERLAY_FLIP) to read in the contents of the
      hw registers into the shadow hw registers (which are actually being used
      by the overlay, not the ones we write stuff into). This is synchronized
      with the respective crtc vblank by the hw.
    
    Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/src/i830_video.c b/src/i830_video.c
index afe02cb..c5ad05e 100644
--- a/src/i830_video.c
+++ b/src/i830_video.c
@@ -1268,10 +1268,7 @@ I830CopyPackedData(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
 	dst_base = pI830->FbBase;
     }
 
-    if (pPriv->currentBuf == 0)
-	dst = dst_base + pPriv->YBuf0offset;
-    else
-	dst = dst_base + pPriv->YBuf1offset;
+    dst = dst_base + pPriv->YBufOffset;
 
     switch (pPriv->rotation) {
     case RR_Rotate_0:
@@ -1430,10 +1427,7 @@ I830CopyPlanarData(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
 	dst_base = pI830->FbBase;
     }
 
-    if (pPriv->currentBuf == 0)
-	dst1 = dst_base + pPriv->YBuf0offset;
-    else
-	dst1 = dst_base + pPriv->YBuf1offset;
+    dst1 = dst_base + pPriv->YBufOffset;
 
     i830_memcpy_plane(dst1, src1, h, w, dstPitch2, srcPitch, pPriv->rotation);
 
@@ -1447,17 +1441,10 @@ I830CopyPlanarData(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
     ErrorF("src2 is %p, offset is %ld\n", src2,
 	   (unsigned long)src2 - (unsigned long)buf);
 #endif
-    if (pPriv->currentBuf == 0) {
-	if (id == FOURCC_I420)
-	    dst2 = dst_base + pPriv->UBuf0offset;
-	else
-	    dst2 = dst_base + pPriv->VBuf0offset;
-    } else {
-	if (id == FOURCC_I420)
-	    dst2 = dst_base + pPriv->UBuf1offset;
-	else
-	    dst2 = dst_base + pPriv->VBuf1offset;
-    }
+    if (id == FOURCC_I420)
+	dst2 = dst_base + pPriv->UBufOffset;
+    else
+	dst2 = dst_base + pPriv->VBufOffset;
 
     i830_memcpy_plane(dst2, src2, h/2, w/2,
 		    dstPitch, srcPitch2, pPriv->rotation);
@@ -1472,17 +1459,10 @@ I830CopyPlanarData(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
     ErrorF("src3 is %p, offset is %ld\n", src3,
 	   (unsigned long)src3 - (unsigned long)buf);
 #endif
-    if (pPriv->currentBuf == 0) {
-	if (id == FOURCC_I420)
-	    dst3 = dst_base + pPriv->VBuf0offset;
-	else
-	    dst3 = dst_base + pPriv->UBuf0offset;
-    } else {
-	if (id == FOURCC_I420)
-	    dst3 = dst_base + pPriv->VBuf1offset;
-	else
-	    dst3 = dst_base + pPriv->UBuf1offset;
-    }
+    if (id == FOURCC_I420)
+	dst3 = dst_base + pPriv->VBufOffset;
+    else
+	dst3 = dst_base + pPriv->UBufOffset;
 
     i830_memcpy_plane(dst3, src3, h/2, w/2,
 		    dstPitch, srcPitch2, pPriv->rotation);
@@ -1729,13 +1709,8 @@ i830_calc_src_regs(I830Ptr pI830, int planar, short width, short height,
 	mask = 0x1f;
     }
 
-    if (pPriv->currentBuf == 0) {
-	offsety = pPriv->YBuf0offset;
-	offsetu = pPriv->UBuf0offset;
-    } else {
-	offsety = pPriv->YBuf1offset;
-	offsetu = pPriv->UBuf1offset;
-    }
+    offsety = pPriv->YBufOffset;
+    offsetu = pPriv->UBufOffset;
 
     if (planar) {
 	*swidth_out = width | ((width/2 & 0x7ff) << 16);
@@ -1822,7 +1797,7 @@ i830_store_coeffs_in_overlay_regs(uint16_t *reg_coeffs, coeffPtr new_coeffs,
 }
 
 static uint32_t
-i830_overlay_cmd(int id, int planar, unsigned char currentBuf)
+i830_overlay_cmd(int id, int planar)
 {
     uint32_t OCMD = OVERLAY_ENABLE;
 
@@ -1841,10 +1816,7 @@ i830_overlay_cmd(int id, int planar, unsigned char currentBuf)
     }
 
     OCMD &= ~(BUFFER_SELECT | FIELD_SELECT);
-    if (currentBuf == 0)
-	OCMD |= BUFFER0;
-    else
-	OCMD |= BUFFER1;
+    OCMD |= BUFFER0;
 
     OVERLAY_DEBUG("OCMD is 0x%x\n", OCMD);
 
@@ -2077,14 +2049,9 @@ i830_display_overlay(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
 		  dstBox->x1, dstBox->y1, dstBox->x2, dstBox->y2);
 
     /* buffer locations */
-    overlay->OBUF_0Y = pPriv->YBuf0offset;
-    overlay->OBUF_0U = pPriv->UBuf0offset;
-    overlay->OBUF_0V = pPriv->VBuf0offset;
-    if(pPriv->doubleBuffer) {
-	overlay->OBUF_1Y = pPriv->YBuf1offset;
-	overlay->OBUF_1U = pPriv->UBuf1offset;
-	overlay->OBUF_1V = pPriv->VBuf1offset;
-    }
+    overlay->OBUF_0Y = pPriv->YBufOffset;
+    overlay->OBUF_0U = pPriv->UBufOffset;
+    overlay->OBUF_0V = pPriv->VBufOffset;
 
     OVERLAY_DEBUG("pos: 0x%x, size: 0x%x\n",
 		  overlay->DWINPOS, overlay->DWINSZ);
@@ -2104,7 +2071,7 @@ i830_display_overlay(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
     } else
 	overlay->OSTRIDE = dstPitch;
 
-    overlay->OCMD = i830_overlay_cmd(id, planar, pPriv->currentBuf);
+    overlay->OCMD = i830_overlay_cmd(id, planar);
 
     /* make sure the overlay is on */
     i830_overlay_on (pScrn);
@@ -2387,42 +2354,38 @@ I830PutImage(ScrnInfoPtr pScrn,
     /* fixup pointers */
 #ifdef INTEL_XVMC
     if (id == FOURCC_XVMC && IS_I915(pI830)) {
-	pPriv->YBuf0offset = (uint32_t)((uintptr_t)buf);
-	pPriv->VBuf0offset = pPriv->YBuf0offset + (dstPitch2 * height);
-	pPriv->UBuf0offset = pPriv->VBuf0offset + (dstPitch * height / 2);
+	pPriv->YBufOffset = (uint32_t)((uintptr_t)buf);
+	pPriv->VBufOffset = pPriv->YBufOffset + (dstPitch2 * height);
+	pPriv->UBufOffset = pPriv->VBufOffset + (dstPitch * height / 2);
 	destId = FOURCC_YV12;
     } else {
 #endif
 	if (pPriv->textured)
-	    pPriv->YBuf0offset = 0;
+	    pPriv->YBufOffset = 0;
 	else
-	    pPriv->YBuf0offset = pPriv->buf->offset;
+	    pPriv->YBufOffset = pPriv->buf->offset;
+
+	/* switch buffers if double buffered */
+	if (!pPriv->textured && pPriv->doubleBuffer) {
+	    if (pPriv->currentBuf == 0)
+		pPriv->currentBuf = 1;
+	    else
+		pPriv->currentBuf = 0;
+
+	    pPriv->YBufOffset += size*pPriv->currentBuf;
+	}
 
 	if (pPriv->rotation & (RR_Rotate_90 | RR_Rotate_270)) {
-	    pPriv->UBuf0offset = pPriv->YBuf0offset + (dstPitch * 2 * width);
-	    pPriv->VBuf0offset = pPriv->UBuf0offset + (dstPitch * width / 2);
-	    if(pPriv->doubleBuffer) {
-		pPriv->YBuf1offset = pPriv->YBuf0offset + size;
-		pPriv->UBuf1offset = pPriv->YBuf1offset + (dstPitch * 2 * width);
-		pPriv->VBuf1offset = pPriv->UBuf1offset + (dstPitch * width / 2);
-	    }
+	    pPriv->UBufOffset = pPriv->YBufOffset + (dstPitch * 2 * width);
+	    pPriv->VBufOffset = pPriv->UBufOffset + (dstPitch * width / 2);
 	} else {
-	    pPriv->UBuf0offset = pPriv->YBuf0offset + (dstPitch * 2 * height);
-	    pPriv->VBuf0offset = pPriv->UBuf0offset + (dstPitch * height / 2);
-	    if(pPriv->doubleBuffer) {
-		pPriv->YBuf1offset = pPriv->YBuf0offset + size;
-		pPriv->UBuf1offset = pPriv->YBuf1offset + (dstPitch * 2 * height);
-		pPriv->VBuf1offset = pPriv->UBuf1offset + (dstPitch * height / 2);
-	    }
+	    pPriv->UBufOffset = pPriv->YBufOffset + (dstPitch * 2 * height);
+	    pPriv->VBufOffset = pPriv->UBufOffset + (dstPitch * height / 2);
 	}
 #ifdef INTEL_XVMC
     }
 #endif
 
-    /* Pick the idle buffer */
-    if (!pPriv->textured && pI830->overlayOn && pPriv->doubleBuffer)
-	pPriv->currentBuf = !((INREG(DOVSTA) & OC_BUF) >> 20);
-
     /* copy data */
     top = y1 >> 16;
     left = (x1 >> 16) & ~1;
@@ -2498,9 +2461,9 @@ I830PutImage(ScrnInfoPtr pScrn,
         if (IS_I965G(pI830)) {
 #ifdef INTEL_XVMC
             if (id == FOURCC_XVMC && pPriv->rotation == RR_Rotate_0) {
-                pPriv->YBuf0offset = buf -  pI830->FbBase;
-                pPriv->UBuf0offset = pPriv->YBuf0offset + height*width; 
-                pPriv->VBuf0offset = pPriv->UBuf0offset + height*width/4; 
+                pPriv->YBufOffset = buf -  pI830->FbBase;
+                pPriv->UBufOffset = pPriv->YBufOffset + height*width;
+                pPriv->VBufOffset = pPriv->UBufOffset + height*width/4;
             }
 #endif
             I965DisplayVideoTextured(pScrn, pPriv, destId, clipBoxes, width, height,
@@ -2757,7 +2720,6 @@ I830DisplaySurface(XF86SurfacePtr surface,
     OffscreenPrivPtr pPriv = (OffscreenPrivPtr) surface->devPrivate.ptr;
     ScrnInfoPtr pScrn = surface->pScrn;
     ScreenPtr pScreen = screenInfo.screens[pScrn->scrnIndex];
-    I830Ptr pI830 = I830PTR(pScrn);
     I830PortPrivPtr pI830Priv = GET_PORT_PRIVATE(pScrn);
     INT32 x1, y1, x2, y2;
     BoxRec dstBox;
@@ -2781,12 +2743,7 @@ I830DisplaySurface(XF86SurfacePtr surface,
 	return Success;
 
     /* fixup pointers */
-    pI830Priv->YBuf0offset = surface->offsets[0];
-    pI830Priv->YBuf1offset = pI830Priv->YBuf0offset;
-
-    /* Pick the idle buffer */
-    if (!pI830Priv->textured && pI830->overlayOn && pI830Priv->doubleBuffer)
-	pI830Priv->currentBuf = !((INREG(DOVSTA) & OC_BUF) >> 20);
+    pI830Priv->YBufOffset = surface->offsets[0];
 
     i830_display_overlay(pScrn, crtc, surface->id, surface->width, surface->height,
 		     surface->pitches[0], x1, y1, x2, y2, &dstBox,
diff --git a/src/i830_video.h b/src/i830_video.h
index fb4ad29..9093d5d 100644
--- a/src/i830_video.h
+++ b/src/i830_video.h
@@ -28,13 +28,9 @@ THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "xf86_OSproc.h"
 
 typedef struct {
-   uint32_t YBuf0offset;
-   uint32_t UBuf0offset;
-   uint32_t VBuf0offset;
-
-   uint32_t YBuf1offset;
-   uint32_t UBuf1offset;
-   uint32_t VBuf1offset;
+   uint32_t YBufOffset;
+   uint32_t UBufOffset;
+   uint32_t VBufOffset;
 
    unsigned char currentBuf;
 
diff --git a/src/i915_video.c b/src/i915_video.c
index b978a43..8e8e962 100644
--- a/src/i915_video.c
+++ b/src/i915_video.c
@@ -158,9 +158,9 @@ I915DisplayVideoTextured(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv, int id,
       OUT_BATCH(_3DSTATE_MAP_STATE | 3);
       OUT_BATCH(0x00000001);	/* texture map #1 */
       if (pPriv->buf)
-          OUT_RELOC(pPriv->buf, I915_GEM_DOMAIN_SAMPLER, 0, pPriv->YBuf0offset);
+          OUT_RELOC(pPriv->buf, I915_GEM_DOMAIN_SAMPLER, 0, pPriv->YBufOffset);
       else
-          OUT_BATCH(pPriv->YBuf0offset);
+          OUT_BATCH(pPriv->YBufOffset);
 
       ms3 = MAPSURF_422 | MS3_USE_FENCE_REGS;
       switch (id) {
@@ -270,9 +270,9 @@ I915DisplayVideoTextured(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv, int id,
       OUT_BATCH(0x00000007);
 
       if (pPriv->buf)
-          OUT_RELOC(pPriv->buf, I915_GEM_DOMAIN_SAMPLER, 0, pPriv->YBuf0offset);
+          OUT_RELOC(pPriv->buf, I915_GEM_DOMAIN_SAMPLER, 0, pPriv->YBufOffset);
       else
-          OUT_BATCH(pPriv->YBuf0offset);
+          OUT_BATCH(pPriv->YBufOffset);
 
       ms3 = MAPSURF_8BIT | MT_8BIT_I8 | MS3_USE_FENCE_REGS;
       ms3 |= (height - 1) << MS3_HEIGHT_SHIFT;
@@ -287,9 +287,9 @@ I915DisplayVideoTextured(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv, int id,
 	  OUT_BATCH(((video_pitch * 2 / 4) - 1) << MS4_PITCH_SHIFT);
 
       if (pPriv->buf)
-          OUT_RELOC(pPriv->buf, I915_GEM_DOMAIN_SAMPLER, 0, pPriv->UBuf0offset);
+          OUT_RELOC(pPriv->buf, I915_GEM_DOMAIN_SAMPLER, 0, pPriv->UBufOffset);
       else
-          OUT_BATCH(pPriv->UBuf0offset);
+          OUT_BATCH(pPriv->UBufOffset);
 
       ms3 = MAPSURF_8BIT | MT_8BIT_I8 | MS3_USE_FENCE_REGS;
       ms3 |= (height / 2 - 1) << MS3_HEIGHT_SHIFT;
@@ -298,9 +298,9 @@ I915DisplayVideoTextured(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv, int id,
       OUT_BATCH(((video_pitch / 4) - 1) << MS4_PITCH_SHIFT);
 
       if (pPriv->buf)
-          OUT_RELOC(pPriv->buf, I915_GEM_DOMAIN_SAMPLER, 0, pPriv->VBuf0offset);
+          OUT_RELOC(pPriv->buf, I915_GEM_DOMAIN_SAMPLER, 0, pPriv->VBufOffset);
       else
-          OUT_BATCH(pPriv->VBuf0offset);
+          OUT_BATCH(pPriv->VBufOffset);
 
       ms3 = MAPSURF_8BIT | MT_8BIT_I8 | MS3_USE_FENCE_REGS;
       ms3 |= (height / 2 - 1) << MS3_HEIGHT_SHIFT;
diff --git a/src/i965_video.c b/src/i965_video.c
index 810b761..423d48c 100644
--- a/src/i965_video.c
+++ b/src/i965_video.c
@@ -997,12 +997,12 @@ I965DisplayVideoTextured(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv, int id,
     ErrorF ("INST_PM 0x%08x\n", INREG(INST_PM));
 #endif
 
-    src_surf_base[0] = pPriv->YBuf0offset;
-    src_surf_base[1] = pPriv->YBuf0offset;
-    src_surf_base[2] = pPriv->VBuf0offset;
-    src_surf_base[3] = pPriv->VBuf0offset;
-    src_surf_base[4] = pPriv->UBuf0offset;
-    src_surf_base[5] = pPriv->UBuf0offset;
+    src_surf_base[0] = pPriv->YBufOffset;
+    src_surf_base[1] = pPriv->YBufOffset;
+    src_surf_base[2] = pPriv->VBufOffset;
+    src_surf_base[3] = pPriv->VBufOffset;
+    src_surf_base[4] = pPriv->UBufOffset;
+    src_surf_base[5] = pPriv->UBufOffset;
 #if 0
     ErrorF ("base 0 0x%x base 1 0x%x base 2 0x%x\n",
 	    src_surf_base[0], src_surf_base[1], src_surf_base[2]);
commit 232418d72ee967a81e39481b9f2ee379cb685458
Author: Daniel Vetter <daniel.vetter at ffwll.ch>
Date:   Tue Aug 11 16:06:35 2009 +0200

    Xv: use is_planar_fourcc helper some more
    
    Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/src/i830_video.c b/src/i830_video.c
index a4cb11e..afe02cb 100644
--- a/src/i830_video.c
+++ b/src/i830_video.c
@@ -1805,23 +1805,6 @@ i830_update_dst_box_to_crtc_coords(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
     return;
 }
 
-static int
-is_planar_fourcc(int id)
-{
-    switch (id) {
-    case FOURCC_YV12:
-    case FOURCC_I420:
-#ifdef INTEL_XVMC
-    case FOURCC_XVMC:
-#endif
-	return 1;
-    case FOURCC_UYVY:
-    case FOURCC_YUY2:
-    default:
-	return 0;
-    }
-}
-
 static void
 i830_store_coeffs_in_overlay_regs(uint16_t *reg_coeffs, coeffPtr new_coeffs,
 	int max_taps)
@@ -1991,6 +1974,25 @@ i830_update_scaling_factors(I830OverlayRegPtr overlay,
     return scaleChanged;
 }
 
+int
+is_planar_fourcc(int id)
+{
+    switch (id) {
+    case FOURCC_YV12:
+    case FOURCC_I420:
+#ifdef INTEL_XVMC
+    case FOURCC_XVMC:
+#endif
+	return 1;
+    case FOURCC_UYVY:
+    case FOURCC_YUY2:
+	return 0;
+    default:
+	ErrorF("Unknown format 0x%x\n", id);
+	return 0;
+    }
+}
+
 static void
 i830_display_overlay(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
 		   int id, short width, short height,
@@ -2278,23 +2280,11 @@ I830PutImage(ScrnInfoPtr pScrn,
      }
 
     destId = id;
-    switch (id) {
-    case FOURCC_YV12:
-    case FOURCC_I420:
+    if (is_planar_fourcc(id)) {
 	srcPitch = (width + 0x3) & ~0x3;
 	srcPitch2 = ((width >> 1) + 0x3) & ~0x3;
-	break;
-#ifdef INTEL_XVMC
-    case FOURCC_XVMC:
-	srcPitch = (width + 0x3) & ~0x3;
-	srcPitch2 = ((width >> 1) + 0x3) & ~0x3;
-	break;
-#endif
-    case FOURCC_UYVY:
-    case FOURCC_YUY2:
-    default:
+    } else {
 	srcPitch = width << 1;
-	break;
     }
 
     /* Only needs to be DWORD-aligned for textured on i915, but overlay has
@@ -2438,33 +2428,18 @@ I830PutImage(ScrnInfoPtr pScrn,
     left = (x1 >> 16) & ~1;
     npixels = ((((x2 + 0xffff) >> 16) + 1) & ~1) - left;
 
-    switch (id) {
-    case FOURCC_YV12:
-    case FOURCC_I420:
-	top &= ~1;
-	nlines = ((((y2 + 0xffff) >> 16) + 1) & ~1) - top;
-	I830CopyPlanarData(pScrn, pPriv, buf, srcPitch, srcPitch2, dstPitch,
-	    	       height, top, left, nlines, npixels, id);
-	break;
-    case FOURCC_UYVY:
-    case FOURCC_YUY2:
-	nlines = ((y2 + 0xffff) >> 16) - top;
-	I830CopyPackedData(pScrn, pPriv, buf, srcPitch, dstPitch, top, left,
-			   nlines, npixels);
-	break;
-#ifdef INTEL_XVMC
-    case FOURCC_XVMC:
-	if (pPriv->rotation != RR_Rotate_0) {
+    if (is_planar_fourcc(id)) {
+	if (id != FOURCC_XVMC
+		|| pPriv->rotation != RR_Rotate_0) {
 	    top &= ~1;
 	    nlines = ((((y2 + 0xffff) >> 16) + 1) & ~1) - top;
 	    I830CopyPlanarData(pScrn, pPriv, buf, srcPitch, srcPitch2, dstPitch,
 		    height, top, left, nlines, npixels, id);
 	}
-
-	break;
-#endif
-    default:
-	break;
+    } else {
+	nlines = ((y2 + 0xffff) >> 16) - top;
+	I830CopyPackedData(pScrn, pPriv, buf, srcPitch, dstPitch, top, left,
+			   nlines, npixels);
     }
 
     if (!pPriv->textured) {
diff --git a/src/i830_video.h b/src/i830_video.h
index 03e2ba9..fb4ad29 100644
--- a/src/i830_video.h
+++ b/src/i830_video.h
@@ -91,3 +91,5 @@ void I965DisplayVideoTextured(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
 void I830VideoBlockHandler(int i, pointer blockData, pointer pTimeout,
 			   pointer pReadmask);
 void i965_free_video(ScrnInfoPtr scrn);
+
+int is_planar_fourcc(int id);
diff --git a/src/i915_video.c b/src/i915_video.c
index 3b4247c..b978a43 100644
--- a/src/i915_video.c
+++ b/src/i915_video.c
@@ -53,27 +53,12 @@ I915DisplayVideoTextured(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv, int id,
    int nbox_total = REGION_NUM_RECTS(dstRegion);
    int nbox_this_time;
    int dxo, dyo, pix_xoff, pix_yoff;
-   Bool planar;
 
 #if 0
    ErrorF("I915DisplayVideo: %dx%d (pitch %d)\n", width, height,
 	  video_pitch);
 #endif
 
-   switch (id) {
-   case FOURCC_UYVY:
-   case FOURCC_YUY2:
-      planar = FALSE;
-      break;
-   case FOURCC_YV12:
-   case FOURCC_I420:
-      planar = TRUE;
-      break;
-   default:
-      ErrorF("Unknown format 0x%x\n", id);
-      return;
-   }
-
 #define BYTES_FOR_BOXES(n)	((200 + (n) * 20) * 4)
 #define BOXES_IN_BYTES(s)	((((s)/4) - 200) / 20)
 #define BATCH_BYTES(p)		((p)->batch_bo->size - 16)
@@ -147,7 +132,7 @@ I915DisplayVideoTextured(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv, int id,
    OUT_RELOC_PIXMAP(pPixmap, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
    ADVANCE_BATCH();
 
-   if (!planar) {
+   if (!is_planar_fourcc(id)) {
       FS_LOCALS(10);
 
       BEGIN_BATCH(16);
diff --git a/src/i965_video.c b/src/i965_video.c
index 46a461f..810b761 100644
--- a/src/i965_video.c
+++ b/src/i965_video.c
@@ -1008,26 +1008,7 @@ I965DisplayVideoTextured(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv, int id,
 	    src_surf_base[0], src_surf_base[1], src_surf_base[2]);
 #endif
     
-    switch (id) {
-    case FOURCC_UYVY:
-	src_surf_format = BRW_SURFACEFORMAT_YCRCB_SWAPY;
-	n_src_surf = 1;
-	src_width[0] = width;
-	src_height[0] = height;
-	src_pitch[0] = video_pitch;
-	break;
-    case FOURCC_YUY2:
-	src_surf_format = BRW_SURFACEFORMAT_YCRCB_NORMAL;
-	src_width[0] = width;
-	src_height[0] = height;
-	src_pitch[0] = video_pitch;
-	n_src_surf = 1;
-	break;
-#ifdef INTEL_XVMC
-    case FOURCC_XVMC:
-#endif
-    case FOURCC_I420:
-    case FOURCC_YV12:
+    if (is_planar_fourcc(id)) {
 	src_surf_format = BRW_SURFACEFORMAT_R8_UNORM;
 	src_width[1] = src_width[0] = width;
 	src_height[1] = src_height[0] = height;
@@ -1036,10 +1017,17 @@ I965DisplayVideoTextured(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv, int id,
 	src_height[4] = src_height[5] = src_height[2] = src_height[3] = height / 2;
 	src_pitch[4] = src_pitch[5] = src_pitch[2] = src_pitch[3] = video_pitch;
 	n_src_surf = 6;
-	break;
-    default:
-	return;
-    }    
+    } else {
+	if (id == FOURCC_UYVY)
+	    src_surf_format = BRW_SURFACEFORMAT_YCRCB_SWAPY;
+	else
+	    src_surf_format = BRW_SURFACEFORMAT_YCRCB_NORMAL;
+
+	src_width[0] = width;
+	src_height[0] = height;
+	src_pitch[0] = video_pitch;
+	n_src_surf = 1;
+    }
 
 #if 0
     ErrorF("dst surf:      0x%08x\n", state_base_offset + dest_surf_offset);
commit 219b14310efe49aff5d3d9023d2ba440c9f702c1
Author: Daniel Vetter <daniel.vetter at ffwll.ch>
Date:   Tue Aug 11 16:06:34 2009 +0200

    Xv: introduce planar memcpy helper
    
    Reduced 3 copies of the same code to one.
    
    Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/src/i830_video.c b/src/i830_video.c
index f4a2663..a4cb11e 100644
--- a/src/i830_video.c
+++ b/src/i830_video.c
@@ -1349,6 +1349,55 @@ I830CopyPackedData(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
 	drm_intel_bo_unmap(pPriv->buf);
 }
 
+static void i830_memcpy_plane(unsigned char *dst, unsigned char *src,
+		int height, int width,
+		int dstPitch, int srcPitch, Rotation rotation)
+{
+    int i, j = 0;
+    unsigned char *s;
+
+    switch (rotation) {
+    case RR_Rotate_0:
+	/* optimise for the case of no clipping */
+	if (srcPitch == dstPitch && srcPitch == width)
+	    memcpy (dst, src, srcPitch * height);
+	else
+	    for (i = 0; i < height; i++) {
+		memcpy(dst, src, width);
+		src += srcPitch;
+		dst += dstPitch;
+	    }
+	break;
+    case RR_Rotate_90:
+	for (i = 0; i < height; i++) {
+	    s = src;
+	    for (j = 0; j < width; j++) {
+		dst[(i) + ((width - j - 1) * dstPitch)] = *s++;
+	    }
+	    src += srcPitch;
+	}
+	break;
+    case RR_Rotate_180:
+	for (i = 0; i < height; i++) {
+	    s = src;
+	    for (j = 0; j < width; j++) {
+		dst[(width - j - 1) + ((height - i - 1) * dstPitch)] = *s++;
+	    }
+	    src += srcPitch;
+	}
+	break;
+    case RR_Rotate_270:
+	for (i = 0; i < height; i++) {
+	    s = src;
+	    for (j = 0; j < width; j++) {
+		dst[(height - i - 1) + (j * dstPitch)] = *s++;
+	    }
+	    src += srcPitch;
+	}
+	break;
+    }
+}
+
 static void
 I830CopyPlanarData(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
 		   unsigned char *buf, int srcPitch,
@@ -1356,9 +1405,7 @@ I830CopyPlanarData(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
 		   int h, int w, int id)
 {
     I830Ptr pI830 = I830PTR(pScrn);
-    int i, j = 0;
     unsigned char *src1, *src2, *src3, *dst_base, *dst1, *dst2, *dst3;
-    unsigned char *s;
     int dstPitch2 = dstPitch << 1;
 
 #if 0
@@ -1388,46 +1435,7 @@ I830CopyPlanarData(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
     else
 	dst1 = dst_base + pPriv->YBuf1offset;
 
-    switch (pPriv->rotation) {
-    case RR_Rotate_0:
-       /* optimise for the case of no clipping */
-	if (srcPitch == dstPitch2 && srcPitch == w)
-	    memcpy (dst1, src1, srcPitch * h);
-	else
-	    for (i = 0; i < h; i++) {
-		memcpy(dst1, src1, w);
-		src1 += srcPitch;
-		dst1 += dstPitch2;
-	    }
-	break;
-    case RR_Rotate_90:
-	for (i = 0; i < h; i++) {
-	    s = src1;
-	    for (j = 0; j < w; j++) {
-		dst1[(i) + ((w - j - 1) * dstPitch2)] = *s++;
-	    }
-	    src1 += srcPitch;
-	}
-	break;
-    case RR_Rotate_180:
-	for (i = 0; i < h; i++) {
-	    s = src1;
-	    for (j = 0; j < w; j++) {
-		dst1[(w - j - 1) + ((h - i - 1) * dstPitch2)] = *s++;
-	    }
-	    src1 += srcPitch;
-	}
-	break;
-    case RR_Rotate_270:
-	for (i = 0; i < h; i++) {
-	    s = src1;
-	    for (j = 0; j < w; j++) {
-		dst1[(h - i - 1) + (j * dstPitch2)] = *s++;
-	    }
-	    src1 += srcPitch;
-	}
-	break;
-    }
+    i830_memcpy_plane(dst1, src1, h, w, dstPitch2, srcPitch, pPriv->rotation);
 
     /* Copy V data for YV12, or U data for I420 */
     src2 = buf +                            /* start of YUV data */
@@ -1451,46 +1459,8 @@ I830CopyPlanarData(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
 	    dst2 = dst_base + pPriv->VBuf1offset;
     }
 
-    switch (pPriv->rotation) {
-    case RR_Rotate_0:
-       /* optimise for the case of no clipping */
-	if (srcPitch2 == dstPitch && srcPitch2 == (w/2))
-	    memcpy (dst2, src2, h/2 * srcPitch2);
-	else
-	    for (i = 0; i < h / 2; i++) {
-		memcpy(dst2, src2, w / 2);
-		src2 += srcPitch2;
-		dst2 += dstPitch;
-	    }
-	break;
-    case RR_Rotate_90:
-	for (i = 0; i < (h/2); i++) {
-	    s = src2;
-	    for (j = 0; j < (w/2); j++) {
-		dst2[(i) + (((w/2) - j - 1) * (dstPitch))] = *s++;
-	    }
-	    src2 += srcPitch2;
-	}
-	break;
-    case RR_Rotate_180:
-	for (i = 0; i < (h/2); i++) {
-	    s = src2;
-	    for (j = 0; j < (w/2); j++) {
-		dst2[((w/2) - j - 1) + (((h/2) - i - 1) * dstPitch)] = *s++;
-	    }
-	    src2 += srcPitch2;
-	}
-	break;
-    case RR_Rotate_270:
-	for (i = 0; i < (h/2); i++) {
-	    s = src2;
-	    for (j = 0; j < (w/2); j++) {
-		dst2[((h/2) - i - 1) + (j * dstPitch)] = *s++;
-	    }
-	    src2 += srcPitch2;
-	}
-	break;
-    }
+    i830_memcpy_plane(dst2, src2, h/2, w/2,
+		    dstPitch, srcPitch2, pPriv->rotation);
 
     /* Copy U data for YV12, or V data for I420 */
     src3 = buf +                            /* start of YUV data */
@@ -1514,46 +1484,8 @@ I830CopyPlanarData(ScrnInfoPtr pScrn, I830PortPrivPtr pPriv,
 	    dst3 = dst_base + pPriv->UBuf1offset;
     }
 
-    switch (pPriv->rotation) {
-    case RR_Rotate_0:
-       /* optimise for the case of no clipping */
-	if (srcPitch2 == dstPitch && srcPitch2 == (w/2))
-	    memcpy (dst3, src3, srcPitch2 * h/2);
-	else
-	    for (i = 0; i < h / 2; i++) {
-		memcpy(dst3, src3, w / 2);
-		src3 += srcPitch2;
-		dst3 += dstPitch;
-	    }
-	break;
-    case RR_Rotate_90:
-	for (i = 0; i < (h/2); i++) {
-	    s = src3;
-	    for (j = 0; j < (w/2); j++) {
-		dst3[(i) + (((w/2) - j - 1) * (dstPitch))] = *s++;
-	    }
-	    src3 += srcPitch2;
-	}
-	break;
-    case RR_Rotate_180:
-	for (i = 0; i < (h/2); i++) {
-	    s = src3;
-	    for (j = 0; j < (w/2); j++) {
-		dst3[((w/2) - j - 1) + (((h/2) - i - 1) * dstPitch)] = *s++;
-	    }
-	    src3 += srcPitch2;
-	}
-	break;
-    case RR_Rotate_270:
-	for (i = 0; i < (h/2); i++) {
-	    s = src3;
-	    for (j = 0; j < (w/2); j++) {
-		dst3[((h/2) - i - 1) + (j * dstPitch)] = *s++;
-	    }
-	    src3 += srcPitch2;
-	}
-	break;
-    }
+    i830_memcpy_plane(dst3, src3, h/2, w/2,
+		    dstPitch, srcPitch2, pPriv->rotation);
 
     if (pPriv->textured)
 	drm_intel_bo_unmap(pPriv->buf);
commit b90171f16652d1145fb80a63919f76a804a94cef
Author: Daniel Vetter <daniel.vetter at ffwll.ch>
Date:   Tue Aug 11 16:06:33 2009 +0200

    Xv: rename i830_display_video to i830_display_overlay
    
    This function only programs the overlay and is never called for textured
    video. Make this obvious.
    
    Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/src/i830_video.c b/src/i830_video.c
index 9e7eef1..f4a2663 100644
--- a/src/i830_video.c
+++ b/src/i830_video.c
@@ -2060,7 +2060,7 @@ i830_update_scaling_factors(I830OverlayRegPtr overlay,
 }
 
 static void
-i830_display_video(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
+i830_display_overlay(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
 		   int id, short width, short height,
 		   int dstPitch, int x1, int y1, int x2, int y2, BoxPtr dstBox,
 		   short src_w, short src_h, short drw_w, short drw_h)
@@ -2071,7 +2071,7 @@ i830_display_video(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
     int			planar;
     uint32_t		swidth, swidthsw, sheigth;
     int			tmp;
-    Bool		scaleChanged = FALSE;
+    Bool		scaleChanged;
 
     OVERLAY_DEBUG("I830DisplayVideo: %dx%d (pitch %d)\n", width, height,
 		  dstPitch);
@@ -2536,7 +2536,7 @@ I830PutImage(ScrnInfoPtr pScrn,
     }
 
     if (!pPriv->textured) {
-	i830_display_video(pScrn, crtc, destId, width, height, dstPitch,
+	i830_display_overlay(pScrn, crtc, destId, width, height, dstPitch,
 			   x1, y1, x2, y2, &dstBox, src_w, src_h,
 			   drw_w, drw_h);
 	
@@ -2881,7 +2881,7 @@ I830DisplaySurface(XF86SurfacePtr surface,
     if (!pI830Priv->textured && pI830->overlayOn && pI830Priv->doubleBuffer)
 	pI830Priv->currentBuf = !((INREG(DOVSTA) & OC_BUF) >> 20);
 
-    i830_display_video(pScrn, crtc, surface->id, surface->width, surface->height,
+    i830_display_overlay(pScrn, crtc, surface->id, surface->width, surface->height,
 		     surface->pitches[0], x1, y1, x2, y2, &dstBox,
 		     src_w, src_h, drw_w, drw_h);
 
commit 857e40a6e00db72401717da3ed79edbf65db31d4
Author: Daniel Vetter <daniel.vetter at ffwll.ch>
Date:   Tue Aug 11 16:06:32 2009 +0200

    Xv i830_display_video splitup: extract i830_overlay_cmd
    
    This slightly moves around (and simplifies) the OSTRIDE reg programming,
    too.
    
    Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/src/i830_video.c b/src/i830_video.c
index 1083f59..9e7eef1 100644
--- a/src/i830_video.c
+++ b/src/i830_video.c
@@ -1906,6 +1906,36 @@ i830_store_coeffs_in_overlay_regs(uint16_t *reg_coeffs, coeffPtr new_coeffs,
     }
 }
 
+static uint32_t
+i830_overlay_cmd(int id, int planar, unsigned char currentBuf)
+{
+    uint32_t OCMD = OVERLAY_ENABLE;
+
+    if (planar) {
+	OVERLAY_DEBUG("YUV420\n");
+	OCMD &= ~SOURCE_FORMAT;
+	OCMD &= ~OV_BYTE_ORDER;
+	OCMD |= YUV_420;
+    } else {
+	OVERLAY_DEBUG("YUV422\n");
+	OCMD &= ~SOURCE_FORMAT;
+	OCMD |= YUV_422;
+	OCMD &= ~OV_BYTE_ORDER;
+	if (id == FOURCC_UYVY)
+	    OCMD |= Y_SWAP;
+    }
+
+    OCMD &= ~(BUFFER_SELECT | FIELD_SELECT);
+    if (currentBuf == 0)
+	OCMD |= BUFFER0;
+    else
+	OCMD |= BUFFER1;
+
+    OVERLAY_DEBUG("OCMD is 0x%x\n", OCMD);
+
+    return OCMD;
+}
+
 static double
 i830_limit_coeff(double coeff)
 {
@@ -2041,7 +2071,6 @@ i830_display_video(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
     int			planar;
     uint32_t		swidth, swidthsw, sheigth;
     int			tmp;
-    uint32_t		OCMD;
     Bool		scaleChanged = FALSE;
 
     OVERLAY_DEBUG("I830DisplayVideo: %dx%d (pitch %d)\n", width, height,
@@ -2130,46 +2159,18 @@ i830_display_video(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
     scaleChanged = i830_update_scaling_factors(overlay,
 	    src_w, src_h, drw_w, drw_h);
 
-    OCMD = OVERLAY_ENABLE;
-    
-    switch (id) {
-    case FOURCC_YV12:
-    case FOURCC_I420:
-#ifdef INTEL_XVMC
-    case FOURCC_XVMC:
-#endif
-	OVERLAY_DEBUG("YUV420\n");
+    if (planar) {
 #if 0
 	/* set UV vertical phase to -0.25 */
 	overlay->UV_VPH = 0x30003000;
 #endif
+	overlay->OSTRIDE = (dstPitch * 2) | (dstPitch << 16);
 	OVERLAY_DEBUG("UV stride is %d, Y stride is %d\n",
 		      dstPitch, dstPitch * 2);
-	overlay->OSTRIDE = (dstPitch * 2) | (dstPitch << 16);
-	OCMD &= ~SOURCE_FORMAT;
-	OCMD &= ~OV_BYTE_ORDER;
-	OCMD |= YUV_420;
-	break;
-    case FOURCC_UYVY:
-    case FOURCC_YUY2:
-	OVERLAY_DEBUG("YUV422\n");
+    } else
 	overlay->OSTRIDE = dstPitch;
-	OCMD &= ~SOURCE_FORMAT;
-	OCMD |= YUV_422;
-	OCMD &= ~OV_BYTE_ORDER;
-	if (id == FOURCC_UYVY)
-	    OCMD |= Y_SWAP;
-	break;
-    }
 
-    OCMD &= ~(BUFFER_SELECT | FIELD_SELECT);
-    if (pPriv->currentBuf == 0)
-	OCMD |= BUFFER0;
-    else
-	OCMD |= BUFFER1;
-
-    overlay->OCMD = OCMD;
-    OVERLAY_DEBUG("OCMD is 0x%x\n", OCMD);
+    overlay->OCMD = i830_overlay_cmd(id, planar, pPriv->currentBuf);
 
     /* make sure the overlay is on */
     i830_overlay_on (pScrn);
commit 50d70e644ea0574752d0fe160ce8d873653c913b
Author: Daniel Vetter <daniel.vetter at ffwll.ch>
Date:   Tue Aug 11 16:06:31 2009 +0200

    Xv i830_display_video splitup: extract i830_calc_src_regs
    
    Also introduce an is_planar_fourcc helper. I'll use that one later.
    
    In i830_display_video this changeset moves the XVMC case (previously
    obscured as the default case) around. I've figured this default case
    does not make sense, here's why:
    
    XvMC is everywhere else handled as a planar format (e.g. in the register
    programming a few lines down). Furthermore the id variable gets mapped
    to FOURCC_YV12 if IS_I915(pI830) is true in I830PutImage. There's a
    second caller in the offscreen overlay support code.  But I think that
    code is bitrotten and not reliable as an information source.
    
    So we have a different behaviour only for id=FOURCC_XVMC and i965 class
    hw (i830 class doesn't have xvmc). I've crawled through various
    sources/intel documentations. Finally in the textured video implemention
    for i965 class hw (src/i965_video.c) I've found a switch statement that
    puts XVMC into the same case as I420 and YV12. So also in i965 class hw
    xvmc uses a planar format.
    
    In conclusion I claim that this code was bogus and XvMC on i965 class hw
    over Xv overlay was most likely broken.
    
    Signed-off-by: Daniel Vetter <daniel.vetter at ffwll.ch>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/src/i830_video.c b/src/i830_video.c
index 47c026d..1083f59 100644
--- a/src/i830_video.c
+++ b/src/i830_video.c
@@ -1782,6 +1782,46 @@ i830_swidth (I830Ptr pI830, unsigned int offset,
 }
 
 static void
+i830_calc_src_regs(I830Ptr pI830, int planar, short width, short height,
+	uint32_t *swidth_out, uint32_t *swidthsw_out, uint32_t *sheigth_out)
+{
+    unsigned int	mask, shift, offsety, offsetu;
+    unsigned int	swidth, swidthy, swidthuv;
+    I830PortPrivPtr	pPriv = pI830->adaptor->pPortPrivates[0].ptr;
+
+    if (IS_I9XX(pI830)) {
+	shift = 6;
+	mask = 0x3f;
+    } else {
+	shift = 5;
+	mask = 0x1f;
+    }
+
+    if (pPriv->currentBuf == 0) {
+	offsety = pPriv->YBuf0offset;
+	offsetu = pPriv->UBuf0offset;
+    } else {
+	offsety = pPriv->YBuf1offset;
+	offsetu = pPriv->UBuf1offset;
+    }
+
+    if (planar) {
+	*swidth_out = width | ((width/2 & 0x7ff) << 16);
+	swidthy  = i830_swidth (pI830, offsety, width, mask, shift);
+	swidthuv = i830_swidth (pI830, offsetu, width/2, mask, shift);
+	*swidthsw_out = (swidthy) | (swidthuv << 16);
+	*sheigth_out = height | ((height / 2) << 16);
+    } else {
+	*swidth_out = width;
+	swidth = i830_swidth (pI830, offsety, width << 1, mask, shift);
+	*swidthsw_out = swidth;
+	*sheigth_out = height;
+    }
+
+    return;
+}
+
+static void
 i830_update_dst_box_to_crtc_coords(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
 		BoxPtr dstBox)
 {
@@ -1833,6 +1873,23 @@ i830_update_dst_box_to_crtc_coords(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
     return;
 }
 
+static int
+is_planar_fourcc(int id)
+{
+    switch (id) {
+    case FOURCC_YV12:
+    case FOURCC_I420:
+#ifdef INTEL_XVMC
+    case FOURCC_XVMC:
+#endif
+	return 1;
+    case FOURCC_UYVY:
+    case FOURCC_YUY2:
+    default:
+	return 0;
+    }
+}
+
 static void
 i830_store_coeffs_in_overlay_regs(uint16_t *reg_coeffs, coeffPtr new_coeffs,
 	int max_taps)
@@ -1981,8 +2038,8 @@ i830_display_video(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
     I830Ptr		pI830 = I830PTR(pScrn);
     I830PortPrivPtr	pPriv = pI830->adaptor->pPortPrivates[0].ptr;
     I830OverlayRegPtr	overlay = I830OVERLAYREG(pI830);
-    unsigned int	swidth, swidthy, swidthuv;
-    unsigned int	mask, shift, offsety, offsetu;
+    int			planar;
+    uint32_t		swidth, swidthsw, sheigth;
     int			tmp;
     uint32_t		OCMD;
     Bool		scaleChanged = FALSE;
@@ -2039,54 +2096,14 @@ i830_display_video(ScrnInfoPtr pScrn, xf86CrtcPtr crtc,
 	drw_h = ((drw_h * pPriv->scaleRatio) >> 16) + 1;
     }
 
-    if (IS_I9XX(pI830)) {
-	shift = 6;
-	mask = 0x3f;
-    } else {
-	shift = 5;
-	mask = 0x1f;
-    }
-
-    if (pPriv->currentBuf == 0) {
-	offsety = pPriv->YBuf0offset;
-	offsetu = pPriv->UBuf0offset;
-    } else {
-	offsety = pPriv->YBuf1offset;
-	offsetu = pPriv->UBuf1offset;
-    }
-
-    switch (id) {
-    case FOURCC_YV12:
-    case FOURCC_I420:
-	overlay->SWIDTH = width | ((width/2 & 0x7ff) << 16);
-	swidthy  = i830_swidth (pI830, offsety, width, mask, shift);
-	swidthuv = i830_swidth (pI830, offsetu, width/2, mask, shift);
-	overlay->SWIDTHSW = (swidthy) | (swidthuv << 16);
-	overlay->SHEIGHT = height | ((height / 2) << 16);
-	break;
-    case FOURCC_UYVY:
-    case FOURCC_YUY2:
-    default:
-	overlay->SWIDTH = width;
-	swidth = ((offsety + (width << 1) + mask) >> shift) -
-	(offsety >> shift);
-
-	if (IS_I9XX(pI830))
-	    swidth <<= 1;
+    planar = is_planar_fourcc(id);
 
-	swidth -= 1;
+    i830_calc_src_regs(pI830, planar, width, height,
+	    &swidth, &swidthsw, &sheigth);
 
-	swidth <<= 2;
-	
-	OVERLAY_DEBUG("swidthsw is old %d new %d\n",
-		      swidth,
-		      i830_swidth (pI830, offsety, width << 1,
-				   mask, shift));
-
-	overlay->SWIDTHSW = swidth;
-	overlay->SHEIGHT = height;
-	break;
-    }
+    overlay->SWIDTH = swidth;
+    overlay->SWIDTHSW = swidthsw;
+    overlay->SHEIGHT = sheigth;
 
     overlay->DWINPOS = (dstBox->y1 << 16) | dstBox->x1;
 


More information about the xorg-commit mailing list