[PATCH 1/2] drm/vkms: Use alpha for blending in blend() function

Mamta Shukla mamtashukla555 at gmail.com
Thu Jan 24 04:51:52 UTC 2019


Use the alpha value to blend vaddr_src with vaddr_dst instead
of overwriting it in blend().

Signed-off-by: Mamta Shukla <mamtashukla555 at gmail.com>
---
 drivers/gpu/drm/vkms/vkms_crc.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_crc.c b/drivers/gpu/drm/vkms/vkms_crc.c
index 9d9e8146db90..13d5ffed9135 100644
--- a/drivers/gpu/drm/vkms/vkms_crc.c
+++ b/drivers/gpu/drm/vkms/vkms_crc.c
@@ -70,7 +70,8 @@ static void blend(void *vaddr_dst, void *vaddr_src,
 
 	int y_limit = y_src + h_dst;
 	int x_limit = x_src + w_dst;
-
+	u8 alpha, r_src, r_dst, g_src, g_dst, b_src, b_dst;
+	u8 r_alpha, g_alpha, b_alpha;
 	for (i = y_src, i_dst = y_dst; i < y_limit; ++i) {
 		for (j = x_src, j_dst = x_dst; j < x_limit; ++j) {
 			offset_dst = crc_dst->offset
@@ -80,8 +81,23 @@ static void blend(void *vaddr_dst, void *vaddr_src,
 				     + (i * crc_src->pitch)
 				     + (j * crc_src->cpp);
 
-			memcpy(vaddr_dst + offset_dst,
-			       vaddr_src + offset_src, sizeof(u32));
+			/*Currently handles alpha values for fully opaque or fully transparent */
+			alpha = (u8)((*(u32 *)(vaddr_src + offset_src)) >> 24);
+			alpha = alpha/255;
+			r_src = (u8)((*(u32 *)(vaddr_src + offset_src)) >> 16 & 0xff);
+			g_src = (u8)((*(u32 *)(vaddr_src + offset_src)) >> 8  & 0xff);
+			b_src = (u8)((*(u32 *)(vaddr_src + offset_src)) & 0xff);
+			r_dst = (u8)((*(u32 *)(vaddr_dst + offset_dst)) >> 16 & 0xff);
+			g_dst = (u8)((*(u32 *)(vaddr_dst + offset_dst)) >> 8 & 0xff);
+			b_dst = (u8)((*(u32 *)(vaddr_dst + offset_dst)) & 0xff);
+
+			/*Pre-multiplied alpha for blending */
+			r_alpha = (r_src) + (r_dst * (1 -alpha));
+			g_alpha = (g_src) + (g_dst * (1 -alpha));
+			b_alpha = (b_src) + (b_dst * (1 -alpha));
+			memset(vaddr_dst + offset_dst, b_alpha, sizeof(u8));
+			memset(vaddr_dst + offset_dst + 1, g_alpha, sizeof(u8));			
+			memset(vaddr_dst + offset_dst + 2, r_alpha, sizeof(u8));
 		}
 		i_dst++;
 	}
-- 
2.17.1



More information about the dri-devel mailing list