summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeo Liu <[email protected]>2017-09-19 12:27:19 -0400
committerLeo Liu <[email protected]>2017-09-25 09:42:14 -0400
commitb47bdf55dc91278e43e31579b7d2a496facae0e8 (patch)
treeada59068c450396f97accff6b37ad62ea3ec9f42
parent737d13637dbf460d379a66bd2d50ef5b27b8571a (diff)
vl/compositor: convert RGB buffer to YUV with color conversion
Acked-by: Christian König <[email protected]>
-rw-r--r--src/gallium/auxiliary/vl/vl_compositor.c69
-rw-r--r--src/gallium/auxiliary/vl/vl_compositor.h12
2 files changed, 81 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/vl/vl_compositor.c b/src/gallium/auxiliary/vl/vl_compositor.c
index c084de9fb09..67ad7f5beea 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,37 @@ 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)
+{
+ vl_csc_matrix csc_matrix;
+
+ 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_csc_get_matrix(VL_CSC_COLOR_STANDARD_BT_709_REV, NULL, false, &csc_matrix);
+ vl_compositor_set_csc_matrix(s, (const vl_csc_matrix *)&csc_matrix, 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 +1312,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);
+
+ 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);
+ pipe_sampler_view_reference(&sv, NULL);
+
+ 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 cbad60a7031..88191762609 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);
+
/*@}*/
/**