summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiang, Haihao <haihao.xiang@intel.com>2007-07-16 13:03:58 +0800
committerXiang, Haihao <haihao.xiang@intel.com>2007-07-19 17:28:35 +0800
commit25658f838bd1bcd7559d7a032d127c626833fb7c (patch)
tree0e3284e9dfe7e35bee3d2f21ae5a44d9f61c3712
parent8f316a4584d0676e5dae051698bde0831f018cc4 (diff)
1. The pitches for y/u/v surfaces are 1024bytes aligned.
2. clean code
-rw-r--r--src/i830.h3
-rw-r--r--src/i830_video.c10
-rw-r--r--src/i915_hwmc.c47
-rw-r--r--src/i915_hwmc.h6
-rw-r--r--src/xvmc/I915XvMC.c188
-rw-r--r--src/xvmc/I915XvMC.h2
6 files changed, 73 insertions, 183 deletions
diff --git a/src/i830.h b/src/i830.h
index cde15ad6..de377499 100644
--- a/src/i830.h
+++ b/src/i830.h
@@ -313,7 +313,8 @@ typedef struct _I830Rec {
/* For XvMC */
void *xvmc;
Bool XvMCEnabled;
-
+ Bool IsXvMCSurface;
+
XF86ModReqInfo shadowReq; /* to test for later libshadow */
Rotation rotation;
void (*PointerMoved)(int, int, int);
diff --git a/src/i830_video.c b/src/i830_video.c
index f7f2f740..015b4268 100644
--- a/src/i830_video.c
+++ b/src/i830_video.c
@@ -2382,8 +2382,14 @@ I830PutImage(ScrnInfoPtr pScrn,
switch (id) {
case FOURCC_YV12:
case FOURCC_I420:
- srcPitch = (width + 3) & ~3;
- srcPitch2 = ((width >> 1) + 3) & ~3;
+ if (pI830->IsXvMCSurface) {
+ srcPitch = (width + 0x400) & ~0x3ff;
+ srcPitch2 = ((width >> 1) + 0x400) & ~0x3ff;
+ } else {
+ srcPitch = (width + 0x3) & ~0x3;
+ srcPitch2 = ((width >> 1) + 0x3) & ~0x3;
+ }
+
if (pPriv->textured && IS_I965G(pI830))
destId = FOURCC_YUY2;
break;
diff --git a/src/i915_hwmc.c b/src/i915_hwmc.c
index 0f57a5fb..b5bd13e1 100644
--- a/src/i915_hwmc.c
+++ b/src/i915_hwmc.c
@@ -191,41 +191,6 @@ static XF86MCAdaptorPtr ppAdapt[1] =
(XF86MCAdaptorPtr)&pAdapt
};
-static unsigned int stride(int w)
-{
- return (w + 3) & ~3;
-}
-
-static unsigned long size_y420(int w, int h)
-{
- unsigned cpp = 1;
- unsigned yPitch = stride(w) * cpp;
-
- return h * yPitch;
-}
-
-static unsigned long size_uv420(int w, int h)
-{
- unsigned cpp = 1;
- unsigned uvPitch = stride(w >> 1) * cpp;
-
- return h / 2 * uvPitch;
-}
-
-static unsigned long size_yuv420(int w, int h)
-{
- unsigned cpp = 1;
- unsigned yPitch = stride(w) * cpp;
- unsigned uvPitch = stride(w >> 1) * cpp;
-
- return h * (yPitch + uvPitch);
-}
-
-static unsigned long size_xx44(int w, int h)
-{
- return h * stride(w);
-}
-
/*
* Init and clean up the screen private parts of XvMC.
*/
@@ -641,7 +606,7 @@ static int I915XvMCCreateSurface(ScrnInfoPtr pScrn, XvMCSurfacePtr pSurf,
}
ctx = pSurf->context;
- bufsize = size_yuv420(ctx->width, ctx->height);
+ bufsize = SIZE_YUV420(ctx->width, ctx->height);
if (!i830_allocate_xvmc_buffer(pScrn, "XvMC surface",
&(sfpriv->surface), bufsize,
@@ -727,7 +692,7 @@ static int I915XvMCCreateSubpicture (ScrnInfoPtr pScrn, XvMCSubpicturePtr pSubp,
}
ctx = pSubp->context;
- bufsize = size_xx44(ctx->width, ctx->height);
+ bufsize = SIZE_XX44(ctx->width, ctx->height);
if (!i830_allocate_xvmc_buffer(pScrn, "XvMC surface",
&(sfpriv->surface), bufsize,
@@ -900,12 +865,13 @@ static int I915XvMCInterceptPutImage(ScrnInfoPtr pScrn, short src_x, short src_y
short height, Bool sync, RegionPtr clipBoxes, pointer data,
DrawablePtr pDraw)
{
+ I830Ptr pI830 = I830PTR(pScrn);
I830PortPrivPtr pPriv = (I830PortPrivPtr)data;
I915XvMCXVPriv *vx = (I915XvMCXVPriv *)pPriv->xvmc_priv;
+ int ret;
if (I830PTR(pScrn)->XvMCEnabled) {
if (FOURCC_XVMC == id) {
- I830Ptr pI830 = I830PTR(pScrn);
I915XvMCPtr pXvMC = pI830->xvmc;
I915XvMCCommandBuffer *i915XvMCData = (I915XvMCCommandBuffer *)buf;
int i;
@@ -933,6 +899,7 @@ static int I915XvMCInterceptPutImage(ScrnInfoPtr pScrn, short src_x, short src_y
mem = pXvMC->sfprivs[i915XvMCData->srfNo]->surface;
buf = pI830->FbBase + mem->offset;
id = i915XvMCData->real_id;
+ pI830->IsXvMCSurface = 1;
break;
}
@@ -944,8 +911,10 @@ static int I915XvMCInterceptPutImage(ScrnInfoPtr pScrn, short src_x, short src_y
}
}
- return vx->PutImage(pScrn, src_x, src_y, drw_x, drw_y, src_w, src_h,
+ ret = vx->PutImage(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;
}
/*********************************** Public Function **************************************/
diff --git a/src/i915_hwmc.h b/src/i915_hwmc.h
index a4b4220a..f2570ceb 100644
--- a/src/i915_hwmc.h
+++ b/src/i915_hwmc.h
@@ -1,6 +1,12 @@
#ifndef _I915_HWMC_H
#define _I915_HWMC_H
+#define STRIDE(w) (((w) + 0x3ff) & ~0x3ff)
+#define SIZE_Y420(w, h) (h * STRIDE(w))
+#define SIZE_UV420(w, h) ((h >> 1) * STRIDE(w >> 1))
+#define SIZE_YUV420(w, h) (h * (STRIDE(w) + STRIDE(w >> 1)))
+#define SIZE_XX44(w, h) (h * STRIDE(w))
+
#define FOURCC_XVMC (('C' << 24) + ('M' << 16) + ('V' << 8) + 'X')
#define I915_NUM_XVMC_ATTRIBUTES 0x02
diff --git a/src/xvmc/I915XvMC.c b/src/xvmc/I915XvMC.c
index b4d1f574..3b086c2b 100644
--- a/src/xvmc/I915XvMC.c
+++ b/src/xvmc/I915XvMC.c
@@ -34,10 +34,10 @@
#define YOFFSET(surface) (surface->srf.offset)
#define UOFFSET(surface) (surface->srf.offset + \
- size_y(surface->width, surface->height) + \
- size_uv(surface->width, surface->height))
+ SIZE_Y420(surface->width, surface->height) + \
+ SIZE_UV420(surface->width, surface->height))
#define VOFFSET(surface) (surface->srf.offset + \
- size_y(surface->width, surface->height))
+ SIZE_Y420(surface->width, surface->height))
/* Lookup tables to speed common calculations */
_STATIC_ unsigned mb_bytes[] = {
@@ -173,67 +173,6 @@ _STATIC_ void UNLOCK_HARDWARE(i915XvMCContext *pI915XvMC)
pthread_mutex_unlock(&pI915XvMC->ctxmutex);
}
-_STATIC_ unsigned stride(int w)
-{
- return (w + 3) & ~3;
-}
-
-_STATIC_ unsigned long size_y(int w, int h)
-{
- unsigned cpp = 1;
- unsigned yPitch = stride(w) * cpp;
-
- return h * yPitch;
-}
-
-_STATIC_ unsigned long size_uv(int w, int h)
-{
- unsigned cpp = 1;
- unsigned uvPitch = stride(w >> 1) * cpp;
-
- return h / 2 * uvPitch;
-}
-
-_STATIC_ unsigned long size_yuv420(int w, int h)
-{
- unsigned cpp = 1;
- unsigned yPitch = stride(w) * cpp;
- unsigned uvPitch = stride(w >> 1) * cpp;
-
- return h * (yPitch + uvPitch);
-}
-
-_STATIC_ void i915_clear_surface(i915XvMCContext *pI915XvMC, i915XvMCSurface *surface)
-{
- struct i915_color_blt color_blt;
-
- if (surface->processing)
- return;
-
- memset(&color_blt, 0, sizeof(color_blt));
- color_blt.dw0.type = CMD_2D;
- color_blt.dw0.opcode = OPC_COLOR_BLT;
- color_blt.dw0.bpp_mask = 0x1;
- color_blt.dw0.length = 3;
- color_blt.dw1.color_depth = 0; /* 8bit */
- color_blt.dw1.rop = 0xf0;
- color_blt.dw1.pitch = surface->yStride;
- color_blt.dw2.height = surface->height;
- color_blt.dw2.width = surface->width;
- color_blt.dw3.address = YOFFSET(surface);
- color_blt.dw4.pattern = 0x7f;
- intelBatchbufferData(pI915XvMC, &color_blt, sizeof(color_blt), 0);
-
- color_blt.dw1.pitch = surface->uvStride;
- color_blt.dw2.height = (surface->height >> 1);
- color_blt.dw2.width = (surface->width >> 1);
- color_blt.dw3.address = VOFFSET(surface);
- intelBatchbufferData(pI915XvMC, &color_blt, sizeof(color_blt), 0);
-
- color_blt.dw3.address = UOFFSET(surface);
- intelBatchbufferData(pI915XvMC, &color_blt, sizeof(color_blt), 0);
-}
-
_STATIC_ void i915_flush(i915XvMCContext *pI915XvMC, int map, int render)
{
struct i915_mi_flush mi_flush;
@@ -247,11 +186,6 @@ _STATIC_ void i915_flush(i915XvMCContext *pI915XvMC, int map, int render)
intelBatchbufferData(pI915XvMC, &mi_flush, sizeof(mi_flush), 0);
}
-_STATIC_ void i915_flush_with_flush_bit_clear(i915XvMCContext *pI915XvMC)
-{
- i915_flush(pI915XvMC, 1, 0);
-}
-
/* for MC picture rendering */
_STATIC_ void i915_mc_static_indirect_state_buffer(XvMCContext *context,
XvMCSurface *surface,
@@ -535,8 +469,6 @@ _STATIC_ void i915_mc_load_sis_msb_buffers(XvMCContext *context)
unsigned size;
int mem_select = 1;
- i915_flush_with_flush_bit_clear(pI915XvMC);
-
/* 3DSTATE_LOAD_INDIRECT */
size = sizeof(*load_indirect) + sizeof(*sis) + sizeof(*msb);
base = calloc(1, size);
@@ -668,10 +600,10 @@ _STATIC_ void i915_mc_mpeg_macroblock_1fbmv(XvMCContext *context, XvMCMacroBlock
macroblock_1fbmv.header.dw1.coded_block_pattern = mb->coded_block_pattern;
macroblock_1fbmv.header.dw1.skipped_macroblocks = 0;
- fmv.s[0] = mb->PMV[0][0][1];
- fmv.s[1] = mb->PMV[0][0][0];
- bmv.s[0] = mb->PMV[0][1][1];
- bmv.s[1] = mb->PMV[0][1][0];
+ fmv.s[0] = mb->PMV[0][0][0];
+ fmv.s[1] = mb->PMV[0][0][1];
+ bmv.s[0] = mb->PMV[0][1][0];
+ bmv.s[1] = mb->PMV[0][1][1];
macroblock_1fbmv.dw2 = fmv.u[0];
macroblock_1fbmv.dw3 = bmv.u[0];
@@ -707,34 +639,34 @@ _STATIC_ void i915_mc_mpeg_macroblock_2fbmv(XvMCContext *context, XvMCMacroBlock
macroblock_2fbmv.header.dw1.coded_block_pattern = mb->coded_block_pattern;
macroblock_2fbmv.header.dw1.skipped_macroblocks = 0;
- fmv.s[0] = mb->PMV[0][0][1];
- fmv.s[1] = mb->PMV[0][0][0];
- fmv.s[2] = mb->PMV[1][0][1];
- fmv.s[3] = mb->PMV[1][0][0];
- bmv.s[0] = mb->PMV[0][1][1];
- bmv.s[1] = mb->PMV[0][1][0];
- bmv.s[2] = mb->PMV[1][1][1];
- bmv.s[3] = mb->PMV[1][1][0];
+ fmv.s[0] = mb->PMV[0][0][0];
+ fmv.s[1] = mb->PMV[0][0][1];
+ fmv.s[2] = mb->PMV[1][0][0];
+ fmv.s[3] = mb->PMV[1][0][1];
+ bmv.s[0] = mb->PMV[0][1][0];
+ bmv.s[1] = mb->PMV[0][1][1];
+ bmv.s[2] = mb->PMV[1][1][0];
+ bmv.s[3] = mb->PMV[1][1][1];
if ((ps & XVMC_FRAME_PICTURE) == XVMC_FRAME_PICTURE) {
if ((mb->motion_type & 3) == XVMC_PREDICTION_FIELD) {
- fmv.s[0] = mb->PMV[0][0][1] >> 1;
- fmv.s[1] = mb->PMV[0][0][0];
- fmv.s[2] = mb->PMV[1][0][1] >> 1;
- fmv.s[3] = mb->PMV[1][0][0];
- bmv.s[0] = mb->PMV[0][1][1] >> 1;
- bmv.s[1] = mb->PMV[0][1][0];
- bmv.s[2] = mb->PMV[1][1][1] >> 1;
- bmv.s[3] = mb->PMV[1][1][0];
+ fmv.s[0] = mb->PMV[0][0][0];
+ fmv.s[1] = mb->PMV[0][0][1] >> 1;
+ fmv.s[2] = mb->PMV[1][0][0];
+ fmv.s[3] = mb->PMV[1][0][1] >> 1;
+ bmv.s[0] = mb->PMV[0][1][0];
+ bmv.s[1] = mb->PMV[0][1][1] >> 1;
+ bmv.s[2] = mb->PMV[1][1][0];
+ bmv.s[3] = mb->PMV[1][1][1] >> 1;
} else if ((mb->motion_type & 3) == XVMC_PREDICTION_DUAL_PRIME) {
- fmv.s[0] = mb->PMV[0][0][1] >> 1;
- fmv.s[1] = mb->PMV[0][0][0];
- fmv.s[2] = mb->PMV[0][0][1] >> 1; // MPEG2 MV[0][1] isn't used
- fmv.s[3] = mb->PMV[0][0][0];
- bmv.s[0] = mb->PMV[1][0][1] >> 1;
- bmv.s[1] = mb->PMV[1][0][0];
- bmv.s[2] = mb->PMV[1][1][1] >> 1;
- bmv.s[3] = mb->PMV[1][1][0];
+ fmv.s[0] = mb->PMV[0][0][0];
+ fmv.s[1] = mb->PMV[0][0][1] >> 1;
+ fmv.s[2] = mb->PMV[0][0][0];
+ fmv.s[3] = mb->PMV[0][0][1] >> 1; // MPEG2 MV[0][1] isn't used
+ bmv.s[0] = mb->PMV[1][0][0];
+ bmv.s[1] = mb->PMV[1][0][1] >> 1;
+ bmv.s[2] = mb->PMV[1][1][0];
+ bmv.s[3] = mb->PMV[1][1][1] >> 1;
}
}
@@ -1072,9 +1004,6 @@ _STATIC_ void i915_mc_one_time_state_initialization(XvMCContext *context)
intelBatchbufferData(pI915XvMC, base, size, 0);
free(base);
- /* flush */
- i915_flush_with_flush_bit_clear(pI915XvMC);
-
/* 3DSTATE_LOAD_INDIRECT */
size = sizeof(*load_indirect) + sizeof(*dis) + sizeof(*ssb) + sizeof(*psp) + sizeof(*psc);
base = calloc(1, size);
@@ -1147,9 +1076,6 @@ _STATIC_ void i915_mc_invalidate_subcontext_buffers(XvMCContext *context, unsign
unsigned size;
void *base = NULL, *ptr = NULL;
- /* flush */
- i915_flush_with_flush_bit_clear(pI915XvMC);
-
size = sizeof(*load_indirect);
if (mask & BLOCK_SIS)
size += sizeof(*sis);
@@ -1364,8 +1290,7 @@ _STATIC_ void i915_yuv2rgb_map_state_buffer(XvMCSurface *target_surface)
memset(tm, 0, sizeof(*tm));
tm->tm0.v_ls_offset = 0;
tm->tm0.v_ls = 0;
- tm->tm0.base_address = privTarget->srf.offset +
- size_y(w, h);
+ tm->tm0.base_address = VOFFSET(privTarget);
tm->tm1.tile_walk = TILEWALK_XMAJOR;
tm->tm1.tiled_surface = 0;
tm->tm1.utilize_fence_regs = 1;
@@ -1383,7 +1308,7 @@ _STATIC_ void i915_yuv2rgb_map_state_buffer(XvMCSurface *target_surface)
memset(tm, 0, sizeof(*tm));
tm->tm0.v_ls_offset = 0;
tm->tm0.v_ls = 0;
- tm->tm0.base_address = privTarget->srf.offset;
+ tm->tm0.base_address = YOFFSET(privTarget);
tm->tm1.tile_walk = TILEWALK_XMAJOR;
tm->tm1.tiled_surface = 0;
tm->tm1.utilize_fence_regs = 1;
@@ -1401,8 +1326,7 @@ _STATIC_ void i915_yuv2rgb_map_state_buffer(XvMCSurface *target_surface)
memset(tm, 0, sizeof(*tm));
tm->tm0.v_ls_offset = 0;
tm->tm0.v_ls = 0;
- tm->tm0.base_address = privTarget->srf.offset +
- size_y(w, h) + size_uv(w, h);
+ tm->tm0.base_address = UOFFSET(privTarget);
tm->tm1.tile_walk = TILEWALK_XMAJOR;
tm->tm1.tiled_surface = 0;
tm->tm1.utilize_fence_regs = 1;
@@ -1675,9 +1599,6 @@ _STATIC_ void i915_yuv2rgb_proc(XvMCSurface *surface)
scissor_rectangle.dw2.max_y = 2047;
intelBatchbufferData(pI915XvMC, &scissor_rectangle, sizeof(scissor_rectangle), 0);
- /* flush */
- i915_flush_with_flush_bit_clear(pI915XvMC);
-
/* 3DSTATE_LOAD_INDIRECT */
size = sizeof(*load_indirect) + sizeof(*sis) + sizeof(*ssb) + sizeof(*msb) + sizeof(*psp);
base = calloc(1, size);
@@ -2071,8 +1992,8 @@ Status XvMCCreateContext(Display *display, XvPortID port,
/* Initialize private context values */
setupAttribDesc(display, port, &pI915XvMC->attrib, pI915XvMC->attribDesc);
- pI915XvMC->yStride = stride(width) * 1; /* cpp = 1 */
- pI915XvMC->uvStride = stride(width >> 1) * 1;
+ pI915XvMC->yStride = STRIDE(width);
+ pI915XvMC->uvStride = STRIDE(width >> 1);
pI915XvMC->haveXv = 0;
pI915XvMC->attribChanged = 1;
pI915XvMC->dual_prime = 0;
@@ -2082,7 +2003,6 @@ Status XvMCCreateContext(Display *display, XvPortID port,
pthread_mutex_init(&pI915XvMC->ctxmutex, NULL);
intelInitBatchBuffer(pI915XvMC);
pI915XvMC->ref = 1;
- pI915XvMC->inited_mc = 0;
return Success;
}
@@ -2144,7 +2064,6 @@ Status XvMCCreateSurface(Display *display, XvMCContext *context, XvMCSurface *su
pI915Surface->uvStride = pI915XvMC->uvStride;
pI915Surface->width = context->width;
pI915Surface->height = context->height;
- pI915Surface->processing = 0;
pI915Surface->privContext = pI915XvMC;
pI915Surface->privSubPic = NULL;
pI915Surface->srf.map = NULL;
@@ -2415,27 +2334,9 @@ Status XvMCRenderSurface(Display *display, XvMCContext *context,
}
LOCK_HARDWARE(pI915XvMC);
- // if (!pI915XvMC->inited_mc) {
- i915_clear_surface(pI915XvMC, privTarget);
- i915_mc_invalidate_subcontext_buffers(context, BLOCK_SIS | BLOCK_DIS | BLOCK_SSB
- | BLOCK_MSB | BLOCK_PSP | BLOCK_PSC);
- i915_mc_sampler_state_buffer(context);
- i915_mc_pixel_shader_program_buffer(context);
- i915_mc_pixel_shader_constants_buffer(context);
- i915_mc_one_time_state_initialization(context);
- pI915XvMC->inited_mc = 1;
- //}
- intelFlushBatch(pI915XvMC, TRUE);
- UNLOCK_HARDWARE(pI915XvMC);
-
corrdata_ptr = pI915XvMC->corrdata.map;
corrdata_size = 0;
- if (macroblock_array->macro_blocks[first_macroblock].y == (target_surface->height >> 4) - 1)
- privTarget->processing = 0;
- else
- privTarget->processing = 1;
-
for (i = first_macroblock; i < (num_macroblocks + first_macroblock); i++) {
int bspm = 0;
mb = &macroblock_array->macro_blocks[i];
@@ -2461,19 +2362,29 @@ Status XvMCRenderSurface(Display *display, XvMCContext *context,
}
bspm = mb_bytes[mb->coded_block_pattern];
+
+ if (!bspm)
+ continue;
+
corrdata_size += bspm;
if (corrdata_size > pI915XvMC->corrdata.size) {
printf("Error, correction data buffer overflow\n");
break;
}
-
memcpy(corrdata_ptr, block_ptr, bspm);
corrdata_ptr += bspm;
}
- /* Lock */
- LOCK_HARDWARE(pI915XvMC);
+ i915_flush(pI915XvMC, 1, 0);
+ i915_mc_invalidate_subcontext_buffers(context, BLOCK_SIS | BLOCK_DIS | BLOCK_SSB
+ | BLOCK_MSB | BLOCK_PSP | BLOCK_PSC);
+
+ i915_mc_sampler_state_buffer(context);
+ i915_mc_pixel_shader_program_buffer(context);
+ i915_mc_pixel_shader_constants_buffer(context);
+ i915_mc_one_time_state_initialization(context);
+
i915_mc_static_indirect_state_buffer(context, target_surface,
picture_structure, flags,
picture_coding_type);
@@ -2524,7 +2435,6 @@ Status XvMCRenderSurface(Display *display, XvMCContext *context,
break;
}
} /* Field Picture */
- i915_flush(pI915XvMC, 0, 1);
}
intelFlushBatch(pI915XvMC, TRUE);
diff --git a/src/xvmc/I915XvMC.h b/src/xvmc/I915XvMC.h
index 9dd73e7c..7f47f433 100644
--- a/src/xvmc/I915XvMC.h
+++ b/src/xvmc/I915XvMC.h
@@ -77,7 +77,6 @@ typedef struct _i915XvMCContext {
int lock; /* Lightweight lock to avoid locking twice */
int locked;
volatile drmI830Sarea *sarea;
- int inited_mc;
drmLock *driHwLock;
drm_context_t hHWContext; /* drmcontext; */
@@ -159,7 +158,6 @@ typedef struct _i915XvMCSurface {
unsigned uvStride;
unsigned width; /* Dimensions */
unsigned height;
- unsigned processing;
i915XvMCDrmMap srf;
i915XvMCContext *privContext;
i915XvMCSubpicture *privSubPic; /* Subpicture to be blended when