diff options
Diffstat (limited to 'src/gallium/auxiliary/vl/vl_video_buffer.c')
-rw-r--r-- | src/gallium/auxiliary/vl/vl_video_buffer.c | 224 |
1 files changed, 121 insertions, 103 deletions
diff --git a/src/gallium/auxiliary/vl/vl_video_buffer.c b/src/gallium/auxiliary/vl/vl_video_buffer.c index f0b3d192eb5..5ea0dfa3736 100644 --- a/src/gallium/auxiliary/vl/vl_video_buffer.c +++ b/src/gallium/auxiliary/vl/vl_video_buffer.c @@ -25,85 +25,18 @@ * **************************************************************************/ -#include "vl_video_buffer.h" -#include <util/u_format.h> -#include <util/u_inlines.h> -#include <util/u_sampler.h> -#include <pipe/p_screen.h> -#include <pipe/p_context.h> #include <assert.h> -bool vl_video_buffer_init(struct vl_video_buffer *buffer, - struct pipe_context *pipe, - unsigned width, unsigned height, unsigned depth, - enum pipe_video_chroma_format chroma_format, - unsigned num_planes, - const enum pipe_format resource_format[VL_MAX_PLANES], - unsigned usage) -{ - struct pipe_resource templ; - unsigned i; - - assert(buffer && pipe); - assert(num_planes > 0 && num_planes <= VL_MAX_PLANES); - - memset(buffer, 0, sizeof(struct vl_video_buffer)); - buffer->pipe = pipe; - buffer->num_planes = num_planes; - - memset(&templ, 0, sizeof(templ)); - templ.target = PIPE_TEXTURE_2D; - templ.format = resource_format[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]) - goto error; - - if (num_planes == 1) { - assert(chroma_format == PIPE_VIDEO_CHROMA_FORMAT_444); - return true; - } - - templ.format = resource_format[1]; - if (chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420) { - if (depth > 1) - templ.depth0 /= 2; - else - templ.width0 /= 2; - templ.height0 /= 2; - } else if (chroma_format == PIPE_VIDEO_CHROMA_FORMAT_422) { - if (depth > 1) - templ.depth0 /= 2; - else - templ.height0 /= 2; - } - - buffer->resources[1] = pipe->screen->resource_create(pipe->screen, &templ); - if (!buffer->resources[1]) - goto error; - - if (num_planes == 2) - return true; - - templ.format = resource_format[2]; - buffer->resources[2] = pipe->screen->resource_create(pipe->screen, &templ); - if (!buffer->resources[2]) - goto error; - - return true; +#include <pipe/p_screen.h> +#include <pipe/p_context.h> +#include <pipe/p_state.h> -error: - for (i = 0; i < VL_MAX_PLANES; ++i) - pipe_resource_reference(&buffer->resources[i], NULL); +#include <util/u_format.h> +#include <util/u_inlines.h> +#include <util/u_sampler.h> +#include <util/u_memory.h> - return false; -} +#include "vl_video_buffer.h" static inline void adjust_swizzle(struct pipe_sampler_view *sv_templ) @@ -116,75 +49,160 @@ adjust_swizzle(struct pipe_sampler_view *sv_templ) } } -vl_sampler_views *vl_video_buffer_sampler_views(struct vl_video_buffer *buffer) +static void +vl_video_buffer_destroy(struct pipe_video_buffer *buffer) +{ + struct vl_video_buffer *buf = (struct vl_video_buffer *)buffer; + unsigned i; + + assert(buf); + + for (i = 0; i < VL_MAX_PLANES; ++i) { + pipe_surface_reference(&buf->surfaces[i], NULL); + pipe_sampler_view_reference(&buf->sampler_views[i], NULL); + pipe_resource_reference(&buf->resources[i], NULL); + } +} + +static struct pipe_sampler_view ** +vl_video_buffer_sampler_views(struct pipe_video_buffer *buffer) { + struct vl_video_buffer *buf = (struct vl_video_buffer *)buffer; struct pipe_sampler_view sv_templ; struct pipe_context *pipe; unsigned i; - assert(buffer); + assert(buf); - pipe = buffer->pipe; + pipe = buf->pipe; - for (i = 0; i < buffer->num_planes; ++i ) { - if (!buffer->sampler_views[i]) { + for (i = 0; i < buf->num_planes; ++i ) { + if (!buf->sampler_views[i]) { memset(&sv_templ, 0, sizeof(sv_templ)); - u_sampler_view_default_template(&sv_templ, buffer->resources[i], buffer->resources[i]->format); + u_sampler_view_default_template(&sv_templ, buf->resources[i], buf->resources[i]->format); adjust_swizzle(&sv_templ); - buffer->sampler_views[i] = pipe->create_sampler_view(pipe, buffer->resources[i], &sv_templ); - if (!buffer->sampler_views[i]) + buf->sampler_views[i] = pipe->create_sampler_view(pipe, buf->resources[i], &sv_templ); + if (!buf->sampler_views[i]) goto error; } } - return &buffer->sampler_views; + return buf->sampler_views; error: - for (i = 0; i < buffer->num_planes; ++i ) - pipe_sampler_view_reference(&buffer->sampler_views[i], NULL); + for (i = 0; i < buf->num_planes; ++i ) + pipe_sampler_view_reference(&buf->sampler_views[i], NULL); return NULL; } -vl_surfaces *vl_video_buffer_surfaces(struct vl_video_buffer *buffer) +static struct pipe_surface ** +vl_video_buffer_surfaces(struct pipe_video_buffer *buffer) { + struct vl_video_buffer *buf = (struct vl_video_buffer *)buffer; struct pipe_surface surf_templ; struct pipe_context *pipe; unsigned i; - assert(buffer); + assert(buf); - pipe = buffer->pipe; + pipe = buf->pipe; - for (i = 0; i < buffer->num_planes; ++i ) { - if (!buffer->surfaces[i]) { + for (i = 0; i < buf->num_planes; ++i ) { + if (!buf->surfaces[i]) { memset(&surf_templ, 0, sizeof(surf_templ)); - surf_templ.format = buffer->resources[i]->format; + surf_templ.format = buf->resources[i]->format; surf_templ.usage = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET; - buffer->surfaces[i] = pipe->create_surface(pipe, buffer->resources[i], &surf_templ); - if (!buffer->surfaces[i]) + buf->surfaces[i] = pipe->create_surface(pipe, buf->resources[i], &surf_templ); + if (!buf->surfaces[i]) goto error; } } - return &buffer->surfaces; + return buf->surfaces; error: - for (i = 0; i < buffer->num_planes; ++i ) - pipe_surface_reference(&buffer->surfaces[i], NULL); + for (i = 0; i < buf->num_planes; ++i ) + pipe_surface_reference(&buf->surfaces[i], NULL); return NULL; } -void vl_video_buffer_cleanup(struct vl_video_buffer *buffer) +struct pipe_video_buffer * +vl_video_buffer_init(struct pipe_video_context *context, + struct pipe_context *pipe, + unsigned width, unsigned height, unsigned depth, + enum pipe_video_chroma_format chroma_format, + unsigned num_planes, + const enum pipe_format resource_formats[VL_MAX_PLANES], + unsigned usage) { + struct vl_video_buffer *buffer; + struct pipe_resource templ; unsigned i; - assert(buffer); + assert(context && pipe); + assert(num_planes > 0 && num_planes <= VL_MAX_PLANES); + + buffer = CALLOC_STRUCT(vl_video_buffer); - for (i = 0; i < VL_MAX_PLANES; ++i) { - pipe_surface_reference(&buffer->surfaces[i], NULL); - pipe_sampler_view_reference(&buffer->sampler_views[i], NULL); - pipe_resource_reference(&buffer->resources[i], NULL); + buffer->base.destroy = vl_video_buffer_destroy; + buffer->base.get_sampler_views = vl_video_buffer_sampler_views; + buffer->base.get_surfaces = vl_video_buffer_surfaces; + buffer->pipe = pipe; + buffer->num_planes = num_planes; + + memset(&templ, 0, sizeof(templ)); + templ.target = 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]) + goto error; + + if (num_planes == 1) { + assert(chroma_format == PIPE_VIDEO_CHROMA_FORMAT_444); + return &buffer->base; + } + + templ.format = resource_formats[1]; + if (chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420) { + if (depth > 1) + templ.depth0 /= 2; + else + templ.width0 /= 2; + templ.height0 /= 2; + } else if (chroma_format == PIPE_VIDEO_CHROMA_FORMAT_422) { + if (depth > 1) + templ.depth0 /= 2; + else + templ.height0 /= 2; } + + buffer->resources[1] = pipe->screen->resource_create(pipe->screen, &templ); + if (!buffer->resources[1]) + goto error; + + if (num_planes == 2) + return &buffer->base; + + templ.format = resource_formats[2]; + buffer->resources[2] = pipe->screen->resource_create(pipe->screen, &templ); + if (!buffer->resources[2]) + goto error; + + return &buffer->base; + +error: + for (i = 0; i < VL_MAX_PLANES; ++i) + pipe_resource_reference(&buffer->resources[i], NULL); + FREE(buffer); + + return NULL; } |