diff options
author | Daniel Vetter <daniel.vetter@ffwll.ch> | 2010-03-10 19:23:06 +0100 |
---|---|---|
committer | Daniel Vetter <daniel.vetter@ffwll.ch> | 2010-04-08 11:22:24 +0200 |
commit | 676028ec0cbd4fadded92feefc8371e075abcc12 (patch) | |
tree | 11f48f6ee1255543affc9c471c91d93195e8a0f3 /src/xvmc | |
parent | 3f590a4577f554313e7577205e471757a39129b6 (diff) |
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>
Diffstat (limited to 'src/xvmc')
-rw-r--r-- | src/xvmc/i915_xvmc.c | 46 | ||||
-rw-r--r-- | src/xvmc/i965_xvmc.c | 22 | ||||
-rw-r--r-- | src/xvmc/intel_xvmc.c | 28 | ||||
-rw-r--r-- | src/xvmc/intel_xvmc.h | 5 | ||||
-rw-r--r-- | src/xvmc/xvmc_vld.c | 26 |
5 files changed, 31 insertions, 96 deletions
diff --git a/src/xvmc/i915_xvmc.c b/src/xvmc/i915_xvmc.c index 80b70e66..40f0f35f 100644 --- a/src/xvmc/i915_xvmc.c +++ b/src/xvmc/i915_xvmc.c @@ -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, }; diff --git a/src/xvmc/i965_xvmc.c b/src/xvmc/i965_xvmc.c index 3005a597..1665f6d0 100644 --- a/src/xvmc/i965_xvmc.c +++ b/src/xvmc/i965_xvmc.c @@ -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, }; diff --git a/src/xvmc/intel_xvmc.c b/src/xvmc/intel_xvmc.c index 0d543479..4437b1a9 100644 --- a/src/xvmc/intel_xvmc.c +++ b/src/xvmc/intel_xvmc.c @@ -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; } diff --git a/src/xvmc/intel_xvmc.h b/src/xvmc/intel_xvmc.h index 684f9314..9aa55487 100644 --- a/src/xvmc/intel_xvmc.h +++ b/src/xvmc/intel_xvmc.h @@ -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, diff --git a/src/xvmc/xvmc_vld.c b/src/xvmc/xvmc_vld.c index 5443f021..5687593a 100644 --- a/src/xvmc/xvmc_vld.c +++ b/src/xvmc/xvmc_vld.c @@ -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, |