xf86-video-intel: Branch 'xvmc-i915' - 5 commits - src/i830_driver.c src/i830.h src/i830_video.c src/i830_video.h src/i915_hwmc.c src/i915_hwmc.h src/xvmc/I915XvMC.c src/xvmc/I915XvMC.h

Zhenyu Wang zhen at kemper.freedesktop.org
Tue Aug 7 18:47:27 PDT 2007


 src/i830.h          |    4 
 src/i830_driver.c   |    8 -
 src/i830_video.c    |   23 +---
 src/i830_video.h    |    1 
 src/i915_hwmc.c     |  288 +++++++++++++++-------------------------------------
 src/i915_hwmc.h     |   36 +-----
 src/xvmc/I915XvMC.c |  224 +++++++---------------------------------
 src/xvmc/I915XvMC.h |   61 +++++------
 8 files changed, 177 insertions(+), 468 deletions(-)

New commits:
diff-tree 87cc72ef509b85635bf0e84c47dfed6b7242170b (from fec6744b763f2b85b4e592c51326b9ee979bef5d)
Author: Zhenyu Wang <zhenyu.z.wang at intel.com>
Date:   Wed Aug 8 09:39:55 2007 +0800

    check early if we have slot left for new context or surface

diff --git a/src/i915_hwmc.c b/src/i915_hwmc.c
index 9475977..b6865c6 100644
--- a/src/i915_hwmc.c
+++ b/src/i915_hwmc.c
@@ -208,6 +208,8 @@ static void initI915XvMC(I915XvMCPtr xvm
         xvmc->surfaces[i] = 0;
         xvmc->sfprivs[i] = NULL;
     }
+    xvmc->ncontexts = 0;
+    xvmc->nsurfaces = 0;
 }
 
 //XXX
@@ -468,7 +470,13 @@ static int I915XvMCCreateContext (ScrnIn
         return BadAlloc;
     }
 
