[PATCH 3/4] compositor: add YUV shaders.

Gwenole Beauchesne gb.devel at gmail.com
Fri Apr 20 08:17:29 PDT 2012


Add shaders for NV12 (2 planes) and YUV (3 planes).

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne at intel.com>
---
 src/compositor.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 src/compositor.h |    2 ++
 2 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/src/compositor.c b/src/compositor.c
index 53140a2..74aee25 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -2240,6 +2240,12 @@ static const char vertex_shader[] =
 	"   gl_FragColor = vec4(vec3(bright, bright, bright) * gl_FragColor.rgb, gl_FragColor.a);\n" \
 	"   gl_FragColor = alpha * gl_FragColor;\n"
 
+#define FRAGMENT_CONVERT_YUV8						\
+	"  gl_FragColor.r = y + 1.59602678 * v;\n"			\
+	"  gl_FragColor.g = y - 0.39176229 * u - 0.81296764 * v;\n"	\
+	"  gl_FragColor.b = y + 2.01723214 * u;\n"			\
+	"  gl_FragColor.a = 1.0;\n"
+
 static const char texture_fragment_shader_rgba[] =
 	"precision mediump float;\n"
 	"varying vec2 v_texcoord;\n"
@@ -2252,6 +2258,37 @@ static const char texture_fragment_shader_rgba[] =
 	FRAGMENT_SHADER_EXIT
 	"}\n";
 
+static const char texture_fragment_shader_nv12[] =
+	"precision mediump float;\n"
+	"uniform sampler2D tex;\n"
+	"uniform sampler2D tex1;\n"
+	"varying vec2 v_texcoord;\n"
+	FRAGMENT_SHADER_UNIFORMS
+	"void main() {\n"
+	FRAGMENT_SHADER_INIT
+	"  float y = 1.16438356 * (texture2D(tex, v_texcoord).x - 0.0625);\n"
+	"  float u = texture2D(tex1, v_texcoord).r - 0.5;\n"
+	"  float v = texture2D(tex1, v_texcoord).g - 0.5;\n"
+	FRAGMENT_CONVERT_YUV8
+	FRAGMENT_SHADER_EXIT
+	"}\n";
+
+static const char texture_fragment_shader_yuv8[] =
+	"precision mediump float;\n"
+	"uniform sampler2D tex;\n"
+	"uniform sampler2D tex1;\n"
+	"uniform sampler2D tex2;\n"
+	"varying vec2 v_texcoord;\n"
+	FRAGMENT_SHADER_UNIFORMS
+	"void main() {\n"
+	FRAGMENT_SHADER_INIT
+	"  float y = 1.16438356 * (texture2D(tex, v_texcoord).x - 0.0625);\n"
+	"  float u = texture2D(tex1, v_texcoord).x - 0.5;\n"
+	"  float v = texture2D(tex2, v_texcoord).x - 0.5;\n"
+	FRAGMENT_CONVERT_YUV8
+	FRAGMENT_SHADER_EXIT
+	"}\n";
+
 static const char solid_fragment_shader[] =
 	"precision mediump float;\n"
 	"uniform vec4 color;\n"
@@ -2517,6 +2554,12 @@ weston_compositor_init(struct weston_compositor *ec, struct wl_display *display)
 	if (weston_shader_init(&ec->texture_shader_rgba,
 			     vertex_shader, texture_fragment_shader_rgba) < 0)
 		return -1;
+	if (weston_shader_init(&ec->texture_shader_nv12,
+			       vertex_shader, texture_fragment_shader_nv12) < 0)
+		return -1;
+	if (weston_shader_init(&ec->texture_shader_yuv8,
+			       vertex_shader, texture_fragment_shader_yuv8) < 0)
+		return -1;
 	if (weston_shader_init(&ec->solid_shader,
 			     vertex_shader, solid_fragment_shader) < 0)
 		return -1;
diff --git a/src/compositor.h b/src/compositor.h
index ac07a79..e45c377 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -179,6 +179,8 @@ struct weston_compositor {
 	EGLConfig config;
 	GLuint fbo;
 	struct weston_shader texture_shader_rgba;
+	struct weston_shader texture_shader_nv12;
+	struct weston_shader texture_shader_yuv8;
 	struct weston_shader solid_shader;
 	struct weston_shader *current_shader;
 	struct wl_display *wl_display;
-- 
1.7.5.4



More information about the wayland-devel mailing list