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

Kristian Høgsberg hoegsberg at gmail.com
Tue May 22 08:32:51 PDT 2012


On Tue, May 22, 2012 at 02:14:15AM -0600, Scott Moreau wrote:
> ---
>  src/compositor.c |   16 ++++++++++------
>  src/compositor.h |    1 +
>  2 files changed, 11 insertions(+), 6 deletions(-)

We have an "opaque_rect" feature now, that makes the shader force
alpha=1 within that rect.  Instead of adding another uniform, we
should set opaque_rect = { 0.0, 1.0, 0.0, 1.0 } when es->blend is 0.

> 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);

Maybe something like this

  GLfloat surface_rect[4] = { 0.0, 1.0, 0.0, 1.0 };
  if (es->blend)
  	glUniform4fv(es->shader->opaque_uniform, 1, es->opaque_rect);
  else
  	glUniform4fv(es->shader->opaque_uniform, 1, surface_rect);


>  	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
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list