summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>2012-04-20 11:22:16 +0200
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>2012-04-27 16:27:28 +0200
commitaa16c8505a8b393f34a1026e78f02ab0b86acdab (patch)
tree79a5fc7d23174eabc38e8ed47c2497bdd55eb66a
parent520d44325af6d18e9bf618718f04b5ff24007c67 (diff)
compositor: add YUV shaders.
Add shaders for NV12 (2 planes) and YUV (3 planes). Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
-rw-r--r--src/compositor.c43
-rw-r--r--src/compositor.h2
2 files changed, 45 insertions, 0 deletions
diff --git a/src/compositor.c b/src/compositor.c
index 22a4468..08e8d55 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -2274,6 +2274,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"
@@ -2286,6 +2292,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"
@@ -2573,6 +2610,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 d83a6dc..ada5743 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -201,6 +201,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;