Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp750330pxa; Wed, 19 Aug 2020 13:56:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysHx0IuuLrlTGtkRhhTYKoq+TB+XmlpVKOi0BWmja6Kk+Bqr1OWxc2ClB8D7PXtmHMTzY3 X-Received: by 2002:aa7:db0f:: with SMTP id t15mr27104163eds.359.1597870590346; Wed, 19 Aug 2020 13:56:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597870590; cv=none; d=google.com; s=arc-20160816; b=tsBZnqYL562XrwOl2pnEbBqNtiQRH2Pov+6/r6r2moCtwRYm6XV+q1OWLqs2GKBQVi LTimwuFIdacnnpWFlvCGlRqhKeYXN+PKpRbwnWRXXofVL+J+jvHUyRbMCyX5Vzdk/F5B 3L30TqzaCKYem2TaGpbHxxxQAtLETqFp6kLLj6Gc8dqzdUriqFm4/5H7t7LzuHZBp2PR BiCI7W1N0GanAEoteKaNgsOEBSK3aJu729RqeZZfemEPezF6rAY1K7DuoMxLMMdvdK/s pCVxel16T5oj5neDnqJSaeUUDZ25XskQuewwirdAbv80EeLOwx7dMdDIhyqpfO6/Z/01 VBTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=leOKJQwVub96yOA0n24Q0PTDFaIFg46bzjrPQUgb4xk=; b=Mo32hCSd+sCxREo3hX8DtaPxP/xlzP62Tr3vGPalHVMZdlxWDvoF1wj/aWcj2njF+Z civvfb7EmjJp1IH3/j6YLuZfHxCjyWeF7PXVNw+H2L+C8Oc8JicFUa38OkWHMRF1gUPe IH2ZhfvJwgzqYjcPtOSOcwQ2jqLfkaeRv7Sy/3rlYSHGERPjG2zRxnIQ9OVOu592FXop 3F1tM24o8VM+Kc0XmzEDjDzmjA2+dRoRLo4Oj9otvB060cbaU4d7aUygGSSGv3Poi0zS u+yTk3B6mIOgFdQWfgoeauQMBJioFzjPSYC/ckMrtsVxoP0L+RlYdC6knh+4domf+YAO t5Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=j7zmd3Me; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l25si70701edv.47.2020.08.19.13.56.05; Wed, 19 Aug 2020 13:56:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=j7zmd3Me; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727078AbgHSUxs (ORCPT + 99 others); Wed, 19 Aug 2020 16:53:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726617AbgHSUxs (ORCPT ); Wed, 19 Aug 2020 16:53:48 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB261C061757 for ; Wed, 19 Aug 2020 13:53:47 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id c80so3373502wme.0 for ; Wed, 19 Aug 2020 13:53:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=leOKJQwVub96yOA0n24Q0PTDFaIFg46bzjrPQUgb4xk=; b=j7zmd3MeXvJDX8vwMtu3DoXYCbpZ7kXuO3iKnMJ6xTP+3XEm3Bv+Ryb05aKqnrunfy 6J23qggYuT3sf/hc/zPLdqVrqP92ujiXMslyH4Lzol7333oXUBPEHx65dkIV4rCAXTrl LccOBgWVyEFpyNgyANVfWMs4aV5qD8FFbtn5Us2XLW/U9FQa+/hjaYij+KAiVQJrpdNl hJG8TFnOifFfM6quOUyT+dOo1Te28Y/A9mP9X/8VdMA95lb8fKgYa7W+nZzYJMnMx9Mv 71qf7YrNHGjUJEvxPcfih46E37P67wLg+uwr5rl1AQ10gWyr5ZOa0CGEG1qj4oSHJESx GtWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=leOKJQwVub96yOA0n24Q0PTDFaIFg46bzjrPQUgb4xk=; b=hKG8pDE0hwCMKoReRh7YkorgD1YYD09ptaHLGuOndWWlj/9IpSe/+XD8aB1M7f8TWQ Nzc9UNuRuJPW3AVXb4NcAzoic93OhPI4x8ASQGmbS3YyMdunEbBDbPc5F4HikZpK3Nph nJznDuwFu+OFKvZuP4vVt+1kElWoCiCSU3/27MyrfZvV7iTNuRQaDtvaXzpsCh04SDC4 o1oJSkZ5yq2zGuXb9S8xW6Bj66aL3FAwQ0EK8dcX8l4LB5c84QE1qKFMkdStQSU7JjEM 6Sk7e/OJtfzaotpCcnbRJEo7fRVcWXGm+4hZDLH72jUjjrOuLGsV34G2GNJm6EvIA5+j 1wJQ== X-Gm-Message-State: AOAM533ayg7ANmHN7lWs4R3R5TgUq0s4EaEJixg+OIbZ2heAIF9z/Xn+ 6AHIJv3cLZewYjJwbkeWL6w= X-Received: by 2002:a1c:2045:: with SMTP id g66mr109387wmg.184.1597870426631; Wed, 19 Aug 2020 13:53:46 -0700 (PDT) Received: from smtp.gmail.com (a95-92-181-29.cpe.netcabo.pt. [95.92.181.29]) by smtp.gmail.com with ESMTPSA id y2sm162239wmg.25.2020.08.19.13.53.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 13:53:46 -0700 (PDT) Date: Wed, 19 Aug 2020 17:53:36 -0300 From: Melissa Wen To: Rodrigo Siqueira , Haneen Mohammed , Daniel Vetter , David Airlie , Rodrigo Siqueira Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel-usp@googlegroups.com, twoerner@gmail.com Subject: [PATCH] drm/vkms: add alpha-premultiplied color blending Message-ID: <20200819205336.fce24lioz34vbcd2@smtp.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The current VKMS blend function ignores alpha channel and just overwrites vaddr_src with vaddr_dst. This XRGB approach triggers a warning when running the kms_cursor_crc/cursor-alpha-transparent test case. In IGT tests, cairo_format_argb32 uses premultiplied alpha (according to documentation), so this patch considers premultiplied alpha colors to compose vaddr_src with vaddr_dst. This change removes the following cursor-alpha-transparent warning: Suspicious CRC: All values are 0. Cc: Daniel Vetter Cc: Rodrigo Siqueira Cc: Haneen Mohammed Signed-off-by: Melissa Wen --- drivers/gpu/drm/vkms/vkms_composer.c | 43 +++++++++++++++++++++------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c index 4f3b07a32b60..6aac962d3e2e 100644 --- a/drivers/gpu/drm/vkms/vkms_composer.c +++ b/drivers/gpu/drm/vkms/vkms_composer.c @@ -32,8 +32,6 @@ static uint32_t compute_crc(void *vaddr_out, struct vkms_composer *composer) src_offset = composer->offset + (i * composer->pitch) + (j * composer->cpp); - /* XRGB format ignores Alpha channel */ - bitmap_clear(vaddr_out + src_offset, 24, 8); crc = crc32_le(crc, vaddr_out + src_offset, sizeof(u32)); } @@ -42,6 +40,32 @@ static uint32_t compute_crc(void *vaddr_out, struct vkms_composer *composer) return crc; } +u8 blend_channel(u8 c_src, u8 c_dst, u8 a_src) +{ + u32 pre_blend; + u8 new_color; + + /* Premultiplied alpha blending - IGT + cairo context */ + pre_blend = (c_src * 255 + c_dst * (255 - a_src)); + + /* Faster div by 255 */ + new_color = ((pre_blend + ((pre_blend + 257) >> 8)) >> 8); + + return new_color; +} + +void alpha_blending(u8 *argb_src, u8 *argb_dst) +{ + u8 a_src; + + a_src = argb_src[3]; + argb_dst[0] = blend_channel(argb_src[0], argb_dst[0], a_src); + argb_dst[1] = blend_channel(argb_src[1], argb_dst[1], a_src); + argb_dst[2] = blend_channel(argb_src[2], argb_dst[2], a_src); + /* Opaque primary */ + argb_dst[3] = 0xFF; +} + /** * blend - blend value at vaddr_src with value at vaddr_dst * @vaddr_dst: destination address @@ -50,12 +74,9 @@ static uint32_t compute_crc(void *vaddr_out, struct vkms_composer *composer) * @src_composer: source framebuffer's metadata * * Blend value at vaddr_src with value at vaddr_dst. - * Currently, this function write value of vaddr_src on value - * at vaddr_dst using buffer's metadata to locate the new values - * from vaddr_src and their destination at vaddr_dst. - * - * TODO: Use the alpha value to blend vaddr_src with vaddr_dst - * instead of overwriting it. + * Currently, this function considers premultiplied alpha for blending, as used + * by Cairo. It uses buffer's metadata to locate the new composite values at + * vaddr_dst. */ static void blend(void *vaddr_dst, void *vaddr_src, struct vkms_composer *dest_composer, @@ -63,6 +84,7 @@ static void blend(void *vaddr_dst, void *vaddr_src, { int i, j, j_dst, i_dst; int offset_src, offset_dst; + u8 *p_dst, *p_src; int x_src = src_composer->src.x1 >> 16; int y_src = src_composer->src.y1 >> 16; @@ -84,8 +106,9 @@ static void blend(void *vaddr_dst, void *vaddr_src, + (i * src_composer->pitch) + (j * src_composer->cpp); - memcpy(vaddr_dst + offset_dst, - vaddr_src + offset_src, sizeof(u32)); + p_src = (u8 *)(vaddr_src + offset_src); + p_dst = (u8 *)(vaddr_dst + offset_dst); + alpha_blending(p_src, p_dst); } i_dst++; } -- 2.28.0