-    if (pXvMC->ncontexts >= I915_XVMC_MAX_CONTEXTS) {
+    for (i = 0; i < I915_XVMC_MAX_CONTEXTS; i++) {
+        if (!pXvMC->contexts[i])
+            break;
+    }
+
+    if (i == I915_XVMC_MAX_CONTEXTS || 
+	    pXvMC->ncontexts >= I915_XVMC_MAX_CONTEXTS) {
         xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
                    "[XvMC] I915XvMCCreateContext: Out of contexts.\n");
         return BadAlloc;
@@ -484,11 +492,6 @@ static int I915XvMCCreateContext (ScrnIn
 
     *num_priv = sizeof(I915XvMCCreateContextRec) >> 2;
 
-    for (i = 0; i < I915_XVMC_MAX_CONTEXTS; i++) {
-        if (!pXvMC->contexts[i])
-            break;
-    }
-
     ctxpriv = (I915XvMCContextPriv *)xcalloc(1, sizeof(I915XvMCContextPriv));
 
     if (!ctxpriv) {
@@ -572,10 +575,22 @@ static int I915XvMCCreateSurface(ScrnInf
     unsigned int srfno;
     unsigned long bufsize;
 
+    if (!pI830->XvMCEnabled) {
+        xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+                   "[XvMC] I915XvMCCreateContext: Cannot use XvMC!\n");
+        return BadAlloc;
+    }
+
     *priv = NULL;
     *num_priv = 0;
 
-    if (pXvMC->nsurfaces >= I915_XVMC_MAX_SURFACES) {
+    for (srfno = 0; srfno < I915_XVMC_MAX_SURFACES; ++srfno) {
+        if (!pXvMC->surfaces[srfno])
+            break;
+    }
+
+    if (srfno == I915_XVMC_MAX_SURFACES ||
+	    pXvMC->nsurfaces >= I915_XVMC_MAX_SURFACES) {
         xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
                    "[XvMC] I915XvMCCreateSurface: Too many surfaces !\n");
         return BadAlloc;
@@ -631,10 +646,6 @@ static int I915XvMCCreateSurface(ScrnInf
         return BadAlloc;
     }
 
-    for (srfno = 0; srfno < I915_XVMC_MAX_SURFACES; ++srfno) {
-        if (!pXvMC->surfaces[srfno])
-            break;
-    }
     surfaceRec->srfno = srfno;
     surfaceRec->srf.handle = sfpriv->surface_handle;
     surfaceRec->srf.offset = sfpriv->surface->offset;
@@ -661,7 +672,13 @@ static int I915XvMCCreateSubpicture (Scr
     *priv = NULL;
     *num_priv = 0;
 
-    if (pXvMC->nsurfaces >= I915_XVMC_MAX_SURFACES) {
+    for (srfno = 0; srfno < I915_XVMC_MAX_SURFACES; ++srfno) {
+        if (!pXvMC->surfaces[srfno])
+            break;
+    }
+
+    if (srfno == I915_XVMC_MAX_SURFACES ||
+	    pXvMC->nsurfaces >= I915_XVMC_MAX_SURFACES) {
         xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
                    "[XvMC] I915XvMCCreateSubpicture: Too many surfaces !\n");
         return BadAlloc;
@@ -717,11 +734,6 @@ static int I915XvMCCreateSubpicture (Scr
         return BadAlloc;
     }
 
-    for (srfno = 0; srfno < I915_XVMC_MAX_SURFACES; ++srfno) {
-        if (!pXvMC->surfaces[srfno])
-            break;
-    }
-
     surfaceRec->srfno = srfno;
     surfaceRec->srf.handle = sfpriv->surface_handle;
     surfaceRec->srf.offset = sfpriv->surface->offset;
@@ -820,7 +832,7 @@ static int I915XvMCPutImage(ScrnInfoPtr 
 			    "[XvMC] I915XvMCPutImage: Invalid parameters !\n");
 		    return 1;
 		}
-                   
+
 		buf = pI830->FbBase + pXvMC->sfprivs[i915XvMCData->srfNo]->surface->offset;
 		id = i915XvMCData->real_id;
 		pI830->IsXvMCSurface = 1;
diff-tree fec6744b763f2b85b4e592c51326b9ee979bef5d (from 76c084d41999f13497b80d4ac6799cb974adaa03)
Author: Zhenyu Wang <zhenyu.z.wang at intel.com>
Date:   Wed Aug 8 09:26:10 2007 +0800

    I missed to remove port attributes wrapper

diff --git a/src/i915_hwmc.c b/src/i915_hwmc.c
index 8ff1864..9475977 100644
--- a/src/i915_hwmc.c
+++ b/src/i915_hwmc.c
@@ -93,8 +93,6 @@ typedef struct _I915XvMC 
     I915XvMCSurfacePriv *sfprivs[I915_XVMC_MAX_SURFACES];
     I915XvMCContextPriv *ctxprivs[I915_XVMC_MAX_CONTEXTS];
     int ncontexts,nsurfaces;
-    SetPortAttributeFuncPtr saveSetPortAttribute;
-    GetPortAttributeFuncPtr saveGetPortAttribute;
     PutImageFuncPtr savePutImage;
 } I915XvMC, *I915XvMCPtr;
 
diff-tree 76c084d41999f13497b80d4ac6799cb974adaa03 (from cfc614b1f9143ed1407733aaa81c4a980c613a63)
Author: Zhenyu Wang <zhenyu.z.wang at intel.com>
Date:   Wed Aug 8 09:22:42 2007 +0800

    explicit say "unsigned int"

diff --git a/src/i915_hwmc.c b/src/i915_hwmc.c
index 79fe284..8ff1864 100644
--- a/src/i915_hwmc.c
+++ b/src/i915_hwmc.c
@@ -657,8 +657,8 @@ static int I915XvMCCreateSubpicture (Scr
     I915XvMCSurfacePriv *sfpriv = NULL;
     I915XvMCCreateSurfaceRec *surfaceRec = NULL;
     XvMCContextPtr ctx = NULL;
-    unsigned srfno;
-    unsigned bufsize;
+    unsigned int srfno;
+    unsigned int bufsize;
 
     *priv = NULL;
     *num_priv = 0;
diff --git a/src/i915_hwmc.h b/src/i915_hwmc.h
index 61c7c4b..597d30c 100644
--- a/src/i915_hwmc.h
+++ b/src/i915_hwmc.h
@@ -47,12 +47,11 @@
 
 typedef struct
 {
-    unsigned command;
-    unsigned ctxNo;
-    unsigned srfNo;
-    unsigned subPicNo;
+    unsigned int command;
+    unsigned int ctxNo;
+    unsigned int srfNo;
+    unsigned int subPicNo;
     int real_id;
-    unsigned pad;
 } I915XvMCCommandBuffer;
 
 struct hwmc_buffer
@@ -65,7 +64,7 @@ struct hwmc_buffer
 
 typedef struct 
 {
-    unsigned ctxno; /* XvMC private context reference number */
+    unsigned int ctxno; /* XvMC private context reference number */
     struct hwmc_buffer sis;
     struct hwmc_buffer ssb;
     struct hwmc_buffer msb;
@@ -73,16 +72,16 @@ typedef struct 
     struct hwmc_buffer psc;
     struct hwmc_buffer corrdata;/* Correction Data Buffer */
     struct hwmc_buffer batchbuffer;
-    unsigned sarea_size;
-    unsigned sarea_priv_offset;
-    unsigned screen;
-    unsigned depth;
+    unsigned int sarea_size;
+    unsigned int sarea_priv_offset;
+    unsigned int screen;
+    unsigned int depth;
     int deviceID;
 } I915XvMCCreateContextRec;
 
 typedef struct 
 {
-    unsigned srfno;
+    unsigned int srfno;
     struct hwmc_buffer srf;
 } I915XvMCCreateSurfaceRec;
 
diff --git a/src/xvmc/I915XvMC.c b/src/xvmc/I915XvMC.c
index 7040f6a..22718de 100644
--- a/src/xvmc/I915XvMC.c
+++ b/src/xvmc/I915XvMC.c
@@ -66,7 +66,7 @@
                                  SIZE_Y420(surface->width, surface->height))
 
 /* Lookup tables to speed common calculations */
-_STATIC_ unsigned mb_bytes[] = {
+_STATIC_ unsigned int mb_bytes[] = {
     000, 128, 128, 256, 128, 256, 256, 384,  // 0
     128, 256, 256, 384, 256, 384, 384, 512,  // 1
     128, 256, 256, 384, 256, 384, 384, 512,  // 10
@@ -86,13 +86,13 @@ _STATIC_ char I915KernelDriverName[] = "
 _STATIC_ int error_base;
 _STATIC_ int event_base;
 
-_STATIC_ int findOverlap(unsigned width, unsigned height,
+_STATIC_ int findOverlap(unsigned int width, unsigned int height,
                        short *dstX, short *dstY,
                        short *srcX, short *srcY, 
                        unsigned short *areaW, unsigned short *areaH)
 {
     int w, h;
-    unsigned mWidth, mHeight;
+    unsigned int mWidth, mHeight;
 
     w = *areaW;
     h = *areaH;
@@ -128,7 +128,7 @@ _STATIC_ __inline__ void renderError(voi
     return;
 }
 
-_STATIC_ void I915XvMCContendedLock(i915XvMCContext *pI915XvMC, unsigned flags)
+_STATIC_ void I915XvMCContendedLock(i915XvMCContext *pI915XvMC, drmLockFlags flags)
 {
     drmGetLock(pI915XvMC->fd, pI915XvMC->hHWContext, flags);
 }
@@ -202,16 +202,16 @@ _STATIC_ void i915_flush(i915XvMCContext
 /* for MC picture rendering */
 _STATIC_ void i915_mc_static_indirect_state_buffer(XvMCContext *context, 
                                                    XvMCSurface *surface,
-                                                   unsigned picture_structure,
-                                                   unsigned flags,
-                                                   unsigned picture_coding_type)
+                                                   unsigned int picture_structure,
+                                                   unsigned int flags,
+                                                   unsigned int picture_coding_type)
 {
     struct i915_3dstate_buffer_info *buffer_info;
     struct i915_3dstate_dest_buffer_variables *dest_buffer_variables;
     struct i915_3dstate_dest_buffer_variables_mpeg *dest_buffer_variables_mpeg;
     i915XvMCSurface *pI915Surface = (i915XvMCSurface *)surface->privData;
     i915XvMCContext *pI915XvMC = (i915XvMCContext *)context->privData;
-    unsigned w = surface->width, h = surface->height;
+    unsigned int w = surface->width, h = surface->height;
 
     /* 3DSTATE_BUFFER_INFO */
     /* DEST Y */
@@ -334,7 +334,7 @@ _STATIC_ void i915_mc_map_state_buffer(X
     struct i915_3dstate_map_state *map_state;
     struct texture_map *tm;
     i915XvMCContext *pI915XvMC = (i915XvMCContext *)context->privData;
-    unsigned w = context->width, h = context->height;
+    unsigned int w = context->width, h = context->height;
  
     /* 3DSATE_MAP_STATE: Y */
     map_state = (struct i915_3dstate_map_state *)pI915XvMC->msb.map;
@@ -479,7 +479,7 @@ _STATIC_ void i915_mc_load_sis_msb_buffe
     msb_state *msb = NULL;
     i915XvMCContext *pI915XvMC = (i915XvMCContext *)context->privData;
     void *base = NULL;
-    unsigned size;
+    unsigned int size;
     int mem_select = 1;
 
     /* 3DSTATE_LOAD_INDIRECT */
@@ -624,7 +624,7 @@ _STATIC_ void i915_mc_mpeg_macroblock_1f
     intelBatchbufferData(pI915XvMC, &macroblock_1fbmv, sizeof(macroblock_1fbmv), 0);
 }
 
-_STATIC_ void i915_mc_mpeg_macroblock_2fbmv(XvMCContext *context, XvMCMacroBlock *mb, unsigned ps)
+_STATIC_ void i915_mc_mpeg_macroblock_2fbmv(XvMCContext *context, XvMCMacroBlock *mb, unsigned int ps)
 {
     struct i915_3dmpeg_macroblock_2fbmv macroblock_2fbmv;
     i915XvMCContext *pI915XvMC = (i915XvMCContext *)context->privData;
@@ -761,12 +761,12 @@ _STATIC_ void i915_mc_sampler_state_buff
     ts->ts2.default_color = 0;
 }
 
-_STATIC_ void i915_inst_arith(unsigned *inst,
-                            unsigned op,
-                            unsigned dest,
-                            unsigned mask,
-                            unsigned saturate,
-                            unsigned src0, unsigned src1, unsigned src2)
+_STATIC_ void i915_inst_arith(unsigned int *inst,
+                            unsigned int op,
+                            unsigned int dest,
+                            unsigned int mask,
+                            unsigned int saturate,
+                            unsigned int src0, unsigned int src1, unsigned int src2)
 {
     dest = UREG(GET_UREG_TYPE(dest), GET_UREG_NR(dest));
     *inst = (op | A0_DEST(dest) | mask | saturate | A0_SRC0(src0));
@@ -776,12 +776,12 @@ _STATIC_ void i915_inst_arith(unsigned *
     *inst = (A2_SRC1(src1) | A2_SRC2(src2));
 }
 
-_STATIC_ void i915_inst_decl(unsigned *inst, 
-                           unsigned type,
-                           unsigned nr,
-                           unsigned d0_flags)
+_STATIC_ void i915_inst_decl(unsigned int *inst, 
+                           unsigned int type,
+                           unsigned int nr,
+                           unsigned int d0_flags)
 {
-    unsigned reg = UREG(type, nr);
+    unsigned int reg = UREG(type, nr);
     
     *inst = (D0_DCL | D0_DEST(reg) | d0_flags);
     inst++;
@@ -790,11 +790,11 @@ _STATIC_ void i915_inst_decl(unsigned *i
     *inst = D2_MBZ;
 }
 
-_STATIC_ void i915_inst_texld(unsigned *inst,
-                              unsigned op,
-                              unsigned dest,
-                              unsigned coord,
-                              unsigned sampler)
+_STATIC_ void i915_inst_texld(unsigned int *inst,
+                              unsigned int op,
+                              unsigned int dest,
+                              unsigned int coord,
+                              unsigned int sampler)
 {
    dest = UREG(GET_UREG_TYPE(dest), GET_UREG_NR(dest));
    *inst = (op | T0_DEST(dest) | T0_SAMPLER(sampler));
@@ -808,8 +808,8 @@ _STATIC_ void i915_mc_pixel_shader_progr
 {
     struct i915_3dstate_pixel_shader_program *pixel_shader_program;
     i915XvMCContext *pI915XvMC = (i915XvMCContext *)context->privData;
-    unsigned *inst;
-    unsigned dest, src0, src1, src2;
+    unsigned int *inst;
+    unsigned int dest, src0, src1, src2;
 
     /* Shader 0 */
     pixel_shader_program = (struct i915_3dstate_pixel_shader_program *)pI915XvMC->psp.map;
@@ -819,7 +819,7 @@ _STATIC_ void i915_mc_pixel_shader_progr
     pixel_shader_program->dw0.retain = 1;
     pixel_shader_program->dw0.length = 2;
     /* mov oC, c0.0000 */
-    inst = (unsigned *)(++pixel_shader_program);
+    inst = (unsigned int*)(++pixel_shader_program);
     dest = UREG(REG_TYPE_OC, 0);
     src0 = UREG(REG_TYPE_CONST, 0);
     src1 = 0;
@@ -836,7 +836,7 @@ _STATIC_ void i915_mc_pixel_shader_progr
     pixel_shader_program->dw0.retain = 1;
     pixel_shader_program->dw0.length = 14;
     /* dcl t0.xy */
-    inst = (unsigned *)(++pixel_shader_program);
+    inst = (unsigned int*)(++pixel_shader_program);
     i915_inst_decl(inst, REG_TYPE_T, T_TEX0, D0_CHANNEL_XY);
     /* dcl t1.xy */
     inst += 3;
@@ -867,7 +867,7 @@ _STATIC_ void i915_mc_pixel_shader_progr
     pixel_shader_program->dw0.retain = 1;
     pixel_shader_program->dw0.length = 14;
     /* dcl t2.xy */
-    inst = (unsigned *)(++pixel_shader_program);
+    inst = (unsigned int*)(++pixel_shader_program);
     i915_inst_decl(inst, REG_TYPE_T, T_TEX2, D0_CHANNEL_XY);
     /* dcl t3.xy */
     inst += 3;
@@ -898,7 +898,7 @@ _STATIC_ void i915_mc_pixel_shader_progr
     pixel_shader_program->dw0.retain = 1;
     pixel_shader_program->dw0.length = 29;
     /* dcl t0.xy */
-    inst = (unsigned *)(++pixel_shader_program);
+    inst = (unsigned int*)(++pixel_shader_program);
     i915_inst_decl(inst, REG_TYPE_T, T_TEX0, D0_CHANNEL_XY);
     /* dcl t1.xy */
     inst += 3;
@@ -976,7 +976,7 @@ _STATIC_ void i915_mc_one_time_state_ini
     psp_state *psp = NULL;
     psc_state *psc = NULL;
     i915XvMCContext *pI915XvMC = (i915XvMCContext *)context->privData;
-    unsigned size;
+    unsigned int size;
     void *base = NULL;
     int mem_select = 1;
 
@@ -1077,7 +1077,7 @@ _STATIC_ void i915_mc_one_time_state_ini
     free(base);
 }
 
-_STATIC_ void i915_mc_invalidate_subcontext_buffers(XvMCContext *context, unsigned mask)
+_STATIC_ void i915_mc_invalidate_subcontext_buffers(XvMCContext *context, unsigned int mask)
 {
     struct i915_3dstate_load_indirect *load_indirect = NULL;
     sis_state *sis = NULL;
@@ -1087,7 +1087,7 @@ _STATIC_ void i915_mc_invalidate_subcont
     psp_state *psp = NULL;
     psc_state *psc = NULL;
     i915XvMCContext *pI915XvMC = (i915XvMCContext *)context->privData;
-    unsigned size;
+    unsigned int size;
     void *base = NULL, *ptr = NULL;
 
     size = sizeof(*load_indirect);
@@ -1286,7 +1286,7 @@ _STATIC_ void i915_yuv2rgb_map_state_buf
     struct texture_map *tm;
     i915XvMCSurface *privTarget = NULL;
     i915XvMCContext *pI915XvMC = NULL;
-    unsigned w = target_surface->width, h = target_surface->height;
+    unsigned int w = target_surface->width, h = target_surface->height;
 
     privTarget = (i915XvMCSurface *)target_surface->privData;
     pI915XvMC = (i915XvMCContext *)privTarget->privContext;
@@ -1452,7 +1452,7 @@ _STATIC_ void i915_yuv2rgb_sampler_state
 }
 
 _STATIC_ void i915_yuv2rgb_static_indirect_state_buffer(XvMCSurface *surface,
-                                                      unsigned dstaddr, 
+                                                      unsigned int dstaddr, 
                                                       int dstpitch)
 {
     struct i915_3dstate_buffer_info *buffer_info;
@@ -1490,8 +1490,8 @@ _STATIC_ void i915_yuv2rgb_pixel_shader_
     struct i915_3dstate_pixel_shader_program *pixel_shader_program;
     i915XvMCSurface *privSurface = (i915XvMCSurface *)surface->privData;
     i915XvMCContext *pI915XvMC = (i915XvMCContext *)privSurface->privContext;
-    unsigned *inst;
-    unsigned dest, src0, src1;
+    unsigned int *inst;
+    unsigned int dest, src0, src1;
 
     /* Shader 0 */
     pixel_shader_program = (struct i915_3dstate_pixel_shader_program *)pI915XvMC->psp.map;
@@ -1501,7 +1501,7 @@ _STATIC_ void i915_yuv2rgb_pixel_shader_
     pixel_shader_program->dw0.retain = 0;
     pixel_shader_program->dw0.length = 23;
     /* dcl      t0.xy */
-    inst = (unsigned *)(++pixel_shader_program);
+    inst = (unsigned int*)(++pixel_shader_program);
     i915_inst_decl(inst, REG_TYPE_T, T_TEX0, D0_CHANNEL_XY);
     /* dcl         t1.xy */
     inst += 3;
@@ -1554,7 +1554,7 @@ _STATIC_ void i915_yuv2rgb_proc(XvMCSurf
     psp_state *psp = NULL;
     struct i915_3dprimitive *_3dprimitive = NULL;
     struct vertex_data *vd = NULL;
-    unsigned size;
+    unsigned int size;
     void *base = NULL;
 
     /* 3DSTATE_LOAD_STATE_IMMEDIATE_1 */
diff --git a/src/xvmc/I915XvMC.h b/src/xvmc/I915XvMC.h
index 3a83edc..78aea7d 100644
--- a/src/xvmc/I915XvMC.h
+++ b/src/xvmc/I915XvMC.h
@@ -66,13 +66,13 @@ typedef struct _i915XvMCDrmMap {
 //  pointer in the XvMCContext structure.
 ***************************************************************************/
 typedef struct _i915XvMCContext {
-    unsigned ctxno;
+    unsigned int ctxno;
     int fd;   /* File descriptor for /dev/dri */
-    unsigned last_render;
-    unsigned last_flip;
-    unsigned dual_prime; /* Flag to identify when dual prime is in use. */
-    unsigned yStride;
-    unsigned uvStride;
+    unsigned int last_render;
+    unsigned int last_flip;
+    unsigned int dual_prime; /* Flag to identify when dual prime is in use. */
+    unsigned int yStride;
+    unsigned int uvStride;
     unsigned short ref;
     pthread_mutex_t ctxmutex;
     char busIdString[21]; /* PCI:0:1:0 or PCI:0:2:0 */
@@ -84,10 +84,10 @@ typedef struct _i915XvMCContext {
     drm_context_t hHWContext; /* drmcontext; */
     drm_handle_t hsarea;                /* Handle to drm shared memory area */
     drmAddress sarea_address;	        /* Virtual address of shared memory area */
-    unsigned sarea_size;                /* Size of drm shared memory area */
-    unsigned sarea_priv_offset;	        /* Offset in sarea to private part */
-    unsigned screen;
-    unsigned depth;
+    unsigned int sarea_size;                /* Size of drm shared memory area */
+    unsigned int sarea_priv_offset;	        /* Offset in sarea to private part */
+    unsigned int screen;
+    unsigned int depth;
     XvPortID port;		       /* Xv Port ID when displaying */
     int haveXv;                        /* Have I initialized the Xv
                                         * connection for this surface? */
@@ -112,19 +112,19 @@ typedef struct _i915XvMCContext {
     sigset_t sa_mask;
 
     struct {
-        unsigned start_offset;
-        unsigned size;
-        unsigned space;
+        unsigned int start_offset;
+        unsigned int size;
+        unsigned int space;
         unsigned char *ptr;
     } batch;
 
     struct 
     {
         void *ptr;
-        unsigned size;
-        unsigned offset;
-        unsigned active_buf;
-        unsigned irq_emitted;
+        unsigned int size;
+        unsigned int offset;
+        unsigned int active_buf;
+        unsigned int irq_emitted;
     } alloc;
 } i915XvMCContext;
 
@@ -134,10 +134,10 @@ typedef struct _i915XvMCContext {
 //  structure.
 ***************************************************************************/
 typedef struct _i915XvMCSubpicture {
-    unsigned srfNo;
-    unsigned last_render;
-    unsigned last_flip;
-    unsigned pitch;
+    unsigned int srfNo;
+    unsigned int last_render;
+    unsigned int last_flip;
+    unsigned int pitch;
     unsigned char palette[3][16];
     i915XvMCDrmMap srf;
     i915XvMCContext *privContext;
@@ -150,13 +150,13 @@ typedef struct _i915XvMCSubpicture {
 ***************************************************************************/
 #define I830_MAX_BUFS 2                   /*Number of YUV buffers per surface */
 typedef struct _i915XvMCSurface {
-    unsigned srfNo;                    /* XvMC private surface numbers */
-    unsigned last_render;
-    unsigned last_flip;
-    unsigned yStride;                  /* Stride of YUV420 Y component. */
-    unsigned uvStride;
-    unsigned width;                    /* Dimensions */
-    unsigned height;
+    unsigned int srfNo;                    /* XvMC private surface numbers */
+    unsigned int last_render;
+    unsigned int last_flip;
+    unsigned int yStride;                  /* Stride of YUV420 Y component. */
+    unsigned int uvStride;
+    unsigned int width;                    /* Dimensions */
+    unsigned int height;
     i915XvMCDrmMap srf;
     i915XvMCContext *privContext;
     i915XvMCSubpicture *privSubPic;     /* Subpicture to be blended when
diff-tree cfc614b1f9143ed1407733aaa81c4a980c613a63 (from b29a932bec2a3cc5a38e9c09c012cfdc1b6209c1)
Author: Zhenyu Wang <zhenyu.z.wang at intel.com>
Date:   Wed Aug 8 09:06:47 2007 +0800

    remove xvmc attributes
    
    We don't have extra attributes than Xv port.

diff --git a/src/i830_video.h b/src/i830_video.h
index 67022f6..7e2d149 100644
--- a/src/i830_video.h
+++ b/src/i830_video.h
@@ -77,7 +77,6 @@ typedef struct {
    int oneLineMode;
    int scaleRatio;
    Bool textured;
-   void *xvmc_priv;
 } I830PortPrivRec, *I830PortPrivPtr;
 
 #define GET_PORT_PRIVATE(pScrn) \
diff --git a/src/i915_hwmc.c b/src/i915_hwmc.c
index 19e2b34..79fe284 100644
--- a/src/i915_hwmc.c
+++ b/src/i915_hwmc.c
@@ -57,31 +57,6 @@
 
 #include "i915_hwmc.h"
 
-#define MAKE_ATOM(a) MakeAtom(a, strlen(a), TRUE)
-
-/*
- * List Attributes for the XvMC extension to handle:
- * As long as the attribute is supported by the Xv adaptor, it needs only to
- * be added here to be supported also by XvMC.
- */
-static char *attrXvMC[I915_NUM_XVMC_ATTRIBUTES] = { 
-    "XV_BRIGHTNESS",
-    "XV_CONTRAST",
-};
-static Atom attrAtoms[I915_NUM_XVMC_ATTRIBUTES];
-
-typedef struct
-{
-    unsigned ctxDisplaying;
-    int xvmc_port;
-    I915XvMCAttrHolder xvAttr;
-    int newAttribute;
-
-    SetPortAttributeFuncPtr SetPortAttribute;
-    GetPortAttributeFuncPtr GetPortAttribute;
-    PutImageFuncPtr PutImage;
-} I915XvMCXVPriv;
-
 #define I915_XVMC_MAX_BUFFERS 2
 #define I915_XVMC_MAX_CONTEXTS 4
 #define I915_XVMC_MAX_SURFACES 20
@@ -484,9 +459,6 @@ static int I915XvMCCreateContext (ScrnIn
     I915XvMCCreateContextRec *contextRec = NULL;
     I915XvMCPtr pXvMC = pI830->xvmc;
     I915XvMCContextPriv *ctxpriv = NULL;
-    XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)pContext->port_priv;
-    I830PortPrivPtr pPriv = (I830PortPrivPtr)portPriv->DevPriv.ptr;
-    I915XvMCXVPriv *vx = (I915XvMCXVPriv *)pPriv->xvmc_priv;
     int i;
 
     *priv = NULL;
@@ -583,7 +555,6 @@ static int I915XvMCCreateContext (ScrnIn
     contextRec->screen = pScrn->pScreen->myNum;
     contextRec->depth = pScrn->bitsPerPixel;
     contextRec->deviceID = pI830DRI->deviceID;
-    contextRec->initAttrs = vx->xvAttr;
 
     pXvMC->ncontexts++;
     pXvMC->contexts[i] = pContext->context_id;
@@ -828,70 +799,7 @@ static void I915XvMCDestroySubpicture (S
     return;
 }
 
-/*
- *
- */
-static int I915XvMCInterceptXvGetAttribute(ScrnInfoPtr pScrn, Atom attribute,
-                                           INT32 * value, pointer data)
-{
-    unsigned i;
-    I830PortPrivPtr pPriv = (I830PortPrivPtr)data;
-    I915XvMCXVPriv *vx = (I915XvMCXVPriv *)pPriv->xvmc_priv;
-    I830Ptr pI830 = I830PTR(pScrn);
-    I915XvMCPtr pXvMC = pI830->xvmc;
-
-    if (I830PTR(pScrn)->XvMCEnabled) {
-        for (i = 0; i < vx->xvAttr.numAttr; ++i) {
-            if (vx->xvAttr.attributes[i].attribute == attribute) {
-                *value = vx->xvAttr.attributes[i].value;
-                return Success;
-            }
-        }
-    }
-
-    return pXvMC->saveGetPortAttribute(pScrn, attribute, value, data);
-}
-
-static int I915XvMCInterceptXvAttribute(ScrnInfoPtr pScrn, Atom attribute,
-                                        INT32 value, pointer data)
-{
-    unsigned i;
-    I830PortPrivPtr pPriv = (I830PortPrivPtr)data;
-    I915XvMCXVPriv *vx = (I915XvMCXVPriv *)pPriv->xvmc_priv;
-    I830Ptr pI830 = I830PTR(pScrn);
-    I915XvMCPtr pXvMC = pI830->xvmc;
-
-    if (pI830->XvMCEnabled) {
-        for (i = 0; i < vx->xvAttr.numAttr; ++i) {
-            if (vx->xvAttr.attributes[i].attribute == attribute) {
-                vx->xvAttr.attributes[i].value = value;
-                return Success;
-            }
-        }
-    }
-
-    return pXvMC->saveSetPortAttribute(pScrn, attribute, value, data);
-}
-
-static int I915XvMCDisplayAttributes(ScrnInfoPtr pScrn,
-                                     const I915XvMCAttrHolder * ah, I830PortPrivPtr pPriv)
-{
-    I830Ptr pI830 = I830PTR(pScrn);
-    I915XvMCPtr pXvMC = pI830->xvmc;
-    unsigned i;
-    int ret;
-
-    for (i = 0; i < ah->numAttr; ++i) {
-        ret = pXvMC->saveSetPortAttribute(pScrn, ah->attributes[i].attribute,
-                                   ah->attributes[i].value, pPriv);
-        if (ret)
-            return ret;
-    }
-
-    return Success;
-}
-
-static int I915XvMCInterceptPutImage(ScrnInfoPtr pScrn, short src_x, short src_y,
+static int I915XvMCPutImage(ScrnInfoPtr pScrn, short src_x, short src_y,
                                      short drw_x, short drw_y, short src_w,
                                      short src_h, short drw_w, short drw_h,
                                      int id, unsigned char *buf, short width,
@@ -899,8 +807,6 @@ static int I915XvMCInterceptPutImage(Scr
                                      DrawablePtr pDraw)
 {
     I830Ptr pI830 = I830PTR(pScrn);
-    I830PortPrivPtr pPriv = (I830PortPrivPtr)data;
-    I915XvMCXVPriv *vx = (I915XvMCXVPriv *)pPriv->xvmc_priv;
     I915XvMCPtr pXvMC = pI830->xvmc;
     I915XvMCCommandBuffer *i915XvMCData = (I915XvMCCommandBuffer *)buf;
     int ret;
@@ -908,19 +814,12 @@ static int I915XvMCInterceptPutImage(Scr
     if (pI830->XvMCEnabled) {
         if (FOURCC_XVMC == id) {
             switch (i915XvMCData->command) {
-            case I915_XVMC_COMMAND_ATTRIBUTES:
-                if ((i915XvMCData->ctxNo | I915_XVMC_VALID) != vx->ctxDisplaying)
-                    return 1;
-
-                I915XvMCDisplayAttributes(pScrn, &i915XvMCData->attrib, pPriv);
-                return 0;
-
             case I915_XVMC_COMMAND_DISPLAY:
 		if ((i915XvMCData->srfNo >= I915_XVMC_MAX_SURFACES) ||
 			!pXvMC->surfaces[i915XvMCData->srfNo] ||
 			!pXvMC->sfprivs[i915XvMCData->srfNo]) {
 		    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-			    "[XvMC] I915XvMCInterceptPutImage: Invalid parameters !\n");
+			    "[XvMC] I915XvMCPutImage: Invalid parameters !\n");
 		    return 1;
 		}
                    
@@ -958,10 +857,7 @@ Bool I915XvMCInit(ScreenPtr pScreen, XF8
 {
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
     I830Ptr pI830 = I830PTR(pScrn);
-    I830PortPrivPtr pPriv;
-    I915XvMCXVPriv *vx;
     I915XvMCPtr pXvMC;
-    int i, j;
 
     if (!IS_I9XX(pI830) || IS_I965G(pI830))
 	return FALSE;
@@ -975,38 +871,9 @@ Bool I915XvMCInit(ScreenPtr pScreen, XF8
     pI830->xvmc = pXvMC;
     initI915XvMC(pXvMC);
 
-    for (j = 0; j < XvAdapt->nPorts; ++j) {
-        pPriv = (I830PortPrivPtr) XvAdapt->pPortPrivates[j].ptr;
-
-        if (NULL == (pPriv->xvmc_priv = xcalloc(1, sizeof(I915XvMCXVPriv)))) {
-	    xfree(pI830->xvmc);
-            return BadAlloc;
-	}
-
-        for (i = 0; i < I915_NUM_XVMC_ATTRIBUTES; ++i)
-            attrAtoms[i] = MAKE_ATOM(attrXvMC[i]);
-
-        vx = (I915XvMCXVPriv *) pPriv->xvmc_priv;
-
-        vx->ctxDisplaying = 0;
-        vx->xvAttr.numAttr = I915_NUM_XVMC_ATTRIBUTES;
-        vx->xvmc_port = -1;
-        vx->newAttribute = 1;
-
-        for (i = 0; i < I915_NUM_XVMC_ATTRIBUTES; ++i) {
-            vx->xvAttr.attributes[i].attribute = attrAtoms[i];
-            XvAdapt->GetPortAttribute(pScrn, attrAtoms[i],
-                                 &(vx->xvAttr.attributes[i].value), pPriv);
-        }
-    }
     /* set up wrappers */
-    pXvMC->saveGetPortAttribute = XvAdapt->GetPortAttribute;
-    pXvMC->saveSetPortAttribute = XvAdapt->SetPortAttribute;
     pXvMC->savePutImage = XvAdapt->PutImage;
-
-    XvAdapt->GetPortAttribute = I915XvMCInterceptXvGetAttribute;
-    XvAdapt->SetPortAttribute = I915XvMCInterceptXvAttribute;
-    XvAdapt->PutImage = I915XvMCInterceptPutImage;
+    XvAdapt->PutImage = I915XvMCPutImage;
     return TRUE;
 }
 
diff --git a/src/i915_hwmc.h b/src/i915_hwmc.h
index 529636e..61c7c4b 100644
--- a/src/i915_hwmc.h
+++ b/src/i915_hwmc.h
@@ -44,19 +44,6 @@
 
 #define I915_XVMC_COMMAND_DISPLAY      0x00
 #define I915_XVMC_COMMAND_UNDISPLAY    0x01
-#define I915_XVMC_COMMAND_ATTRIBUTES   0x02
-
-typedef struct
-{
-    INT32 attribute;
-    INT32 value;
-} I915AttrPair;
-
-typedef struct
-{
-    unsigned numAttr;
-    I915AttrPair attributes[I915_NUM_XVMC_ATTRIBUTES];
-} I915XvMCAttrHolder;
 
 typedef struct
 {
@@ -64,7 +51,6 @@ typedef struct
     unsigned ctxNo;
     unsigned srfNo;
     unsigned subPicNo;
-    I915XvMCAttrHolder attrib;
     int real_id;
     unsigned pad;
 } I915XvMCCommandBuffer;
@@ -92,7 +78,6 @@ typedef struct 
     unsigned screen;
     unsigned depth;
     int deviceID;
-    I915XvMCAttrHolder initAttrs;
 } I915XvMCCreateContextRec;
 
 typedef struct 
diff --git a/src/xvmc/I915XvMC.c b/src/xvmc/I915XvMC.c
index 3eb0bc3..7040f6a 100644
--- a/src/xvmc/I915XvMC.c
+++ b/src/xvmc/I915XvMC.c
@@ -122,45 +122,6 @@ _STATIC_ int findOverlap(unsigned width,
     return 0;
 }
 
-_STATIC_ void setupAttribDesc(Display * display, XvPortID port,
-                            const I915XvMCAttrHolder * attrib, XvAttribute attribDesc[])
-{  
-    XvAttribute *XvAttribs, *curAD;
-    int num;
-    unsigned i, j;
-
-    XLockDisplay(display);
-    XvAttribs = XvQueryPortAttributes(display, port, &num);
-    for (i = 0; i < attrib->numAttr; ++i) {
-        curAD = attribDesc + i;
-        curAD->flags = 0;
-        curAD->min_value = 0;
-        curAD->max_value = 0;
-        curAD->name = NULL;
-        for (j = 0; j < num; ++j) {
-            if (attrib->attributes[i].attribute ==
-                XInternAtom(display, XvAttribs[j].name, TRUE)) {
-                *curAD = XvAttribs[j];
-                curAD->name = strdup(XvAttribs[j].name);
-                break;
-            }
-        }
-    }
-    if (XvAttribs)
-        XFree(XvAttribs);
-    XUnlockDisplay(display);
-}
-
-_STATIC_ void releaseAttribDesc(int numAttr, XvAttribute attribDesc[])
-{
-    int i;
-
-    for (i = 0; i < numAttr; ++i) {
-        if (attribDesc[i].name)
-            free(attribDesc[i].name);
-    }
-}
-
 _STATIC_ __inline__ void renderError(void) 
 {
     printf("Invalid Macroblock Parameters found.\n");
@@ -1747,7 +1708,6 @@ _STATIC_ void i915_release_resource(Disp
 
     pI915XvMC->ref--;
     i915_xvmc_unmap_buffers(pI915XvMC);
-    releaseAttribDesc(pI915XvMC->attrib.numAttr, pI915XvMC->attribDesc);
 
     driDestroyHashContents(pI915XvMC->drawHash);
     drmHashDestroy(pI915XvMC->drawHash);
@@ -1934,7 +1894,6 @@ Status XvMCCreateContext(Display *displa
     pI915XvMC->sarea_priv_offset = tmpComm->sarea_priv_offset;
     pI915XvMC->screen = tmpComm->screen;
     pI915XvMC->depth = tmpComm->depth;
-    pI915XvMC->attrib = tmpComm->initAttrs;
 
     /* Must free the private data we were passed from X */
     free(priv_data);
@@ -2047,11 +2006,9 @@ Status XvMCCreateContext(Display *displa
     }
 
     /* Initialize private context values */
-    setupAttribDesc(display, port, &pI915XvMC->attrib, pI915XvMC->attribDesc);
     pI915XvMC->yStride = STRIDE(width);
     pI915XvMC->uvStride = STRIDE(width >> 1);
     pI915XvMC->haveXv = 0;
-    pI915XvMC->attribChanged = 1;
     pI915XvMC->dual_prime = 0;
     pI915XvMC->last_flip = 0;
     pI915XvMC->locked = 0;
@@ -2582,7 +2539,6 @@ Status XvMCPutSurface(Display *display,X
     buf.srfNo = pI915Surface->srfNo;
     pI915SubPic = pI915Surface->privSubPic;
     buf.subPicNo = (!pI915SubPic ? 0 : pI915SubPic->srfNo);
-    buf.attrib = pI915XvMC->attrib;
     buf.real_id = FOURCC_YV12;
 
     XLockDisplay(display);
@@ -2598,7 +2554,6 @@ Status XvMCPutSurface(Display *display,X
 
     XSync(display, 0);
     XUnlockDisplay(display);
-    pI915XvMC->attribChanged = 0;
     PPTHREAD_MUTEX_UNLOCK(pI915XvMC);
 
     return Success;
@@ -3302,29 +3257,9 @@ Status XvMCGetSubpictureStatus(Display *
 XvAttribute *XvMCQueryAttributes(Display *display, XvMCContext *context,
                                  int *number) 
 {
-    i915XvMCContext *pI915XvMC;
-    XvAttribute *attributes;
-
-    if (!number)
-        return NULL;
-
+    /* now XvMC has no extra attribs than Xv */
     *number = 0;
-
-    if (!display || !context)
-        return NULL;
-
-    if (!(pI915XvMC = context->privData))
-        return NULL;
-
-    PPTHREAD_MUTEX_LOCK(pI915XvMC);
-    if (NULL != (attributes = (XvAttribute *)
-                 malloc(I915_NUM_XVMC_ATTRIBUTES * sizeof(XvAttribute)))) {
-        memcpy(attributes, pI915XvMC->attribDesc, I915_NUM_XVMC_ATTRIBUTES);
-        *number = I915_NUM_XVMC_ATTRIBUTES;
-    }
-    PPTHREAD_MUTEX_UNLOCK(pI915XvMC);
-
-    return attributes;
+    return NULL;
 }
 
 /***************************************************************************
@@ -3343,52 +3278,6 @@ XvAttribute *XvMCQueryAttributes(Display
 Status XvMCSetAttribute(Display *display, XvMCContext *context,
                         Atom attribute, int value)
 {
-    i915XvMCContext *pI915XvMC;
-    I915XvMCCommandBuffer buf;
-    int found = 0;
-    unsigned i;
-
-    if (!display)
-        return BadValue;
-
-    if (!context || !(pI915XvMC = context->privData))
-        return (error_base + XvMCBadContext);
-
-    PPTHREAD_MUTEX_LOCK(pI915XvMC);
-    for (i = 0; i < pI915XvMC->attrib.numAttr; ++i) {
-        if (attribute == pI915XvMC->attrib.attributes[i].attribute) {
-            if ((!(pI915XvMC->attribDesc[i].flags & XvSettable)) ||
-                value < pI915XvMC->attribDesc[i].min_value ||
-                value > pI915XvMC->attribDesc[i].max_value) {
-                PPTHREAD_MUTEX_UNLOCK(pI915XvMC);
-                return BadValue;
-            }
-
-            pI915XvMC->attrib.attributes[i].value = value;
-            found = 1;
-            pI915XvMC->attribChanged = 1;
-            break;
-        }
-    }
-
-    if (!found) {
-        PPTHREAD_MUTEX_UNLOCK(pI915XvMC);
-        return BadMatch;
-    }
-
-    if (pI915XvMC->haveXv) {
-        buf.command = I915_XVMC_COMMAND_ATTRIBUTES;
-        pI915XvMC->xvImage->data = (char *)&buf;
-        buf.ctxNo = pI915XvMC->ctxno | I915_XVMC_VALID;
-        buf.attrib = pI915XvMC->attrib;
-        XLockDisplay(display);
-        pI915XvMC->attribChanged =
-            XvPutImage(display, pI915XvMC->port, pI915XvMC->draw,
-                       pI915XvMC->gc, pI915XvMC->xvImage, 0, 0, 1, 1, 0, 0, 1, 1);
-        XUnlockDisplay(display);
-    }
-
-    PPTHREAD_MUTEX_UNLOCK(pI915XvMC);
     return Success;
 }
 
@@ -3410,30 +3299,5 @@ Status XvMCSetAttribute(Display *display
 Status XvMCGetAttribute(Display *display, XvMCContext *context,
                         Atom attribute, int *value) 
 {
-    i915XvMCContext *pI915XvMC;
-    int found = 0;
-    unsigned i;
-
-    if (!display || !value)
-        return BadValue;
-
-    if (!context || !(pI915XvMC = context->privData))
-        return (error_base + XvMCBadContext);
-
-    PPTHREAD_MUTEX_LOCK(pI915XvMC);
-    for (i = 0; i < pI915XvMC->attrib.numAttr; ++i) {
-        if (attribute == pI915XvMC->attrib.attributes[i].attribute) {
-            if (pI915XvMC->attribDesc[i].flags & XvGettable) {
-                *value = pI915XvMC->attrib.attributes[i].value;
-                found = 1;
-                break;
-            }
-        }
-    }
-    PPTHREAD_MUTEX_UNLOCK(pI915XvMC);
-
-    if (!found)
-        return BadMatch;
-    
     return Success;
 }
diff --git a/src/xvmc/I915XvMC.h b/src/xvmc/I915XvMC.h
index 4fc9fc5..3a83edc 100644
--- a/src/xvmc/I915XvMC.h
+++ b/src/xvmc/I915XvMC.h
@@ -89,15 +89,10 @@ typedef struct _i915XvMCContext {
     unsigned screen;
     unsigned depth;
     XvPortID port;		       /* Xv Port ID when displaying */
-    I915XvMCAttrHolder attrib;          /* This contexts attributes and their values */
-    XvAttribute attribDesc[I915_NUM_XVMC_ATTRIBUTES];    /* Attribute decriptions */
     int haveXv;                        /* Have I initialized the Xv
                                         * connection for this surface? */
     XvImage *xvImage;                  /* Fake Xv Image used for command
                                         * buffer transport to the X server */
-    int attribChanged;                 /* Attributes have changed and need to
-                                        * be uploaded to Xv at next frame
-                                        * display */
     GC  gc;                            /* X GC needed for displaying */
     Drawable draw;                     /* Drawable to undisplay from */
     XID id;
diff-tree b29a932bec2a3cc5a38e9c09c012cfdc1b6209c1 (from c4deefa80a6349db968e25bd6778cdf7a514ca7f)
Author: Zhenyu Wang <zhenyu.z.wang at intel.com>
Date:   Tue Aug 7 16:47:13 2007 +0800

    code cleanups
    
    and put wrap function in driver xvmc priv instead of per xv port priv

diff --git a/src/i830.h b/src/i830.h
index de37749..a792f38 100644
--- a/src/i830.h
+++ b/src/i830.h
@@ -746,8 +746,8 @@ static inline int i830_fb_compression_su
 }
 
 /* i915 XvMC */
-int I915XvMCInitXv(ScrnInfoPtr, XF86VideoAdaptorPtr);
-void I915InitMC(ScreenPtr);
+Bool I915XvMCInit(ScreenPtr, XF86VideoAdaptorPtr);
+Bool I915XvMCScreenInit(ScreenPtr);
 unsigned long I915XvMCPutImageSize(ScrnInfoPtr);
 
 extern const int I830PatternROP[16];
diff --git a/src/i830_driver.c b/src/i830_driver.c
index b617bd4..7957e26 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -2721,14 +2721,6 @@ I830ScreenInit(int scrnIndex, ScreenPtr 
       pI830->directRenderingEnabled = I830DRIFinishScreenInit(pScreen);
    }
 
-#ifdef XvMCExtension
-   if (pI830->XvEnabled && (pI830->directRenderingEnabled) && 
-       (IS_I915G(pI830) || IS_I915GM(pI830) || 
-        IS_I945G(pI830) || IS_I945GM(pI830) ||
-        IS_G33CLASS(pI830))) {
-       I915InitMC(pScreen);
-   }
-#endif
 #endif
 
    /* Setup 3D engine, needed for rotation too */
diff --git a/src/i830_video.c b/src/i830_video.c
index 4ee9f76..ed68104 100644
--- a/src/i830_video.c
+++ b/src/i830_video.c
@@ -560,6 +560,7 @@ I830InitVideo(ScreenPtr pScreen)
     XF86VideoAdaptorPtr *adaptors, *newAdaptors = NULL;
     XF86VideoAdaptorPtr overlayAdaptor = NULL, texturedAdaptor = NULL;
     int num_adaptors;
+    Bool xvmc_init = FALSE;
 
 #if 0
     {
@@ -602,16 +603,6 @@ I830InitVideo(ScreenPtr pScreen)
 	if (texturedAdaptor != NULL) {
 	    adaptors[num_adaptors++] = texturedAdaptor;
 	    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Set up textured video\n");
-
-#ifdef XF86DRI
-#ifdef XvMCExtension
-        if (IS_I915G(pI830) || IS_I915GM(pI830) || 
-            IS_I945G(pI830) || IS_I945GM(pI830) ||
-            IS_G33CLASS(pI830)) {
-               I915XvMCInitXv(pScrn, texturedAdaptor);
-        }
-#endif
-#endif
 	} else {
 	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 		       "Failed to set up textured video\n");
@@ -633,10 +624,18 @@ I830InitVideo(ScreenPtr pScreen)
 	I830InitOffscreenImages(pScreen);
     }
 
+#ifdef XvMCExtension
+    if (texturedAdaptor)
+	xvmc_init = I915XvMCInit(pScreen, texturedAdaptor);
+#endif
     if (num_adaptors)
 	xf86XVScreenInit(pScreen, adaptors, num_adaptors);
 
     xfree(adaptors);
+#ifdef XvMCExtension
+    if (xvmc_init)
+	I915XvMCScreenInit(pScreen);
+#endif
 }
 
 static void
@@ -2631,11 +2630,7 @@ I830QueryImageAttributes(ScrnInfoPtr pSc
 	break;
     case FOURCC_XVMC:
         *h = (*h + 1) & ~1;
-#ifdef XF86DRI
         size = I915XvMCPutImageSize(pScrn);
-#else
-        size = 0;
-#endif
         if (pitches)
             pitches[0] = size;
         break;
diff --git a/src/i915_hwmc.c b/src/i915_hwmc.c
index 158b7b8..19e2b34 100644
--- a/src/i915_hwmc.c
+++ b/src/i915_hwmc.c
@@ -118,6 +118,9 @@ typedef struct _I915XvMC 
     I915XvMCSurfacePriv *sfprivs[I915_XVMC_MAX_SURFACES];
     I915XvMCContextPriv *ctxprivs[I915_XVMC_MAX_CONTEXTS];
     int ncontexts,nsurfaces;
+    SetPortAttributeFuncPtr saveSetPortAttribute;
+    GetPortAttributeFuncPtr saveGetPortAttribute;
+    PutImageFuncPtr savePutImage;
 } I915XvMC, *I915XvMCPtr;
 
 #define ARRARY_SIZE(a) (sizeof(a) / sizeof(a[0]))
@@ -234,6 +237,7 @@ static void initI915XvMC(I915XvMCPtr xvm
     }
 }
 
+//XXX
 static void cleanupI915XvMC(I915XvMCPtr xvmc, XF86VideoAdaptorPtr * XvAdaptors, int XvAdaptorCount)
 {
     unsigned int i;
@@ -483,15 +487,14 @@ static int I915XvMCCreateContext (ScrnIn
     XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)pContext->port_priv;
     I830PortPrivPtr pPriv = (I830PortPrivPtr)portPriv->DevPriv.ptr;
     I915XvMCXVPriv *vx = (I915XvMCXVPriv *)pPriv->xvmc_priv;
-
     int i;
 
     *priv = NULL;
     *num_priv = 0;
 
-    if (!pI830->directRenderingEnabled) {
+    if (!pI830->XvMCEnabled) {
         xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-                   "[XvMC] I915XvMCCreateContext: Cannot use XvMC without DRI!\n");
+                   "[XvMC] I915XvMCCreateContext: Cannot use XvMC!\n");
         return BadAlloc;
     }
 
@@ -834,6 +837,8 @@ static int I915XvMCInterceptXvGetAttribu
     unsigned i;
     I830PortPrivPtr pPriv = (I830PortPrivPtr)data;
     I915XvMCXVPriv *vx = (I915XvMCXVPriv *)pPriv->xvmc_priv;
+    I830Ptr pI830 = I830PTR(pScrn);
+    I915XvMCPtr pXvMC = pI830->xvmc;
 
     if (I830PTR(pScrn)->XvMCEnabled) {
         for (i = 0; i < vx->xvAttr.numAttr; ++i) {
@@ -844,7 +849,7 @@ static int I915XvMCInterceptXvGetAttribu
         }
     }
 
-    return vx->GetPortAttribute(pScrn, attribute, value, data);
+    return pXvMC->saveGetPortAttribute(pScrn, attribute, value, data);
 }
 
 static int I915XvMCInterceptXvAttribute(ScrnInfoPtr pScrn, Atom attribute,
@@ -853,8 +858,10 @@ static int I915XvMCInterceptXvAttribute(
     unsigned i;
     I830PortPrivPtr pPriv = (I830PortPrivPtr)data;
     I915XvMCXVPriv *vx = (I915XvMCXVPriv *)pPriv->xvmc_priv;
+    I830Ptr pI830 = I830PTR(pScrn);
+    I915XvMCPtr pXvMC = pI830->xvmc;
 
-    if (I830PTR(pScrn)->XvMCEnabled) {
+    if (pI830->XvMCEnabled) {
         for (i = 0; i < vx->xvAttr.numAttr; ++i) {
             if (vx->xvAttr.attributes[i].attribute == attribute) {
                 vx->xvAttr.attributes[i].value = value;
@@ -863,18 +870,19 @@ static int I915XvMCInterceptXvAttribute(
         }
     }
 
-    return vx->SetPortAttribute(pScrn, attribute, value, data);
+    return pXvMC->saveSetPortAttribute(pScrn, attribute, value, data);
 }
 
 static int I915XvMCDisplayAttributes(ScrnInfoPtr pScrn,
                                      const I915XvMCAttrHolder * ah, I830PortPrivPtr pPriv)
 {
-    I915XvMCXVPriv *vx = (I915XvMCXVPriv *) pPriv->xvmc_priv;
+    I830Ptr pI830 = I830PTR(pScrn);
+    I915XvMCPtr pXvMC = pI830->xvmc;
     unsigned i;
     int ret;
 
     for (i = 0; i < ah->numAttr; ++i) {
-        ret = vx->SetPortAttribute(pScrn, ah->attributes[i].attribute,
+        ret = pXvMC->saveSetPortAttribute(pScrn, ah->attributes[i].attribute,
                                    ah->attributes[i].value, pPriv);
         if (ret)
             return ret;
@@ -893,14 +901,12 @@ static int I915XvMCInterceptPutImage(Scr
     I830Ptr pI830 = I830PTR(pScrn);
     I830PortPrivPtr pPriv = (I830PortPrivPtr)data;
     I915XvMCXVPriv *vx = (I915XvMCXVPriv *)pPriv->xvmc_priv;
+    I915XvMCPtr pXvMC = pI830->xvmc;
+    I915XvMCCommandBuffer *i915XvMCData = (I915XvMCCommandBuffer *)buf;
     int ret;
 
-    if (I830PTR(pScrn)->XvMCEnabled) {
+    if (pI830->XvMCEnabled) {
         if (FOURCC_XVMC == id) {
-            I915XvMCPtr pXvMC = pI830->xvmc;
-            I915XvMCCommandBuffer *i915XvMCData = (I915XvMCCommandBuffer *)buf;
-            int i;
-
             switch (i915XvMCData->command) {
             case I915_XVMC_COMMAND_ATTRIBUTES:
                 if ((i915XvMCData->ctxNo | I915_XVMC_VALID) != vx->ctxDisplaying)
@@ -910,33 +916,25 @@ static int I915XvMCInterceptPutImage(Scr
                 return 0;
 
             case I915_XVMC_COMMAND_DISPLAY:
-                for (i = 0; i < I915_XVMC_MAX_SURFACES; i++) {
-                   i830_memory *mem = NULL;
-
-                   if ((i915XvMCData->srfNo >= I915_XVMC_MAX_SURFACES) ||
-                       !pXvMC->surfaces[i915XvMCData->srfNo] ||
-                       !pXvMC->sfprivs[i915XvMCData->srfNo]) {
-                      xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-                                 "[XvMC] I915XvMCInterceptPutImage: Invalid parameters !\n");
-                      return 1;
-                   }
+		if ((i915XvMCData->srfNo >= I915_XVMC_MAX_SURFACES) ||
+			!pXvMC->surfaces[i915XvMCData->srfNo] ||
+			!pXvMC->sfprivs[i915XvMCData->srfNo]) {
+		    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+			    "[XvMC] I915XvMCInterceptPutImage: Invalid parameters !\n");
+		    return 1;
+		}
                    
-                   mem = pXvMC->sfprivs[i915XvMCData->srfNo]->surface;
-                   buf = pI830->FbBase + mem->offset;
-                   id = i915XvMCData->real_id;
-                   pI830->IsXvMCSurface = 1;
-                   break;
-                }
-
-                break;
-
+		buf = pI830->FbBase + pXvMC->sfprivs[i915XvMCData->srfNo]->surface->offset;
+		id = i915XvMCData->real_id;
+		pI830->IsXvMCSurface = 1;
+		break;
             default:
                 return 0;
             }
         }
     }
 
-    ret = vx->PutImage(pScrn, src_x, src_y, drw_x, drw_y, src_w, src_h,
+    ret = pXvMC->savePutImage(pScrn, src_x, src_y, drw_x, drw_y, src_w, src_h,
                         drw_w, drw_h, id, buf, width, height, sync, clipBoxes, data, pDraw);
     pI830->IsXvMCSurface = 0;
     return ret;
@@ -955,57 +953,38 @@ static int I915XvMCInterceptPutImage(Scr
  *    None
  *  
  **************************************************************************/
-void I915InitMC(ScreenPtr pScreen)
+
+Bool I915XvMCInit(ScreenPtr pScreen, XF86VideoAdaptorPtr XvAdapt)
 {
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
     I830Ptr pI830 = I830PTR(pScrn);
-    I915XvMCPtr pXvMC = NULL; 
+    I830PortPrivPtr pPriv;
+    I915XvMCXVPriv *vx;
+    I915XvMCPtr pXvMC;
+    int i, j;
 
-    pI830->XvMCEnabled = FALSE;
-    if (!pI830->directRenderingEnabled) {
-        xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
-                   "[XvMC] Cannot use XvMC without DRI!\n");
-        return;
-    }
+    if (!IS_I9XX(pI830) || IS_I965G(pI830))
+	return FALSE;
 
-    pXvMC = (I915XvMCPtr)calloc(1, sizeof(I915XvMC));
+    pXvMC = (I915XvMCPtr)xcalloc(1, sizeof(I915XvMC));
     if (!pXvMC) {
         xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
-                   "[XvMC] Failure!\n");
-        return;
+                   "[XvMC] alloc driver private failed!\n");
+        return FALSE;
     }
-
     pI830->xvmc = pXvMC;
     initI915XvMC(pXvMC);
-    xf86XvMCScreenInit(pScreen, 1, ppAdapt);
-    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
-               "[XvMC] Initialized XvMC extension.\n");
-    pI830->XvMCEnabled = TRUE;
-}
-
-int I915XvMCInitXv(ScrnInfoPtr pScrn, XF86VideoAdaptorPtr XvAdapt)
-{
-    I830PortPrivPtr pPriv;
-    I915XvMCXVPriv *vx;
-    unsigned i, j;
-    SetPortAttributeFuncPtr setportattribute = XvAdapt->SetPortAttribute;
-    GetPortAttributeFuncPtr getportattribute = XvAdapt->GetPortAttribute;
-    PutImageFuncPtr putimage = XvAdapt->PutImage;
-
-    XvAdapt->GetPortAttribute = I915XvMCInterceptXvGetAttribute;
-    XvAdapt->SetPortAttribute = I915XvMCInterceptXvAttribute;
-    XvAdapt->PutImage = I915XvMCInterceptPutImage;
 
     for (j = 0; j < XvAdapt->nPorts; ++j) {
         pPriv = (I830PortPrivPtr) XvAdapt->pPortPrivates[j].ptr;
 
         if (NULL == (pPriv->xvmc_priv = xcalloc(1, sizeof(I915XvMCXVPriv)))) {
+	    xfree(pI830->xvmc);
             return BadAlloc;
-        }
+	}
 
-        for (i = 0; i < I915_NUM_XVMC_ATTRIBUTES; ++i) {
+        for (i = 0; i < I915_NUM_XVMC_ATTRIBUTES; ++i)
             attrAtoms[i] = MAKE_ATOM(attrXvMC[i]);
-        }
 
         vx = (I915XvMCXVPriv *) pPriv->xvmc_priv;
 
@@ -1014,24 +993,48 @@ int I915XvMCInitXv(ScrnInfoPtr pScrn, XF
         vx->xvmc_port = -1;
         vx->newAttribute = 1;
 
-        /* set up wrappers */
-        vx->GetPortAttribute = getportattribute;
-        vx->SetPortAttribute = setportattribute;
-        vx->PutImage = putimage;
-
         for (i = 0; i < I915_NUM_XVMC_ATTRIBUTES; ++i) {
             vx->xvAttr.attributes[i].attribute = attrAtoms[i];
-            vx->xvAttr.attributes[i].value = 0;
-            vx->GetPortAttribute(pScrn, attrAtoms[i],
+            XvAdapt->GetPortAttribute(pScrn, attrAtoms[i],
                                  &(vx->xvAttr.attributes[i].value), pPriv);
         }
     }
-    return Success;
+    /* set up wrappers */
+    pXvMC->saveGetPortAttribute = XvAdapt->GetPortAttribute;
+    pXvMC->saveSetPortAttribute = XvAdapt->SetPortAttribute;
+    pXvMC->savePutImage = XvAdapt->PutImage;
+
+    XvAdapt->GetPortAttribute = I915XvMCInterceptXvGetAttribute;
+    XvAdapt->SetPortAttribute = I915XvMCInterceptXvAttribute;
+    XvAdapt->PutImage = I915XvMCInterceptPutImage;
+    return TRUE;
+}
+
+Bool I915XvMCScreenInit(ScreenPtr pScreen)
+{
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    I830Ptr pI830 = I830PTR(pScrn);
+
+    if (xf86XvMCScreenInit(pScreen, 1, ppAdapt)) {
+	xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+		"[XvMC] Initialized XvMC.\n");
+	pI830->XvMCEnabled = TRUE;
+    } else {
+        xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
+		"[XvMC] xf86 XvMC initial failed\n");
+	pI830->XvMCEnabled = FALSE;
+	xfree(pI830->xvmc);
+	pI830->xvmc = NULL;
+	return FALSE;
+    }
+    return TRUE;
 }
 
 unsigned long I915XvMCPutImageSize(ScrnInfoPtr pScrn)
 {
-    if (I830PTR(pScrn)->XvMCEnabled)
+    I830Ptr pI830 = I830PTR(pScrn);
+
+    if (pI830->XvMCEnabled)
         return sizeof(I915XvMCCommandBuffer);
 
     return 0;


More information about the xorg-commit mailing list