summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>2012-04-20 11:44:06 +0200
committerKristian Høgsberg <krh@bitplanet.net>2012-07-04 00:19:32 -0400
commit6b7d3b473f96635b4f4c89f961b6ea432ff4aaa0 (patch)
tree15c62fde21abae8a3fd2cef32c8e47fa8237b96e
parente1ed146d79faccac4fd706685b2ef59254876102 (diff)
compositor: handle YUV buffers.video
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
-rw-r--r--src/compositor-wayland.c2
-rw-r--r--src/compositor.c64
-rw-r--r--src/compositor.h2
-rw-r--r--src/weston-egl-ext.h1
4 files changed, 54 insertions, 15 deletions
diff --git a/src/compositor-wayland.c b/src/compositor-wayland.c
index 586dc19e..cd779a9b 100644
--- a/src/compositor-wayland.c
+++ b/src/compositor-wayland.c
@@ -188,7 +188,7 @@ draw_border(struct wayland_output *output)
glUniformMatrix4fv(shader->proj_uniform,
1, GL_FALSE, output->base.matrix.d);
- glUniform1i(shader->tex_uniform, 0);
+ glUniform1i(shader->tex_uniforms[0], 0);
glUniform1f(shader->alpha_uniform, 1);
glUniform1f(shader->texwidth_uniform, 1);
diff --git a/src/compositor.c b/src/compositor.c
index 4db7a88a..43075bdf 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -733,7 +733,8 @@ weston_surface_attach(struct wl_surface *surface, struct wl_buffer *buffer)
{
struct weston_surface *es = (struct weston_surface *) surface;
struct weston_compositor *ec = es->compositor;
- int i;
+ EGLint attribs[3];
+ int i, num_planes;
if (es->buffer) {
weston_buffer_post_release(es->buffer);
@@ -780,19 +781,51 @@ weston_surface_attach(struct wl_surface *surface, struct wl_buffer *buffer)
else
es->blend = 1;
} else {
- if (es->images[0] != EGL_NO_IMAGE_KHR)
+ for (i = 0; i < es->num_images; i++)
ec->destroy_image(ec->egl_display, es->images[0]);
+ es->num_images = 0;
+
es->images[0] = ec->create_image(ec->egl_display, NULL,
EGL_WAYLAND_BUFFER_WL,
buffer, NULL);
- es->num_images = 1;
- ensure_textures(es, 1);
- glBindTexture(GL_TEXTURE_2D, es->textures[0]);
- ec->image_target_texture_2d(GL_TEXTURE_2D, es->images[0]);
+ switch (buffer->format) {
+ case WL_BUFFER_FORMAT_ARGB8888:
+ case WL_BUFFER_FORMAT_XRGB8888:
+ default:
+ num_planes = 1;
+ es->shader = &ec->texture_shader_argb;
+ break;
+ case WL_BUFFER_FORMAT_NV12:
+ num_planes = 2;
+ es->shader = &ec->texture_shader_nv12;
+ break;
+ case WL_BUFFER_FORMAT_YUV420:
+ num_planes = 3;
+ es->shader = &ec->texture_shader_yuv8;
+ break;
+ }
+
+ ensure_textures(es, num_planes);
+ for (i = 0; i < num_planes; i++) {
+ attribs[0] = EGL_WAYLAND_PLANE_WL;
+ attribs[1] = i;
+ attribs[2] = EGL_NONE;
+ es->images[i] = ec->create_image(ec->egl_display,
+ NULL,
+ EGL_WAYLAND_BUFFER_WL,
+ buffer, attribs);
+ if (!es->images[i])
+ continue;
+ es->num_images++;
+
+ glActiveTexture(GL_TEXTURE0 + i);
+ glBindTexture(GL_TEXTURE_2D, es->textures[i]);
+ ec->image_target_texture_2d(GL_TEXTURE_2D,
+ es->images[i]);
+ }
es->pitch = buffer->width;
- es->shader = &ec->texture_shader_argb;
}
}
@@ -861,7 +894,7 @@ weston_surface_draw(struct weston_surface *es, struct weston_output *output,
GLfloat *v;
pixman_region32_t repaint;
GLint filter;
- int n;
+ int i, n;
pixman_region32_init(&repaint);
pixman_region32_intersect(&repaint,
@@ -884,7 +917,6 @@ weston_surface_draw(struct weston_surface *es, struct weston_output *output,
glUniformMatrix4fv(es->shader->proj_uniform,
1, GL_FALSE, output->matrix.d);
- glUniform1i(es->shader->tex_uniform, 0);
glUniform4fv(es->shader->color_uniform, 1, es->color);
glUniform1f(es->shader->alpha_uniform, es->alpha);
glUniform1f(es->shader->texwidth_uniform,
@@ -901,9 +933,13 @@ weston_surface_draw(struct weston_surface *es, struct weston_output *output,
n = texture_region(es, &repaint);
- glBindTexture(GL_TEXTURE_2D, es->textures[0]);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
+ for (i = 0; i < es->num_textures; i++) {
+ glUniform1i(es->shader->tex_uniforms[i], i);
+ glActiveTexture(GL_TEXTURE0 + i);
+ glBindTexture(GL_TEXTURE_2D, es->textures[i]);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
+ }
v = ec->vertices.data;
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof *v, &v[0]);
@@ -2887,7 +2923,9 @@ weston_shader_init(struct weston_shader *shader,
}
shader->proj_uniform = glGetUniformLocation(shader->program, "proj");
- shader->tex_uniform = glGetUniformLocation(shader->program, "tex");
+ shader->tex_uniforms[0] = glGetUniformLocation(shader->program, "tex");
+ shader->tex_uniforms[1] = glGetUniformLocation(shader->program, "tex1");
+ shader->tex_uniforms[2] = glGetUniformLocation(shader->program, "tex2");
shader->alpha_uniform = glGetUniformLocation(shader->program, "alpha");
shader->color_uniform = glGetUniformLocation(shader->program, "color");
shader->texwidth_uniform = glGetUniformLocation(shader->program, "texwidth");
diff --git a/src/compositor.h b/src/compositor.h
index edba4495..5d408734 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -244,7 +244,7 @@ struct weston_shader {
GLuint program;
GLuint vertex_shader, fragment_shader;
GLint proj_uniform;
- GLint tex_uniform;
+ GLint tex_uniforms[3];
GLint alpha_uniform;
GLint color_uniform;
GLint texwidth_uniform;
diff --git a/src/weston-egl-ext.h b/src/weston-egl-ext.h
index cd8995fb..3d331270 100644
--- a/src/weston-egl-ext.h
+++ b/src/weston-egl-ext.h
@@ -34,6 +34,7 @@
#define EGL_WL_bind_wayland_display 1
#define EGL_WAYLAND_BUFFER_WL 0x31D5 /* eglCreateImageKHR target */
+#define EGL_WAYLAND_BUFFER_PLANE_WL 0x31D6 /* eglCreateImageKHR attribute */
struct wl_display;
#ifdef EGL_EGLEXT_PROTOTYPES
EGLAPI EGLBoolean EGLAPIENTRY eglBindWaylandDisplayWL(EGLDisplay dpy, struct wl_display *display);