[PATCH weston] compositor: Address blending for XRGB surfaces with alpha < 1.0.

Scott Moreau oreaus at gmail.com
Tue May 22 01:14:15 PDT 2012


---
 src/compositor.c |   16 ++++++++++------
 src/compositor.h |    1 +
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/src/compositor.c b/src/compositor.c
index ab4c970..820578a 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -854,7 +854,7 @@ weston_surface_draw(struct weston_surface *es, struct weston_output *output,
 		goto out;
 
 	glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
-	if (es->blend)
+	if (es->blend || es->alpha < 1.0)
 		glEnable(GL_BLEND);
 	else
 		glDisable(GL_BLEND);
@@ -874,6 +874,7 @@ weston_surface_draw(struct weston_surface *es, struct weston_output *output,
 	glUniform1f(es->shader->texwidth_uniform,
 		    (GLfloat)es->geometry.width / es->pitch);
 	glUniform4fv(es->shader->opaque_uniform, 1, es->opaque_rect);
+	glUniform1i(es->shader->blend_uniform, es->blend);
 
 	if (es->transform.enabled || output->zoom.active)
 		filter = GL_LINEAR;
@@ -2342,6 +2343,7 @@ static const char texture_fragment_shader[] =
 	"uniform float saturation;\n"
 	"uniform float texwidth;\n"
 	"uniform vec4 opaque;\n"
+	"uniform bool blend;\n"
 	"void main()\n"
 	"{\n"
 	"   if (v_texcoord.x < 0.0 || v_texcoord.x > texwidth ||\n"
@@ -2351,7 +2353,10 @@ static const char texture_fragment_shader[] =
 	"   float gray = dot(gl_FragColor.rgb, vec3(0.299, 0.587, 0.114));\n"
 	"   vec3 range = (gl_FragColor.rgb - vec3 (gray, gray, gray)) * saturation;\n"
 	"   gl_FragColor = vec4(vec3(gray + range), gl_FragColor.a);\n"
-	"   gl_FragColor = vec4(vec3(bright, bright, bright) * gl_FragColor.rgb, gl_FragColor.a);\n"
+	"   if (blend)\n"
+	"      gl_FragColor = vec4(vec3(bright, bright, bright) * gl_FragColor.rgb, gl_FragColor.a);\n"
+	"   else\n"
+	"      gl_FragColor = vec4(vec3(bright, bright, bright) * gl_FragColor.rgb, alpha);\n"
 	"   if (opaque.x <= v_texcoord.x && v_texcoord.x < opaque.y &&\n"
 	"       opaque.z <= v_texcoord.y && v_texcoord.y < opaque.w)\n"
 	"      gl_FragColor.a = 1.0;\n"
@@ -2419,10 +2424,9 @@ weston_shader_init(struct weston_shader *shader,
 	shader->brightness_uniform = glGetUniformLocation(shader->program, "bright");
 	shader->saturation_uniform = glGetUniformLocation(shader->program, "saturation");
 	shader->color_uniform = glGetUniformLocation(shader->program, "color");
-	shader->texwidth_uniform = glGetUniformLocation(shader->program,
-							"texwidth");
-	shader->opaque_uniform =
-		glGetUniformLocation(shader->program, "opaque");
+	shader->texwidth_uniform = glGetUniformLocation(shader->program, "texwidth");
+	shader->opaque_uniform = glGetUniformLocation(shader->program, "opaque");
+	shader->blend_uniform = glGetUniformLocation(shader->program, "blend");
 
 	return 0;
 }
diff --git a/src/compositor.h b/src/compositor.h
index 7af423d..2dbd558 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -172,6 +172,7 @@ struct weston_shader {
 	GLint color_uniform;
 	GLint texwidth_uniform;
 	GLint opaque_uniform;
+	GLint blend_uniform;
 };
 
 struct weston_animation {
-- 
1.7.7.6



More information about the wayland-devel mailing list