Mesa (master): vl/video_buffer: improve constructor
Christian König
deathsimple at kemper.freedesktop.org
Mon Dec 26 15:38:25 UTC 2011
Module: Mesa
Branch: master
Commit: e81d2b2318f584913d255bb193ed87d456e47883
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=e81d2b2318f584913d255bb193ed87d456e47883
Author: Christian König <deathsimple at vodafone.de>
Date: Tue Dec 20 17:19:19 2011 +0100
vl/video_buffer: improve constructor
Add a second extened constructor that takes plane
textures for the video buffer. Also provide a
function for texture templates.
Signed-off-by: Christian König <deathsimple at vodafone.de>
---
src/gallium/auxiliary/vl/vl_video_buffer.c | 121 +++++++++++++++++-----------
src/gallium/auxiliary/vl/vl_video_buffer.h | 19 +++++
2 files changed, 93 insertions(+), 47 deletions(-)
diff --git a/src/gallium/auxiliary/vl/vl_video_buffer.c b/src/gallium/auxiliary/vl/vl_video_buffer.c
index 8ceb713..c48c18a 100644
--- a/src/gallium/auxiliary/vl/vl_video_buffer.c
+++ b/src/gallium/auxiliary/vl/vl_video_buffer.c
@@ -126,6 +126,33 @@ vl_video_buffer_get_associated_data(struct pipe_video_buffer *vbuf,
return NULL;
}
+void
+vl_vide_buffer_template(struct pipe_resource *templ,
+ unsigned width, unsigned height, unsigned depth,
+ enum pipe_video_chroma_format chroma_format,
+ enum pipe_format resource_format,
+ unsigned usage, unsigned plane)
+{
+ memset(templ, 0, sizeof(*templ));
+ templ->target = depth > 1 ? PIPE_TEXTURE_3D : PIPE_TEXTURE_2D;
+ templ->format = resource_format;
+ templ->width0 = width;
+ templ->height0 = height;
+ templ->depth0 = depth;
+ templ->array_size = 1;
+ templ->bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET;
+ templ->usage = usage;
+
+ if (plane > 0) {
+ if (chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420) {
+ templ->width0 /= 2;
+ templ->height0 /= 2;
+ } else if (chroma_format == PIPE_VIDEO_CHROMA_FORMAT_422) {
+ templ->height0 /= 2;
+ }
+ }
+}
+
static void
vl_video_buffer_destroy(struct pipe_video_buffer *buffer)
{
@@ -297,73 +324,73 @@ vl_video_buffer_create_ex(struct pipe_context *pipe,
const enum pipe_format resource_formats[VL_MAX_PLANES],
unsigned usage)
{
- struct vl_video_buffer *buffer;
- struct pipe_resource templ;
+ struct pipe_resource templ, *resources[VL_MAX_PLANES] = {};
unsigned i;
assert(pipe);
- buffer = CALLOC_STRUCT(vl_video_buffer);
-
- 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.depth0 = depth;
- templ.array_size = 1;
- templ.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET;
- templ.usage = usage;
-
- buffer->resources[0] = pipe->screen->resource_create(pipe->screen, &templ);
- if (!buffer->resources[0])
+ vl_vide_buffer_template(&templ, width, height, depth, chroma_format,
+ resource_formats[0], usage, 0);
+ resources[0] = pipe->screen->resource_create(pipe->screen, &templ);
+ if (!resources[0])
goto error;
if (resource_formats[1] == PIPE_FORMAT_NONE) {
assert(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) {
- templ.width0 /= 2;
- templ.height0 /= 2;
- } else if (chroma_format == PIPE_VIDEO_CHROMA_FORMAT_422) {
- templ.height0 /= 2;
+ return vl_video_buffer_create_ex2(pipe, width, height, chroma_format, resources);
}
- buffer->resources[1] = pipe->screen->resource_create(pipe->screen, &templ);
- if (!buffer->resources[1])
+ vl_vide_buffer_template(&templ, width, height, depth, chroma_format,
+ resource_formats[1], usage, 1);
+ resources[1] = pipe->screen->resource_create(pipe->screen, &templ);
+ if (!resources[1])
goto error;
if (resource_formats[2] == PIPE_FORMAT_NONE)
- return &buffer->base;
- else
- buffer->num_planes = 3;
+ return vl_video_buffer_create_ex2(pipe, width, height, chroma_format, resources);
- templ.format = resource_formats[2];
- buffer->resources[2] = pipe->screen->resource_create(pipe->screen, &templ);
- if (!buffer->resources[2])
+ vl_vide_buffer_template(&templ, width, height, depth, chroma_format,
+ resource_formats[2], usage, 2);
+ resources[2] = pipe->screen->resource_create(pipe->screen, &templ);
+ if (!resources[2])
goto error;
- return &buffer->base;
+ return vl_video_buffer_create_ex2(pipe, width, height, chroma_format, resources);
error:
for (i = 0; i < VL_MAX_PLANES; ++i)
- pipe_resource_reference(&buffer->resources[i], NULL);
- FREE(buffer);
+ pipe_resource_reference(&resources[i], NULL);
return NULL;
}
+
+struct pipe_video_buffer *
+vl_video_buffer_create_ex2(struct pipe_context *pipe,
+ unsigned width, unsigned height,
+ enum pipe_video_chroma_format chroma_format,
+ struct pipe_resource *resources[VL_MAX_PLANES])
+{
+ struct vl_video_buffer *buffer;
+ unsigned i;
+
+ buffer = CALLOC_STRUCT(vl_video_buffer);
+
+ 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 = 0;
+
+ for (i = 0; i < VL_MAX_PLANES; ++i) {
+ buffer->resources[i] = resources[i];
+ if (resources[i])
+ buffer->num_planes++;
+ }
+
+ return &buffer->base;
+}
diff --git a/src/gallium/auxiliary/vl/vl_video_buffer.h b/src/gallium/auxiliary/vl/vl_video_buffer.h
index e096ccd..5f5e7c0 100644
--- a/src/gallium/auxiliary/vl/vl_video_buffer.h
+++ b/src/gallium/auxiliary/vl/vl_video_buffer.h
@@ -86,6 +86,16 @@ vl_video_buffer_get_associated_data(struct pipe_video_buffer *vbuf,
struct pipe_video_decoder *vdec);
/**
+ * fill a resource template for the given plane
+ */
+void
+vl_vide_buffer_template(struct pipe_resource *templ,
+ unsigned width, unsigned height, unsigned depth,
+ enum pipe_video_chroma_format chroma_format,
+ enum pipe_format resource_format,
+ unsigned usage, unsigned plane);
+
+/**
* creates a video buffer, can be used as a standard implementation for pipe->create_video_buffer
*/
struct pipe_video_buffer *
@@ -104,4 +114,13 @@ vl_video_buffer_create_ex(struct pipe_context *pipe,
const enum pipe_format resource_formats[VL_MAX_PLANES],
unsigned usage);
+/**
+ * even more extended create function, provide the pipe_resource for each plane
+ */
+struct pipe_video_buffer *
+vl_video_buffer_create_ex2(struct pipe_context *pipe,
+ unsigned width, unsigned height,
+ enum pipe_video_chroma_format chroma_format,
+ struct pipe_resource *resources[VL_MAX_PLANES]);
+
#endif /* vl_video_buffer_h */
More information about the mesa-commit
mailing list