[Mesa-dev] [RFC PATCH 1/7] gallium/util: Add a video compositor abstraction
Thomas Hellstrom
thellstrom at vmware.com
Thu Mar 2 20:00:05 UTC 2017
Makes it possible for drivers to provide a single implementation
for multiple state-trackers and to utilize dedicated post-processing
engines. The API is very similar to the vl compositor, but also includes
a generic filter mechanism.
Signed-off-by: Thomas Hellstrom <thellstrom at vmware.com>
Reviewed-by: Brian Paul <brianp at vmware.com>
---
src/gallium/auxiliary/Makefile.sources | 1 +
src/gallium/auxiliary/util/u_video_compositor.h | 272 ++++++++++++++++++++++++
2 files changed, 273 insertions(+)
create mode 100644 src/gallium/auxiliary/util/u_video_compositor.h
diff --git a/src/gallium/auxiliary/Makefile.sources b/src/gallium/auxiliary/Makefile.sources
index 8d3e4a9..18a822f 100644
--- a/src/gallium/auxiliary/Makefile.sources
+++ b/src/gallium/auxiliary/Makefile.sources
@@ -311,6 +311,7 @@ C_SOURCES := \
util/u_vbuf.c \
util/u_vbuf.h \
util/u_video.h \
+ util/u_video_compositor.h \
util/u_viewport.h
NIR_SOURCES := \
diff --git a/src/gallium/auxiliary/util/u_video_compositor.h b/src/gallium/auxiliary/util/u_video_compositor.h
new file mode 100644
index 0000000..7d0c72a
--- /dev/null
+++ b/src/gallium/auxiliary/util/u_video_compositor.h
@@ -0,0 +1,272 @@
+/**************************************************************************
+ *
+ * Copyright 2009 Younes Manton.
+ * Copyright 2016 VMware Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+/*
+ * An abstraction of a video compositor which is based on the G3DVL compositor
+ * by Younes Manton. The intention of the abstraction is to be able to
+ * provide certain functions in specialized hardware and to customize
+ * compositor functions for limitations of the video surfaces, so strictly
+ * this header could be promoted to a gallium pipe interface, but
+ * keep it as a utility for now.
+ */
+
+#ifndef _U_VIDEO_COMPOSITOR_H_
+#define _U_VIDEO_COMPOSITOR_H_
+
+#include <pipe/p_defines.h>
+#include <pipe/p_video_codec.h>
+#include <pipe/p_context.h>
+#include <util/u_rect.h>
+#include <stddef.h>
+
+/* Perhaps rework the interface to remove this struct? */
+struct util_video_vertex4f {
+ float x, y, z, w;
+};
+
+/* Deinterlace algorithm */
+enum util_video_compositor_deinterlace
+{
+ UTIL_VIDEO_COMPOSITOR_WEAVE,
+ UTIL_VIDEO_COMPOSITOR_BOB_TOP,
+ UTIL_VIDEO_COMPOSITOR_BOB_BOTTOM
+};
+
+/* Degrees clockwise */
+enum util_video_compositor_rotation
+{
+ UTIL_VIDEO_COMPOSITOR_ROTATE_0,
+ UTIL_VIDEO_COMPOSITOR_ROTATE_90,
+ UTIL_VIDEO_COMPOSITOR_ROTATE_180,
+ UTIL_VIDEO_COMPOSITOR_ROTATE_270
+};
+
+/** \brief Filter type. Add new filters here */
+enum util_video_filter_type
+{
+ UTIL_VIDEO_FILTER_LUMA_KEY, /**< \brief Luma key filter */
+ UTIL_VIDEO_FILTER_DEINT_TEMPORAL, /**< \brief Temporal deinterlacing */
+ UTIL_VIDEO_FILTER_SHARPNESS, /**< \brief Sharpening / Blurring */
+ UTIL_VIDEO_FILTER_NOISE_REDUCTION, /**< \brief Noise reduction */
+ UTIL_VIDEO_FILTER_HQ_SCALING /**< \breif High quality scaling */
+};
+
+/** \brief A filter base type. New filter types should derive from this type */
+struct util_video_filter {
+ enum util_video_filter_type ftype; /**< \brief Filter type (see above) */
+ bool enabled; /**< \brief Whether enabled */
+};
+
+/** \brief Luma key filter */
+struct util_video_filter_luma_key {
+ struct util_video_filter filter;
+ float luma_min; /**< \brief Luma min value */
+ float luma_max; /**< \brief Luma max value */
+};
+
+/** \brief Deinterlacing filter */
+struct util_video_filter_deint {
+ struct util_video_filter filter;
+ /** \brief Whether to skip chroma deinterlacing */
+ bool skip_chroma;
+};
+
+/** \brief Sharpening / Blurring filter */
+struct util_video_filter_sharpness {
+ struct util_video_filter filter;
+ /** \brief 0. - 1. means sharpening. -1. to 0. means blurring. */
+ float value;
+};
+
+/** \brief Noise reduction filter */
+struct util_video_filter_noise_red {
+ struct util_video_filter filter;
+ /** \brief Level of noise reduction */
+ float level;
+};
+
+/** \brief High quality scaling filter */
+struct util_video_filter_hq_scaling {
+ struct util_video_filter filter;
+ /** \brief Quality level 1 - 9 */
+ unsigned level;
+};
+
+/**
+ * \brief Get the container base type
+ *
+ * \param ptr[in] The pointer to the base type.
+ * \param type[in] The derived type.
+ * \return A derived type pointer to the container.
+ */
+#define to_video_filter_container(ptr, type) \
+ ((type *)((char *)ptr - offsetof(type, filter)))
+
+/*
+ * Video conversion (aka transfer) matrix. Not all hardware
+ * (or virtual hardware for that matter) allows specifying the full matrix
+ * so we should perhaps provide a utility that attempts to reconstruct this
+ * matrix to base matrix + brightness, contrast, hue and saturation.
+ */
+typedef float util_video_compositor_csc_matrix[3][4];
+
+struct util_video_compositor_context {
+ struct util_video_compositor *compositor;
+
+ /**
+ * Specify the video conversion matrix
+ */
+ bool (*set_csc_matrix) (struct util_video_compositor_context *ctx,
+ const util_video_compositor_csc_matrix *matrix);
+ /**
+ * Set the clear color
+ */
+ void (*set_clear_color)(struct util_video_compositor_context *ctx,
+ const union pipe_color_union *color);
+
+ /**
+ * Get the clear color
+ */
+ void (*get_clear_color)(struct util_video_compositor_context *ctx,
+ union pipe_color_union *color);
+
+ /**
+ * Set the destination clipping
+ */
+ void (*set_dst_clip)(struct util_video_compositor_context *ctx,
+ const struct u_rect *dst_clip);
+
+ /**
+ * Set overlay samplers
+ */
+ /*@{*/
+
+ /**
+ * reset all currently set layers
+ */
+ void (*clear_layers)(struct util_video_compositor_context *ctx);
+
+ /**
+ * Set the blender used to render a layer
+ */
+ void (*set_layer_blend)(struct util_video_compositor_context *ctx,
+ unsigned layer,
+ const void *blend,
+ bool is_clearing);
+
+ /**
+ * Set the layer destination area
+ */
+ void (*set_layer_dst_area)(struct util_video_compositor_context *ctx,
+ unsigned layer,
+ const struct u_rect *dst_area);
+
+ /**
+ * Set a video buffer as a layer to render
+ */
+ void (*set_buffer_layer)(struct util_video_compositor_context *ctx,
+ unsigned layer,
+ struct pipe_video_buffer *buffer,
+ const struct u_rect *src_rect,
+ const struct u_rect *dst_rect,
+ enum util_video_compositor_deinterlace deinterlace);
+
+ /**
+ * Set a paletted sampler as a layer to render
+ */
+ void (*set_palette_layer)(struct util_video_compositor_context *ctx,
+ unsigned layer,
+ struct pipe_sampler_view *indices,
+ struct pipe_sampler_view *palette,
+ const struct u_rect *src_rect,
+ const struct u_rect *dst_rect,
+ bool include_color_conversion);
+
+ /**
+ * Set an rgba sampler as a layer to render
+ */
+ void (*set_rgba_layer)(struct util_video_compositor_context *ctx,
+ unsigned layer,
+ struct pipe_sampler_view *rgba,
+ const struct u_rect *src_rect,
+ const struct u_rect *dst_rect,
+ const struct util_video_vertex4f *colors);
+
+ /**
+ * Set the layer rotation
+ */
+ void (*set_layer_rotation)(struct util_video_compositor_context *ctx,
+ unsigned layer,
+ enum util_video_compositor_rotation rotate);
+
+ /**
+ * Set a filter for the buffer layer.
+ */
+ bool (*set_buffer_filter)(struct util_video_compositor_context *ctx,
+ const struct util_video_filter *filter);
+
+ /*@}*/
+
+ /**
+ * Render the layers to the dst_surface.
+ */
+ void (*render)(struct util_video_compositor_context *ctx,
+ struct pipe_surface *dst_surface,
+ struct u_rect *dirty_area,
+ bool clear_dirty,
+ struct pipe_video_buffer *past[],
+ struct pipe_video_buffer *future[],
+ unsigned num_past,
+ unsigned num_future);
+
+ void (*destroy)(struct util_video_compositor_context *ctx);
+};
+
+struct util_video_compositor {
+ struct pipe_context *pipe;
+
+ /**
+ * Query the max number of layers
+ */
+ unsigned (*query_max_layers)(struct util_video_compositor *);
+
+ /**
+ * Create a context.
+ */
+ struct util_video_compositor_context *
+ (*context_create)(struct util_video_compositor *);
+
+ int (*buffer_filter_supported) (struct util_video_compositor *,
+ enum util_video_filter_type);
+
+ /**
+ * Destroy the compositor object and free its resources.
+ */
+ void (*destroy)(struct util_video_compositor *);
+};
+
+#endif
--
2.4.11
More information about the mesa-dev
mailing list