[Mesa-dev] [PATCH 1/9] vl/video_buffer: use template style create params
Christian König
deathsimple at vodafone.de
Tue Jan 10 07:57:51 PST 2012
Just like in the rest of gallium, this reduces the
number of parameters significantly.
Signed-off-by: Christian König <deathsimple at vodafone.de>
---
src/gallium/auxiliary/vl/vl_mpeg12_decoder.c | 27 ++++++++++----
src/gallium/auxiliary/vl/vl_video_buffer.c | 47 ++++++++++--------------
src/gallium/auxiliary/vl/vl_video_buffer.h | 9 ++---
src/gallium/drivers/nouveau/nouveau_video.c | 29 ++++++---------
src/gallium/include/pipe/p_context.h | 4 +--
src/gallium/state_trackers/vdpau/surface.c | 10 ++++--
src/gallium/state_trackers/xorg/xvmc/surface.c | 14 ++++---
7 files changed, 71 insertions(+), 69 deletions(-)
diff --git a/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c b/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c
index cb55fa6..6341cc1 100644
--- a/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c
+++ b/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c
@@ -909,6 +909,7 @@ init_idct(struct vl_mpeg12_decoder *dec, const struct format_config* format_conf
{
unsigned nr_of_idct_render_targets, max_inst;
enum pipe_format formats[3];
+ struct pipe_video_buffer templat;
struct pipe_sampler_view *matrix = NULL;
@@ -930,21 +931,28 @@ init_idct(struct vl_mpeg12_decoder *dec, const struct format_config* format_conf
nr_of_idct_render_targets = 1;
formats[0] = formats[1] = formats[2] = format_config->idct_source_format;
+ memset(&templat, 0, sizeof(templat));
+ templat.width = dec->base.width / 4;
+ templat.height = dec->base.height;
+ templat.chroma_format = dec->base.chroma_format;
dec->idct_source = vl_video_buffer_create_ex
(
- dec->base.context, dec->base.width / 4, dec->base.height, 1,
- dec->base.chroma_format, formats, PIPE_USAGE_STATIC
+ dec->base.context, &templat,
+ formats, 1, PIPE_USAGE_STATIC
);
if (!dec->idct_source)
goto error_idct_source;
formats[0] = formats[1] = formats[2] = format_config->mc_source_format;
+ memset(&templat, 0, sizeof(templat));
+ templat.width = dec->base.width / nr_of_idct_render_targets;
+ templat.height = dec->base.height / 4;
+ templat.chroma_format = dec->base.chroma_format;
dec->mc_source = vl_video_buffer_create_ex
(
- dec->base.context, dec->base.width / nr_of_idct_render_targets,
- dec->base.height / 4, nr_of_idct_render_targets,
- dec->base.chroma_format, formats, PIPE_USAGE_STATIC
+ dec->base.context, &templat,
+ formats, nr_of_idct_render_targets, PIPE_USAGE_STATIC
);
if (!dec->mc_source)
@@ -985,12 +993,17 @@ static bool
init_mc_source_widthout_idct(struct vl_mpeg12_decoder *dec, const struct format_config* format_config)
{
enum pipe_format formats[3];
+ struct pipe_video_buffer templat;
formats[0] = formats[1] = formats[2] = format_config->mc_source_format;
+ memset(&templat, 0, sizeof(templat));
+ templat.width = dec->base.width;
+ templat.height = dec->base.height;
+ templat.chroma_format = dec->base.chroma_format;
dec->mc_source = vl_video_buffer_create_ex
(
- dec->base.context, dec->base.width, dec->base.height, 1,
- dec->base.chroma_format, formats, PIPE_USAGE_STATIC
+ dec->base.context, &templat,
+ formats, 1, PIPE_USAGE_STATIC
);
return dec->mc_source != NULL;
diff --git a/src/gallium/auxiliary/vl/vl_video_buffer.c b/src/gallium/auxiliary/vl/vl_video_buffer.c
index 8ceb713..29d910e 100644
--- a/src/gallium/auxiliary/vl/vl_video_buffer.c
+++ b/src/gallium/auxiliary/vl/vl_video_buffer.c
@@ -253,17 +253,14 @@ error:
struct pipe_video_buffer *
vl_video_buffer_create(struct pipe_context *pipe,
- enum pipe_format buffer_format,
- enum pipe_video_chroma_format chroma_format,
- unsigned width, unsigned height)
+ const struct pipe_video_buffer *tmpl)
{
const enum pipe_format *resource_formats;
- struct pipe_video_buffer *result;
- unsigned buffer_width, buffer_height;
+ struct pipe_video_buffer templat;
bool pot_buffers;
assert(pipe);
- assert(width > 0 && height > 0);
+ assert(tmpl->width > 0 && tmpl->height > 0);
pot_buffers = !pipe->screen->get_video_param
(
@@ -272,30 +269,28 @@ vl_video_buffer_create(struct pipe_context *pipe,
PIPE_VIDEO_CAP_NPOT_TEXTURES
);
- resource_formats = vl_video_buffer_formats(pipe->screen, buffer_format);
+ resource_formats = vl_video_buffer_formats(pipe->screen, tmpl->buffer_format);
if (!resource_formats)
return NULL;
- buffer_width = pot_buffers ? util_next_power_of_two(width) : align(width, MACROBLOCK_WIDTH);
- buffer_height = pot_buffers ? util_next_power_of_two(height) : align(height, MACROBLOCK_HEIGHT);
+ templat = *tmpl;
+ templat.width = pot_buffers ? util_next_power_of_two(tmpl->width)
+ : align(tmpl->width, MACROBLOCK_WIDTH);
+ templat.height = pot_buffers ? util_next_power_of_two(tmpl->height)
+ : align(tmpl->height, MACROBLOCK_HEIGHT);
- result = vl_video_buffer_create_ex
+ return vl_video_buffer_create_ex
(
- pipe, buffer_width, buffer_height, 1,
- chroma_format, resource_formats, PIPE_USAGE_STATIC
+ pipe, &templat, resource_formats,
+ 1, PIPE_USAGE_STATIC
);
- if (result)
- result->buffer_format = buffer_format;
-
- return result;
}
struct pipe_video_buffer *
vl_video_buffer_create_ex(struct pipe_context *pipe,
- unsigned width, unsigned height, unsigned depth,
- enum pipe_video_chroma_format chroma_format,
+ const struct pipe_video_buffer *tmpl,
const enum pipe_format resource_formats[VL_MAX_PLANES],
- unsigned usage)
+ unsigned depth, unsigned usage)
{
struct vl_video_buffer *buffer;
struct pipe_resource templ;
@@ -305,21 +300,19 @@ vl_video_buffer_create_ex(struct pipe_context *pipe,
buffer = CALLOC_STRUCT(vl_video_buffer);
+ buffer->base = *tmpl;
buffer->base.context = pipe;
buffer->base.destroy = vl_video_buffer_destroy;
buffer->base.get_sampler_view_planes = vl_video_buffer_sampler_view_planes;
buffer->base.get_sampler_view_components = vl_video_buffer_sampler_view_components;
buffer->base.get_surfaces = vl_video_buffer_surfaces;
- buffer->base.chroma_format = chroma_format;
- buffer->base.width = width;
- buffer->base.height = height;
buffer->num_planes = 1;
memset(&templ, 0, sizeof(templ));
templ.target = depth > 1 ? PIPE_TEXTURE_3D : PIPE_TEXTURE_2D;
templ.format = resource_formats[0];
- templ.width0 = width;
- templ.height0 = height;
+ templ.width0 = tmpl->width;
+ templ.height0 = tmpl->height;
templ.depth0 = depth;
templ.array_size = 1;
templ.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET;
@@ -330,17 +323,17 @@ vl_video_buffer_create_ex(struct pipe_context *pipe,
goto error;
if (resource_formats[1] == PIPE_FORMAT_NONE) {
- assert(chroma_format == PIPE_VIDEO_CHROMA_FORMAT_444);
+ assert(tmpl->chroma_format == PIPE_VIDEO_CHROMA_FORMAT_444);
assert(resource_formats[2] == PIPE_FORMAT_NONE);
return &buffer->base;
} else
buffer->num_planes = 2;
templ.format = resource_formats[1];
- if (chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420) {
+ if (tmpl->chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420) {
templ.width0 /= 2;
templ.height0 /= 2;
- } else if (chroma_format == PIPE_VIDEO_CHROMA_FORMAT_422) {
+ } else if (tmpl->chroma_format == PIPE_VIDEO_CHROMA_FORMAT_422) {
templ.height0 /= 2;
}
diff --git a/src/gallium/auxiliary/vl/vl_video_buffer.h b/src/gallium/auxiliary/vl/vl_video_buffer.h
index e096ccd..e0e29b2 100644
--- a/src/gallium/auxiliary/vl/vl_video_buffer.h
+++ b/src/gallium/auxiliary/vl/vl_video_buffer.h
@@ -90,18 +90,15 @@ vl_video_buffer_get_associated_data(struct pipe_video_buffer *vbuf,
*/
struct pipe_video_buffer *
vl_video_buffer_create(struct pipe_context *pipe,
- enum pipe_format buffer_format,
- enum pipe_video_chroma_format chroma_format,
- unsigned width, unsigned height);
+ const struct pipe_video_buffer *templat);
/**
* extended create function, gets depth, usage and formats for each plane seperately
*/
struct pipe_video_buffer *
vl_video_buffer_create_ex(struct pipe_context *pipe,
- unsigned width, unsigned height, unsigned depth,
- enum pipe_video_chroma_format chroma_format,
+ const struct pipe_video_buffer *templat,
const enum pipe_format resource_formats[VL_MAX_PLANES],
- unsigned usage);
+ unsigned depth, unsigned usage);
#endif /* vl_video_buffer_h */
diff --git a/src/gallium/drivers/nouveau/nouveau_video.c b/src/gallium/drivers/nouveau/nouveau_video.c
index 24a6364..055f925 100644
--- a/src/gallium/drivers/nouveau/nouveau_video.c
+++ b/src/gallium/drivers/nouveau/nouveau_video.c
@@ -780,24 +780,23 @@ nouveau_video_buffer_destroy(struct pipe_video_buffer *buffer)
static struct pipe_video_buffer *
nouveau_video_buffer_create(struct pipe_context *pipe,
struct nouveau_screen *screen,
- enum pipe_format buffer_format,
- enum pipe_video_chroma_format chroma_format,
- unsigned width, unsigned height)
+ const struct pipe_video_buffer *templat)
{
struct nouveau_video_buffer *buffer;
struct pipe_resource templ;
+ unsigned width, height;
/* Only do a linear surface when a hardware decoder is used
* hardware decoder is only supported on some chipsets
* and it only supports the NV12 format
*/
- if (buffer_format != PIPE_FORMAT_NV12 || getenv("XVMC_VL") ||
+ if (templat->buffer_format != PIPE_FORMAT_NV12 || getenv("XVMC_VL") ||
(screen->device->chipset >= 0x98 && screen->device->chipset != 0xa0))
- return vl_video_buffer_create(pipe, buffer_format, chroma_format, width, height);
+ return vl_video_buffer_create(pipe, templat);
- assert(chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420);
- width = align(width, 64);
- height = align(height, 64);
+ assert(templat->chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420);
+ width = align(templat->width, 64);
+ height = align(templat->height, 64);
buffer = CALLOC_STRUCT(nouveau_video_buffer);
if (!buffer)
@@ -808,7 +807,7 @@ nouveau_video_buffer_create(struct pipe_context *pipe,
buffer->base.get_sampler_view_planes = nouveau_video_buffer_sampler_view_planes;
buffer->base.get_sampler_view_components = nouveau_video_buffer_sampler_view_components;
buffer->base.get_surfaces = nouveau_video_buffer_surfaces;
- buffer->base.chroma_format = chroma_format;
+ buffer->base.chroma_format = templat->chroma_format;
buffer->base.width = width;
buffer->base.height = height;
buffer->num_planes = 2;
@@ -882,12 +881,10 @@ nvfx_context_create_decoder(struct pipe_context *context,
static struct pipe_video_buffer *
nvfx_context_video_buffer_create(struct pipe_context *pipe,
- enum pipe_format buffer_format,
- enum pipe_video_chroma_format chroma_format,
- unsigned width, unsigned height)
+ const struct pipe_video_buffer *templat)
{
struct nouveau_screen *screen = &nvfx_context(pipe)->screen->base;
- return nouveau_video_buffer_create(pipe, screen, buffer_format, chroma_format, width, height);
+ return nouveau_video_buffer_create(pipe, screen, templat);
}
void
@@ -913,12 +910,10 @@ nouveau_context_create_decoder(struct pipe_context *context,
static struct pipe_video_buffer *
nouveau_context_video_buffer_create(struct pipe_context *pipe,
- enum pipe_format buffer_format,
- enum pipe_video_chroma_format chroma_format,
- unsigned width, unsigned height)
+ const struct pipe_video_buffer *templat)
{
struct nouveau_screen *screen = nouveau_context(pipe)->screen;
- return nouveau_video_buffer_create(pipe, screen, buffer_format, chroma_format, width, height);
+ return nouveau_video_buffer_create(pipe, screen, templat);
}
void
diff --git a/src/gallium/include/pipe/p_context.h b/src/gallium/include/pipe/p_context.h
index f7ee522..4c58ed0 100644
--- a/src/gallium/include/pipe/p_context.h
+++ b/src/gallium/include/pipe/p_context.h
@@ -417,9 +417,7 @@ struct pipe_context {
* Creates a video buffer as decoding target
*/
struct pipe_video_buffer *(*create_video_buffer)( struct pipe_context *context,
- enum pipe_format buffer_format,
- enum pipe_video_chroma_format chroma_format,
- unsigned width, unsigned height );
+ const struct pipe_video_buffer *templat );
};
diff --git a/src/gallium/state_trackers/vdpau/surface.c b/src/gallium/state_trackers/vdpau/surface.c
index 77503cf..206a839 100644
--- a/src/gallium/state_trackers/vdpau/surface.c
+++ b/src/gallium/state_trackers/vdpau/surface.c
@@ -44,6 +44,7 @@ vlVdpVideoSurfaceCreate(VdpDevice device, VdpChromaType chroma_type,
uint32_t width, uint32_t height,
VdpVideoSurface *surface)
{
+ struct pipe_video_buffer tmpl;
vlVdpSurface *p_surf;
VdpStatus ret;
@@ -72,12 +73,15 @@ vlVdpVideoSurfaceCreate(VdpDevice device, VdpChromaType chroma_type,
}
p_surf->device = dev;
+ memset(&tmpl, 0, sizeof(tmpl));
+ tmpl.buffer_format = PIPE_FORMAT_YV12;
+ tmpl.chroma_format = ChromaToPipe(chroma_type);
+ tmpl.width = width;
+ tmpl.height = height;
p_surf->video_buffer = dev->context->pipe->create_video_buffer
(
dev->context->pipe,
- PIPE_FORMAT_YV12, // most common used
- ChromaToPipe(chroma_type),
- width, height
+ &tmpl
);
*surface = vlAddDataHTAB(p_surf);
diff --git a/src/gallium/state_trackers/xorg/xvmc/surface.c b/src/gallium/state_trackers/xorg/xvmc/surface.c
index b4447c4..ddc937c 100644
--- a/src/gallium/state_trackers/xorg/xvmc/surface.c
+++ b/src/gallium/state_trackers/xorg/xvmc/surface.c
@@ -167,6 +167,7 @@ Status XvMCCreateSurface(Display *dpy, XvMCContext *context, XvMCSurface *surfac
XvMCContextPrivate *context_priv;
struct pipe_context *pipe;
XvMCSurfacePrivate *surface_priv;
+ struct pipe_video_buffer tmpl;
XVMC_MSG(XVMC_TRACE, "[XvMC] Creating surface %p.\n", surface);
@@ -184,12 +185,13 @@ Status XvMCCreateSurface(Display *dpy, XvMCContext *context, XvMCSurface *surfac
if (!surface_priv)
return BadAlloc;
- surface_priv->video_buffer = pipe->create_video_buffer
- (
- pipe, PIPE_FORMAT_NV12, context_priv->decoder->chroma_format,
- context_priv->decoder->width, context_priv->decoder->height
- );
-
+ memset(&tmpl, 0, sizeof(tmpl));
+ tmpl.buffer_format = PIPE_FORMAT_NV12;
+ tmpl.chroma_format = context_priv->decoder->chroma_format;
+ tmpl.width = context_priv->decoder->width;
+ tmpl.height = context_priv->decoder->height;
+
+ surface_priv->video_buffer = pipe->create_video_buffer(pipe, &tmpl);
surface_priv->context = context;
surface->surface_id = XAllocID(dpy);
--
1.7.5.4
More information about the mesa-dev
mailing list