Commit 8a31dacb authored by Daniel Vetter's avatar Daniel Vetter

libXvMC: derive driver context from struct intel_xvmc_context

... by putting struct intel_xvmc_surface at the beginning. Also kill
the common context handling code and simply keep a pointer in the
surface private to the context.
Signed-off-by: Daniel Vetter's avatarDaniel Vetter <daniel.vetter@ffwll.ch>
parent 16e5edde
......@@ -1103,7 +1103,7 @@ static int i915_xvmc_mc_render_surface(Display * display, XvMCContext * context,
if (!i915_xvmc_alloc_render_state_buffers(pI915XvMC))
return BadAlloc;
intel_ctx = intel_xvmc_find_context(context->context_id);
intel_ctx = context->privData;
if (!intel_ctx) {
XVMC_ERR("Can't find intel xvmc context\n");
return BadValue;
......
......@@ -50,6 +50,7 @@
* pointer in the XvMCContext structure.
*/
typedef struct _i915XvMCContext {
struct intel_xvmc_context comm;
unsigned int ctxno;
unsigned int dual_prime; /* Flag to identify when dual prime is in use. */
unsigned int yStride;
......
......@@ -241,11 +241,10 @@ out:
static Status destroy_context(Display * display, XvMCContext * context)
{
struct i965_xvmc_context *private_context;
private_context = context->privData;
free_object(&media_state);
Xfree(private_context);
struct intel_xvmc_context *intel_ctx;
intel_ctx = context->privData;
Xfree(intel_ctx->hw);
free(intel_ctx);
return Success;
}
......@@ -720,7 +719,7 @@ static Status render_surface(Display * display,
struct intel_xvmc_surface *priv_future_surface =
future_surface ? future_surface->privData : 0;
unsigned short *block_ptr;
intel_ctx = intel_xvmc_find_context(context->context_id);
intel_ctx = context->privData;
i965_ctx = context->privData;
if (!intel_ctx) {
XVMC_ERR("Can't find intel xvmc context\n");
......@@ -871,12 +870,18 @@ static Status render_surface(Display * display,
static Status create_context(Display * display, XvMCContext * context,
int priv_count, CARD32 * priv_data)
{
struct intel_xvmc_hw_context *ctx;
ctx = (struct intel_xvmc_hw_context *)priv_data;
context->privData = ctx;
struct intel_xvmc_context *intel_ctx;
struct intel_xvmc_hw_context *hw_ctx;
hw_ctx = (struct intel_xvmc_hw_context *)priv_data;
intel_ctx = calloc(1, sizeof(struct intel_xvmc_context));
if (!intel_ctx)
return BadAlloc;
intel_ctx->hw = hw_ctx;
context->privData = intel_ctx;
media_state.is_g4x = ctx->i965.is_g4x;
media_state.is_965_q = ctx->i965.is_965_q;
media_state.is_g4x = hw_ctx->i965.is_g4x;
media_state.is_965_q = hw_ctx->i965.is_965_q;
if (alloc_object(&media_state))
return BadAlloc;
......
......@@ -128,60 +128,6 @@ void UNLOCK_HARDWARE(drm_context_t ctx)
PPTHREAD_MUTEX_UNLOCK();
}
static intel_xvmc_context_ptr intel_xvmc_new_context(Display * dpy)
{
intel_xvmc_context_ptr ret;
ret = (intel_xvmc_context_ptr) calloc(1, sizeof(intel_xvmc_context_t));
if (!ret)
return NULL;
if (!xvmc_driver->ctx_list)
ret->next = NULL;
else
ret->next = xvmc_driver->ctx_list;
xvmc_driver->ctx_list = ret;
xvmc_driver->num_ctx++;
return ret;
}
static void intel_xvmc_free_context(XID id)
{
intel_xvmc_context_ptr p = xvmc_driver->ctx_list;
intel_xvmc_context_ptr pre = p;
while (p) {
if (p->context && p->context->context_id == id) {
if (p == xvmc_driver->ctx_list)
xvmc_driver->ctx_list = p->next;
else
pre->next = p->next;
break;
}
pre = p;
p = p->next;
}
if (p) {
free(p);
xvmc_driver->num_ctx--;
}
}
intel_xvmc_context_ptr intel_xvmc_find_context(XID id)
{
intel_xvmc_context_ptr p = xvmc_driver->ctx_list;
while (p) {
if (p->context && p->context->context_id == id)
return p;
p = p->next;
}
return NULL;
}
static int
dri2_connect(Display *display)
{
......@@ -364,14 +310,6 @@ _X_EXPORT Status XvMCCreateContext(Display * display, XvPortID port,
XVMC_INFO("decoder type is %s", intel_xvmc_decoder_string(comm->type));
/* assign local ctx info */
intel_ctx = intel_xvmc_new_context(display);
if (!intel_ctx) {
XVMC_ERR("Intel XvMC context create fail\n");
return BadAlloc;
}
intel_ctx->context = context;
/* check DRI2 */
ret = Success;
xvmc_driver->fd = -1;
......@@ -440,8 +378,6 @@ _X_EXPORT Status XvMCDestroyContext(Display * display, XvMCContext * context)
dri_bufmgr_destroy(xvmc_driver->bufmgr);
intel_xvmc_free_context(context->context_id);
ret = _xvmc_destroy_context(display, context);
if (ret != Success) {
XVMC_ERR("_xvmc_destroy_context fail\n");
......@@ -492,6 +428,7 @@ _X_EXPORT Status XvMCCreateSurface(Display * display, XvMCContext * context,
}
intel_surf = surface->privData;
intel_surf->context = context;
intel_surf->image = XvCreateImage(display, context->port,
FOURCC_XVMC,
......@@ -701,17 +638,15 @@ _X_EXPORT Status XvMCPutSurface(Display * display, XvMCSurface * surface,
{
Status ret = Success;
XvMCContext *context;
intel_xvmc_context_ptr intel_ctx;
intel_xvmc_surface_ptr intel_surf;
if (!display || !surface)
return XvMCBadSurface;
intel_ctx = intel_xvmc_find_context(surface->context_id);
intel_surf = surface->privData;
if (!intel_ctx || !intel_surf)
context = intel_surf->context;
if (!context || !intel_surf)
return XvMCBadSurface;
context = intel_ctx->context;
if (intel_surf->gc_init == FALSE) {
intel_surf->gc = XCreateGC(display, draw, 0, NULL);
......
......@@ -102,13 +102,14 @@ extern Status _xvmc_create_subpicture(Display * dpy, XvMCContext * context,
extern Status _xvmc_destroy_subpicture(Display * dpy,
XvMCSubpicture * subpicture);
typedef struct _intel_xvmc_context {
XvMCContext *context;
struct intel_xvmc_context {
struct intel_xvmc_hw_context *hw;
drm_context_t hw_context; /* context id to kernel drm */
struct _intel_xvmc_context *next;
} intel_xvmc_context_t, *intel_xvmc_context_ptr;
};
typedef struct intel_xvmc_context *intel_xvmc_context_ptr;
struct intel_xvmc_surface {
XvMCContext *context;
XvImage *image;
GC gc;
Bool gc_init;
......@@ -247,9 +248,6 @@ static inline const char *intel_xvmc_decoder_string(int flag)
}
}
extern intel_xvmc_context_ptr intel_xvmc_find_context(XID id);
extern intel_xvmc_surface_ptr intel_xvmc_find_surface(XID id);
extern unsigned int mb_bytes_420[64];
/* dump function */
......
......@@ -595,23 +595,30 @@ static Status cs_init(int interface_offset)
static Status create_context(Display * display, XvMCContext * context,
int priv_count, CARD32 * priv_data)
{
struct intel_xvmc_hw_context *ctx;
ctx = (struct intel_xvmc_hw_context *)priv_data;
context->privData = priv_data;
struct intel_xvmc_context *intel_ctx;
struct intel_xvmc_hw_context *hw_ctx;
hw_ctx = (struct intel_xvmc_hw_context *)priv_data;
intel_ctx = calloc(1, sizeof(struct intel_xvmc_context));
if (!intel_ctx)
return BadAlloc;
intel_ctx->hw = hw_ctx;
context->privData = intel_ctx;
if (alloc_object(&media_state))
return BadAlloc;
if (setup_media_kernels(ctx))
if (setup_media_kernels(hw_ctx))
return BadAlloc;
return Success;
}
static Status destroy_context(Display * display, XvMCContext * context)
{
struct i965_xvmc_context *i965_ctx;
i965_ctx = context->privData;
Xfree(i965_ctx);
struct intel_xvmc_context *intel_ctx;
intel_ctx = context->privData;
Xfree(intel_ctx->hw);
free(intel_ctx);
return Success;
}
......@@ -796,10 +803,9 @@ static Status begin_surface(Display * display, XvMCContext * context,
{
struct i965_xvmc_contex *i965_ctx;
struct intel_xvmc_surface *priv_target, *priv_past, *priv_future;
intel_xvmc_context_ptr intel_ctx;
intel_xvmc_context_ptr intel_ctx = context->privData;
Status ret;
intel_ctx = intel_xvmc_find_context(context->context_id);
priv_target = target->privData;
priv_past = past ? past->privData : NULL;
priv_future = future ? future->privData : NULL;
......@@ -989,11 +995,10 @@ static Status put_slice2(Display * display, XvMCContext * context,
unsigned char *slice, int nbytes, int sliceCode)
{
unsigned int bit_buf;
intel_xvmc_context_ptr intel_ctx;
struct intel_xvmc_hw_context *ctx;
intel_xvmc_context_ptr intel_ctx = context->privData;
struct intel_xvmc_hw_context *hw_ctx = intel_ctx->hw;
int q_scale_code, mb_row;
ctx = (struct intel_xvmc_hw_context *)context->privData;
mb_row = *(slice - 1) - 1;
bit_buf =
(slice[0] << 24) | (slice[1] << 16) | (slice[2] << 8) | (slice[3]);
......@@ -1014,9 +1019,8 @@ static Status put_slice2(Display * display, XvMCContext * context,
memcpy(media_state.slice_data.bo->virtual, slice, nbytes);
intel_ctx = intel_xvmc_find_context(context->context_id);
LOCK_HARDWARE(intel_ctx->hw_context);
state_base_address(ctx);
state_base_address(hw_ctx);
pipeline_select();
media_state_pointers(VFE_VLD_MODE);
urb_layout();
......@@ -1049,15 +1053,11 @@ static Status render_surface(Display * display,
unsigned short *block_ptr;
int i, j;
int block_offset = 0;
struct intel_xvmc_hw_context *ctx;
struct intel_xvmc_hw_context *hw_ctx;
intel_ctx = intel_xvmc_find_context(context->context_id);
if (!intel_ctx) {
XVMC_ERR("Can't find intel xvmc context\n");
return BadValue;
}
intel_ctx = context->privData;
ctx = (struct intel_xvmc_hw_context *)context->privData;
hw_ctx = (struct intel_xvmc_hw_context *)context->privData;
priv_target = target_surface->privData;
priv_past = past_surface ? past_surface->privData : NULL;
priv_future = future_surface ? future_surface->privData : NULL;
......@@ -1140,7 +1140,7 @@ static Status render_surface(Display * display,
}
LOCK_HARDWARE(intel_ctx->hw_context);
state_base_address(ctx);
state_base_address(hw_ctx);
flush();
pipeline_select();
urb_layout();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment