diff mbox

[weston,3/5] compositor: specialised fragment shader for RGBX

Message ID 1346363241-29219-4-git-send-email-rob.clark@linaro.org
State New
Headers show

Commit Message

Rob Clark Aug. 30, 2012, 9:47 p.m. UTC
From: Pekka Paalanen <ppaalanen@gmail.com>

Remove the weston_surface::blend attribute, which really meant that the
texture produced valid alpha values. This was used to override the opaque
region for RGBX surfaces, which produce undefined values for alpha.

Instead, compile a new shader especially for RGBX surfaces, that
hardcodes the sampled alpha as 1.0.

Before "compositor: optimize/simplify shaders" there was a 'vec4 opaque'
in the shaders, that would cause part of the texture to be forced to
alpha=1.0. Now that is gone, and we need this replacement.

To test: launch simple-shm, and use the super+alt+mousewheel combination
to make it transparent. It should not show a light cross over the window.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
---
 src/compositor.c |   22 +++++++++++++++++-----
 src/compositor.h |    2 +-
 2 files changed, 18 insertions(+), 6 deletions(-)
diff mbox

Patch

diff --git a/src/compositor.c b/src/compositor.c
index 228ffe4..030ec8f 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -240,7 +240,6 @@  weston_surface_create(struct weston_compositor *compositor)
 
 	surface->compositor = compositor;
 	surface->alpha = 1.0;
-	surface->blend = 1;
 	surface->opaque_rect[0] = 0.0;
 	surface->opaque_rect[1] = 0.0;
 	surface->opaque_rect[2] = 0.0;
@@ -790,7 +789,6 @@  weston_surface_attach(struct wl_surface *surface, struct wl_buffer *buffer)
 
 	if (wl_buffer_is_shm(buffer)) {
 		es->pitch = wl_shm_buffer_get_stride(buffer) / 4;
-		es->shader = &ec->texture_shader_rgba;
 		es->target = GL_TEXTURE_2D;
 
 		ensure_textures(es, 1);
@@ -799,9 +797,9 @@  weston_surface_attach(struct wl_surface *surface, struct wl_buffer *buffer)
 			     es->pitch, es->buffer->height, 0,
 			     GL_BGRA_EXT, GL_UNSIGNED_BYTE, NULL);
 		if (wl_shm_buffer_get_format(buffer) == WL_SHM_FORMAT_XRGB8888)
-			es->blend = 0;
+			es->shader = &ec->texture_shader_rgbx;
 		else
-			es->blend = 1;
+			es->shader = &ec->texture_shader_rgba;
 	} else if (ec->query_buffer(ec->egl_display, buffer,
 				    EGL_TEXTURE_FORMAT, &format)) {
 		for (i = 0; i < es->num_images; i++)
@@ -1307,7 +1305,7 @@  weston_surface_draw(struct weston_surface *es, struct weston_output *output,
 				 &ec->primary_plane.damage, &repaint);
 
 	glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
-	if (es->blend || es->alpha < 1.0) {
+	if (1 || es->alpha < 1.0) {
 		/* blended region is whole surface minus opaque region: */
 		pixman_region32_init_rect(&surface_blend, 0, 0,
 				es->geometry.width, es->geometry.height);
@@ -3204,6 +3202,17 @@  static const char texture_fragment_shader_rgba[] =
 	"   gl_FragColor = alpha * texture2D(tex, v_texcoord)\n;"
 	"}\n";
 
+static const char texture_fragment_shader_rgbx[] =
+	"precision mediump float;\n"
+	"varying vec2 v_texcoord;\n"
+	"uniform sampler2D tex;\n"
+	"uniform float alpha;\n"
+	"void main()\n"
+	"{\n"
+	"   gl_FragColor.rgb = alpha * texture2D(tex, v_texcoord).rgb\n;"
+	"   gl_FragColor.a = alpha;\n"
+	"}\n";
+
 static const char texture_fragment_shader_egl_external[] =
 	"#extension GL_OES_EGL_image_external : require\n"
 	"precision mediump float;\n"
@@ -3621,6 +3630,9 @@  weston_compositor_init_gl(struct weston_compositor *ec)
 	if (weston_shader_init(&ec->texture_shader_rgba,
 			     vertex_shader, texture_fragment_shader_rgba) < 0)
 		return -1;
+	if (weston_shader_init(&ec->texture_shader_rgbx,
+			     vertex_shader, texture_fragment_shader_rgbx) < 0)
+		return -1;
 	if (has_egl_image_external &&
 			weston_shader_init(&ec->texture_shader_egl_external,
 				vertex_shader, texture_fragment_shader_egl_external) < 0)
diff --git a/src/compositor.h b/src/compositor.h
index 3b8c705..74b154a 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -274,6 +274,7 @@  struct weston_compositor {
 	EGLConfig egl_config;
 	GLuint fbo;
 	struct weston_shader texture_shader_rgba;
+	struct weston_shader texture_shader_rgbx;
 	struct weston_shader texture_shader_egl_external;
 	struct weston_shader texture_shader_y_uv;
 	struct weston_shader texture_shader_y_u_v;
@@ -398,7 +399,6 @@  struct weston_surface {
 	GLfloat color[4];
 	GLfloat opaque_rect[4];
 	GLfloat alpha;
-	int blend;
 	struct weston_plane *plane;
 
 	/* Surface geometry state, mutable.