From 0075c90d3192ba90ff1ae8a7b04bfc3ff4fccda7 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 10 Mar 2014 15:17:51 +0000 Subject: [PATCH] sna/gen2: Fix alpha blending with 8bit destination surfaces On gen2 (like gen3), 8-bit destination surfaces are read into the Green channel (and written to from the Green channel). Therefore the expected alpha blending must instead be converted to colour blending. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=75818 Signed-off-by: Chris Wilson --- src/sna/gen2_render.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/sna/gen2_render.c b/src/sna/gen2_render.c index da7049c1..3de0a8fe 100644 --- a/src/sna/gen2_render.c +++ b/src/sna/gen2_render.c @@ -425,14 +425,28 @@ static uint32_t gen2_get_blend_cntl(int op, sblend = gen2_blend_op[op].src_blend; dblend = gen2_blend_op[op].dst_blend; - /* If there's no dst alpha channel, adjust the blend op so that - * we'll treat it as always 1. - */ - if (PICT_FORMAT_A(dst_format) == 0 && gen2_blend_op[op].dst_alpha) { - if (sblend == BLENDFACTOR_DST_ALPHA) - sblend = BLENDFACTOR_ONE; - else if (sblend == BLENDFACTOR_INV_DST_ALPHA) - sblend = BLENDFACTOR_ZERO; + if (gen2_blend_op[op].dst_alpha) { + /* If there's no dst alpha channel, adjust the blend op so that + * we'll treat it as always 1. + */ + if (PICT_FORMAT_A(dst_format) == 0) { + if (sblend == BLENDFACTOR_DST_ALPHA) + sblend = BLENDFACTOR_ONE; + else if (sblend == BLENDFACTOR_INV_DST_ALPHA) + sblend = BLENDFACTOR_ZERO; + } + + /* gen2 engine reads 8bit color buffer into green channel + * in cases like color buffer blending etc., and also writes + * back green channel. So with dst_alpha blend we should use + * color factor. + */ + if (dst_format == PICT_a8) { + if (sblend == BLENDFACTOR_DST_ALPHA) + sblend = BLENDFACTOR_DST_COLR; + else if (sblend == BLENDFACTOR_INV_DST_ALPHA) + sblend = BLENDFACTOR_INV_DST_COLR; + } } /* If the source alpha is being used, then we should only be in a case