libXvMC: unify CreateSurface
Simply store the desired bo size in intel_xvmc_context and initialize it in the driver's create_context function. Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
This commit is contained in:
parent
3f590a4577
commit
676028ec0c
|
|
@ -927,6 +927,8 @@ static Status i915_xvmc_mc_create_context(Display * display,
|
|||
|
||||
tmpComm = (struct intel_xvmc_hw_context *) priv_data;
|
||||
pI915XvMC->use_phys_addr = tmpComm->i915.use_phys_addr;
|
||||
pI915XvMC->comm.surface_bo_size = SIZE_YUV420(context->width,
|
||||
context->height);
|
||||
|
||||
/* Must free the private data we were passed from X */
|
||||
XFree(priv_data);
|
||||
|
|
@ -965,49 +967,6 @@ static int i915_xvmc_mc_destroy_context(Display * display,
|
|||
return Success;
|
||||
}
|
||||
|
||||
static Status i915_xvmc_mc_create_surface(Display * display,
|
||||
XvMCContext * context,
|
||||
XvMCSurface * surface, int priv_count,
|
||||
CARD32 * priv_data)
|
||||
{
|
||||
i915XvMCContext *pI915XvMC;
|
||||
struct intel_xvmc_surface *intel_surf;
|
||||
|
||||
if (!(pI915XvMC = context->privData))
|
||||
return XvMCBadContext;
|
||||
|
||||
XVMC_DBG("%s\n", __FUNCTION__);
|
||||
|
||||
PPTHREAD_MUTEX_LOCK();
|
||||
surface->privData = calloc(1, sizeof(struct intel_xvmc_surface));
|
||||
|
||||
if (!(intel_surf = surface->privData)) {
|
||||
PPTHREAD_MUTEX_UNLOCK();
|
||||
return BadAlloc;
|
||||
}
|
||||
|
||||
/* Initialize private values */
|
||||
intel_surf->bo = drm_intel_bo_alloc(xvmc_driver->bufmgr,
|
||||
"surface",
|
||||
SIZE_YUV420(context->width,
|
||||
context->height),
|
||||
GTT_PAGE_SIZE);
|
||||
|
||||
/* X may still use this buffer when XVMC is already done with it. */
|
||||
drm_intel_bo_disable_reuse(intel_surf->bo);
|
||||
|
||||
if (!intel_surf->bo) {
|
||||
PPTHREAD_MUTEX_UNLOCK();
|
||||
free(intel_surf);
|
||||
return BadAlloc;
|
||||
}
|
||||
|
||||
XFree(priv_data);
|
||||
|
||||
PPTHREAD_MUTEX_UNLOCK();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int i915_xvmc_alloc_render_state_buffers(i915XvMCContext *pI915XvMC)
|
||||
{
|
||||
pI915XvMC->sis_bo = drm_intel_bo_alloc(xvmc_driver->bufmgr,
|
||||
|
|
@ -1266,6 +1225,5 @@ struct _intel_xvmc_driver i915_xvmc_mc_driver = {
|
|||
.ctx_list = NULL,
|
||||
.create_context = i915_xvmc_mc_create_context,
|
||||
.destroy_context = i915_xvmc_mc_destroy_context,
|
||||
.create_surface = i915_xvmc_mc_create_surface,
|
||||
.render_surface = i915_xvmc_mc_render_surface,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -251,25 +251,6 @@ static Status destroy_context(Display * display, XvMCContext * context)
|
|||
#define STRIDE(w) (w)
|
||||
#define SIZE_YUV420(w, h) (h * (STRIDE(w) + STRIDE(w >> 1)))
|
||||
|
||||
static Status create_surface(Display * display,
|
||||
XvMCContext * context, XvMCSurface * surface,
|
||||
int priv_count, CARD32 * priv_data)
|
||||
{
|
||||
struct intel_xvmc_surface *priv_surface = malloc(sizeof(struct intel_xvmc_surface));
|
||||
|
||||
if (!priv_surface)
|
||||
return BadAlloc;
|
||||
|
||||
size_t size = SIZE_YUV420(context->width, context->height);
|
||||
surface->privData = priv_surface;
|
||||
priv_surface->bo = drm_intel_bo_alloc(xvmc_driver->bufmgr, "surface",
|
||||
size, 0x1000);
|
||||
|
||||
Xfree(priv_data);
|
||||
|
||||
return Success;
|
||||
}
|
||||
|
||||
static void flush()
|
||||
{
|
||||
struct brw_mi_flush flush;
|
||||
|
|
@ -878,6 +859,8 @@ static Status create_context(Display * display, XvMCContext * context,
|
|||
if (!intel_ctx)
|
||||
return BadAlloc;
|
||||
intel_ctx->hw = hw_ctx;
|
||||
intel_ctx->surface_bo_size
|
||||
= SIZE_YUV420(context->width, context->height);
|
||||
context->privData = intel_ctx;
|
||||
|
||||
media_state.is_g4x = hw_ctx->i965.is_g4x;
|
||||
|
|
@ -894,6 +877,5 @@ struct _intel_xvmc_driver i965_xvmc_mc_driver = {
|
|||
.type = XVMC_I965_MPEG2_MC,
|
||||
.create_context = create_context,
|
||||
.destroy_context = destroy_context,
|
||||
.create_surface = create_surface,
|
||||
.render_surface = render_surface,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -406,6 +406,7 @@ _X_EXPORT Status XvMCCreateSurface(Display * display, XvMCContext * context,
|
|||
int priv_count;
|
||||
CARD32 *priv_data;
|
||||
intel_xvmc_surface_ptr intel_surf = NULL;
|
||||
struct intel_xvmc_context *intel_ctx;
|
||||
|
||||
if (!display || !context)
|
||||
return XvMCBadContext;
|
||||
|
|
@ -413,20 +414,34 @@ _X_EXPORT Status XvMCCreateSurface(Display * display, XvMCContext * context,
|
|||
if (!surface)
|
||||
return XvMCBadSurface;
|
||||
|
||||
intel_ctx = context->privData;
|
||||
|
||||
if ((ret = _xvmc_create_surface(display, context, surface,
|
||||
&priv_count, &priv_data))) {
|
||||
XVMC_ERR("Unable to create XvMCSurface.");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret =
|
||||
(xvmc_driver->create_surface) (display, context, surface,
|
||||
priv_count, priv_data);
|
||||
if (ret) {
|
||||
XVMC_ERR("create surface failed\n");
|
||||
return ret;
|
||||
XFree(priv_data);
|
||||
|
||||
surface->privData = calloc(1, sizeof(struct intel_xvmc_surface));
|
||||
|
||||
if (!(intel_surf = surface->privData)) {
|
||||
PPTHREAD_MUTEX_UNLOCK();
|
||||
return BadAlloc;
|
||||
}
|
||||
|
||||
intel_surf->bo = drm_intel_bo_alloc(xvmc_driver->bufmgr,
|
||||
"surface",
|
||||
intel_ctx->surface_bo_size,
|
||||
GTT_PAGE_SIZE);
|
||||
if (!intel_surf->bo) {
|
||||
free(intel_surf);
|
||||
return BadAlloc;
|
||||
}
|
||||
|
||||
drm_intel_bo_disable_reuse(intel_surf->bo);
|
||||
|
||||
intel_surf = surface->privData;
|
||||
intel_surf->context = context;
|
||||
|
||||
|
|
@ -436,6 +451,7 @@ _X_EXPORT Status XvMCCreateSurface(Display * display, XvMCContext * context,
|
|||
surface->width, surface->height);
|
||||
if (!intel_surf->image) {
|
||||
XVMC_ERR("Can't create XvImage for surface\n");
|
||||
free(intel_surf);
|
||||
_xvmc_destroy_surface(display, surface);
|
||||
return BadAlloc;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,6 +104,7 @@ extern Status _xvmc_destroy_subpicture(Display * dpy,
|
|||
|
||||
struct intel_xvmc_context {
|
||||
struct intel_xvmc_hw_context *hw;
|
||||
uint32_t surface_bo_size;
|
||||
drm_context_t hw_context; /* context id to kernel drm */
|
||||
};
|
||||
typedef struct intel_xvmc_context *intel_xvmc_context_ptr;
|
||||
|
|
@ -170,10 +171,6 @@ typedef struct _intel_xvmc_driver {
|
|||
|
||||
Status(*destroy_context) (Display * display, XvMCContext * context);
|
||||
|
||||
Status(*create_surface) (Display * display, XvMCContext * context,
|
||||
XvMCSurface * surface, int priv_count,
|
||||
CARD32 * priv_data);
|
||||
|
||||
Status(*render_surface) (Display * display, XvMCContext * context,
|
||||
unsigned int picture_structure,
|
||||
XvMCSurface * target_surface,
|
||||
|
|
|
|||
|
|
@ -592,6 +592,8 @@ static Status cs_init(int interface_offset)
|
|||
return Success;
|
||||
}
|
||||
|
||||
#define STRIDE(w) (w)
|
||||
#define SIZE_YUV420(w, h) (h * (STRIDE(w) + STRIDE(w >> 1)))
|
||||
static Status create_context(Display * display, XvMCContext * context,
|
||||
int priv_count, CARD32 * priv_data)
|
||||
{
|
||||
|
|
@ -604,6 +606,8 @@ static Status create_context(Display * display, XvMCContext * context,
|
|||
return BadAlloc;
|
||||
intel_ctx->hw = hw_ctx;
|
||||
context->privData = intel_ctx;
|
||||
intel_ctx->surface_bo_size
|
||||
= SIZE_YUV420(context->width, context->height);
|
||||
|
||||
if (alloc_object(&media_state))
|
||||
return BadAlloc;
|
||||
|
|
@ -622,27 +626,6 @@ static Status destroy_context(Display * display, XvMCContext * context)
|
|||
return Success;
|
||||
}
|
||||
|
||||
#define STRIDE(w) (w)
|
||||
#define SIZE_YUV420(w, h) (h * (STRIDE(w) + STRIDE(w >> 1)))
|
||||
static Status create_surface(Display * display,
|
||||
XvMCContext * context, XvMCSurface * surface,
|
||||
int priv_count, CARD32 * priv_data)
|
||||
{
|
||||
struct intel_xvmc_surface *priv_surface = malloc(sizeof(struct intel_xvmc_surface));
|
||||
|
||||
if (!priv_surface)
|
||||
return BadAlloc;
|
||||
|
||||
size_t size = SIZE_YUV420(context->width, context->height);
|
||||
surface->privData = priv_surface;
|
||||
priv_surface->bo = drm_intel_bo_alloc(xvmc_driver->bufmgr, "surface",
|
||||
size, 0x1000);
|
||||
|
||||
Xfree(priv_data);
|
||||
|
||||
return Success;
|
||||
}
|
||||
|
||||
static Status load_qmatrix(Display * display, XvMCContext * context,
|
||||
const XvMCQMatrix * qmx)
|
||||
{
|
||||
|
|
@ -1234,7 +1217,6 @@ struct _intel_xvmc_driver xvmc_vld_driver = {
|
|||
.type = XVMC_I965_MPEG2_VLD,
|
||||
.create_context = create_context,
|
||||
.destroy_context = destroy_context,
|
||||
.create_surface = create_surface,
|
||||
.load_qmatrix = load_qmatrix,
|
||||
.begin_surface = begin_surface,
|
||||
.render_surface = render_surface,
|
||||
|
|
|
|||
Loading…
Reference in New Issue