[PATCH xserver 3/3] squash: glamor: Fix Render blending for alpha-to-red.
Eric Anholt
eric at anholt.net
Thu Jan 21 18:36:23 PST 2016
Signed-off-by: Eric Anholt <eric at anholt.net>
---
glamor/glamor_render.c | 36 ++++++++++++++++++++++++++++++++----
1 file changed, 32 insertions(+), 4 deletions(-)
diff --git a/glamor/glamor_render.c b/glamor/glamor_render.c
index c36b345..51718d1 100644
--- a/glamor/glamor_render.c
+++ b/glamor/glamor_render.c
@@ -215,8 +215,8 @@ glamor_create_composite_fs(struct shader_key *key)
"out vec4 color1;\n"
"void main()\n"
"{\n"
- " color0 = get_source() * get_mask();\n"
- " color1 = get_source().a * get_mask();\n"
+ " color0 = dest_swizzle(get_source() * get_mask());\n"
+ " color1 = dest_swizzle(get_source().a * get_mask());\n"
"}\n";
const char *header_ca_dual_blend =
"#version 130\n";
@@ -422,11 +422,29 @@ glamor_lookup_composite_shader(ScreenPtr screen, struct
return shader;
}
+static GLenum
+glamor_translate_blend_alpha_to_red(GLenum blend)
+{
+ switch (blend) {
+ case GL_SRC_ALPHA:
+ return GL_SRC_COLOR;
+ case GL_DST_ALPHA:
+ return GL_DST_COLOR;
+ case GL_ONE_MINUS_SRC_ALPHA:
+ return GL_ONE_MINUS_SRC_COLOR;
+ case GL_ONE_MINUS_DST_ALPHA:
+ return GL_ONE_MINUS_DST_COLOR;
+ default:
+ return blend;
+ }
+}
+
static Bool
glamor_set_composite_op(ScreenPtr screen,
CARD8 op, struct blendinfo *op_info_result,
PicturePtr dest, PicturePtr mask,
- enum ca_state ca_state)
+ enum ca_state ca_state,
+ struct shader_key *key)
{
GLenum source_blend, dest_blend;
struct blendinfo *op_info;
@@ -473,6 +491,14 @@ glamor_set_composite_op(ScreenPtr screen,
}
}
+ /* If we're outputting our alpha to the red channel, then any
+ * reads of alpha for blending need to come from the red channel.
+ */
+ if (key->dest_swizzle == SHADER_DEST_SWIZZLE_ALPHA_TO_RED) {
+ source_blend = glamor_translate_blend_alpha_to_red(source_blend);
+ dest_blend = glamor_translate_blend_alpha_to_red(dest_blend);
+ }
+
op_info_result->source_blend = source_blend;
op_info_result->dest_blend = dest_blend;
op_info_result->source_alpha = op_info->source_alpha;
@@ -1006,8 +1032,10 @@ glamor_composite_choose_shader(CARD8 op,
goto fail;
}
- if (!glamor_set_composite_op(screen, op, op_info, dest, mask, ca_state))
+ if (!glamor_set_composite_op(screen, op, op_info, dest, mask, ca_state,
+ &key)) {
goto fail;
+ }
*shader = glamor_lookup_composite_shader(screen, &key);
if ((*shader)->prog == 0) {
--
2.6.4
More information about the xorg-devel
mailing list