[Mesa-dev] [PATCH 13/14] vl/compositor: convert RGB buffer to YUV with color conversion

Christian König ckoenig.leichtzumerken at gmail.com
Wed Sep 20 07:56:16 UTC 2017


Am 19.09.2017 um 21:05 schrieb Leo Liu:
> ---
>   src/gallium/auxiliary/vl/vl_compositor.c | 71 ++++++++++++++++++++++++++++++++
>   src/gallium/auxiliary/vl/vl_compositor.h | 12 ++++++
>   2 files changed, 83 insertions(+)
>
> diff --git a/src/gallium/auxiliary/vl/vl_compositor.c b/src/gallium/auxiliary/vl/vl_compositor.c
> index c084de9..b1c39e1 100644
> --- a/src/gallium/auxiliary/vl/vl_compositor.c
> +++ b/src/gallium/auxiliary/vl/vl_compositor.c
> @@ -34,6 +34,7 @@
>   #include "util/u_draw.h"
>   #include "util/u_surface.h"
>   #include "util/u_upload_mgr.h"
> +#include "util/u_sampler.h"
>   
>   #include "tgsi/tgsi_ureg.h"
>   
> @@ -992,6 +993,39 @@ set_yuv_layer(struct vl_compositor_state *s, struct vl_compositor *c,
>      }
>   }
>   
> +static void
> +set_rgb_to_yuv_layer(struct vl_compositor_state *s, struct vl_compositor *c,
> +                     unsigned layer, struct pipe_sampler_view *v,
> +                     struct u_rect *src_rect, struct u_rect *dst_rect, bool y)
> +{
> +   static const vl_csc_matrix bt_709_full_rev  = {
> +      { 0.183f,  0.614f,  0.062f, 0.0625f},
> +      {-0.101f, -0.338f,  0.439f, 0.5f   },
> +      { 0.439f, -0.399f, -0.040f, 0.5f   }
> +   };

Better put this into vl_csc.c. Apart from that the set looks good to me.

Patch #1 is Reviewed-by: Christian König <christian.koenig at amd.com>.

The rest is Acked-by: Christian König <christian.koenig at amd.com>.

Regards,
Christian.

> +
> +   assert(s && c && v);
> +
> +   assert(layer < VL_COMPOSITOR_MAX_LAYERS);
> +
> +   s->used_layers |= 1 << layer;
> +
> +   s->layers[layer].fs = y? c->fs_rgb_yuv.y : c->fs_rgb_yuv.uv;
> +   vl_compositor_set_csc_matrix(s, (const vl_csc_matrix *)&bt_709_full_rev, 1.0f, 0.0f);
> +
> +   s->layers[layer].samplers[0] = c->sampler_linear;
> +   s->layers[layer].samplers[1] = NULL;
> +   s->layers[layer].samplers[2] = NULL;
> +
> +   pipe_sampler_view_reference(&s->layers[layer].sampler_views[0], v);
> +   pipe_sampler_view_reference(&s->layers[layer].sampler_views[1], NULL);
> +   pipe_sampler_view_reference(&s->layers[layer].sampler_views[2], NULL);
> +
> +   calc_src_and_dst(&s->layers[layer], v->texture->width0, v->texture->height0,
> +                    src_rect ? *src_rect : default_rect(&s->layers[layer]),
> +                    dst_rect ? *dst_rect : default_rect(&s->layers[layer]));
> +}
> +
>   void
>   vl_compositor_reset_dirty_area(struct u_rect *dirty)
>   {
> @@ -1280,6 +1314,43 @@ vl_compositor_yuv_deint_full(struct vl_compositor_state *s,
>   }
>   
>   void
> +vl_compositor_convert_rgb_to_yuv(struct vl_compositor_state *s,
> +                                 struct vl_compositor *c,
> +                                 unsigned layer,
> +                                 struct pipe_resource *src_res,
> +                                 struct pipe_video_buffer *dst,
> +                                 struct u_rect *src_rect,
> +                                 struct u_rect *dst_rect)
> +{
> +   struct pipe_sampler_view *sv, sv_templ;
> +   struct pipe_surface **dst_surfaces;
> +
> +   dst_surfaces = dst->get_surfaces(dst);
> +   vl_compositor_clear_layers(s);
> +
> +   memset(&sv_templ, 0, sizeof(sv_templ));
> +   u_sampler_view_default_template(&sv_templ, src_res, src_res->format);
> +   sv = s->pipe->create_sampler_view(s->pipe, src_res, &sv_templ);
> +
> +   vl_compositor_clear_layers(s);
> +
> +   set_rgb_to_yuv_layer(s, c, 0, sv, src_rect, NULL, true);
> +   vl_compositor_set_layer_dst_area(s, 0, dst_rect);
> +   vl_compositor_render(s, c, dst_surfaces[0], NULL, false);
> +
> +   if (dst_rect) {
> +      dst_rect->x1 /= 2;
> +      dst_rect->y1 /= 2;
> +   }
> +
> +   set_rgb_to_yuv_layer(s, c, 0, sv, src_rect, NULL, false);
> +   vl_compositor_set_layer_dst_area(s, 0, dst_rect);
> +   vl_compositor_render(s, c, dst_surfaces[1], NULL, false);
> +
> +   s->pipe->flush(s->pipe, NULL, 0);
> +}
> +
> +void
>   vl_compositor_render(struct vl_compositor_state *s,
>                        struct vl_compositor       *c,
>                        struct pipe_surface        *dst_surface,
> diff --git a/src/gallium/auxiliary/vl/vl_compositor.h b/src/gallium/auxiliary/vl/vl_compositor.h
> index cbad60a..8819176 100644
> --- a/src/gallium/auxiliary/vl/vl_compositor.h
> +++ b/src/gallium/auxiliary/vl/vl_compositor.h
> @@ -263,6 +263,18 @@ vl_compositor_yuv_deint_full(struct vl_compositor_state *state,
>                                struct u_rect *dst_rect,
>                                enum vl_compositor_deinterlace deinterlace);
>   
> +/**
> ++ * convert rgb to yuv
> ++ */
> +void
> +vl_compositor_convert_rgb_to_yuv(struct vl_compositor_state *state,
> +                                 struct vl_compositor *compositor,
> +                                 unsigned layer,
> +                                 struct pipe_resource *src_res,
> +                                 struct pipe_video_buffer *dst,
> +                                 struct u_rect *src_rect,
> +                                 struct u_rect *dst_rect);
> +
>   /*@}*/
>   
>   /**




More information about the mesa-dev mailing list