drm/vkms: Use alpha value for blending
cover drm/vkms: Use alpha value for blending
The first patch of this series reworks part of the blend function to improve the readability and also for preparing it for using alpha value. The second patch updates the blend function for applying alpha value for a fully transparent blend. After applying this patchset, pipe-a-cursor-alpha-transparent in kms_cursor_crc start to pass.
This patchset depends on:
https://patchwork.freedesktop.org/series/61738/
Rodrigo Siqueira (2):
drm/vkms: Rework blend function
drm/vkms: Use alpha channel for blending cursor with primary
drivers/gpu/drm/vkms/vkms_composer.c | 54 ++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 15 deletions(-)
Signature · 1 line
2.21.0
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 1/2 drm/vkms: Rework blend function
For combining the cursor into the primary plane, vkms invokes a function named blend which iterates in both buffers and ends up by copying the cursor into the primary buffer. This patch, rework part of the blend function to prepare it for using the alpha channel for blending.
--- drivers/gpu/drm/vkms/vkms_composer.c | 39 +++++++++++++++++----------- 1 file changed, 24 insertions(+), 15 deletions(-)
drivers/gpu/drm/vkms/vkms_composer.c +24 -15
@@ -15,6 +15,17 @@ static u32 get_pixel_from_buffer(int x, int y, const u8 *buffer,return *(u32 *)&buffer[src_offset]; } +static void set_pixel (int x,int y,u8 *buffer, +const struct vkms_composer *composer,const u32 value) +{ +int offset = composer->offset + (y * composer->pitch) + + (x * composer->cpp); +u32 *dst; + + dst = (u32 *)&buffer[offset]; + *dst = value; +} +/** * compute_crc - Compute CRC value on output frame *
@@ -50,7 +61,7 @@ static uint32_t compute_crc(const u8 *vaddr,* blend - belnd value at vaddr_src with value at vaddr_dst * @vaddr_dst: destination address * @vaddr_src: source address -* @dest_composer: destination framebuffer's metadata +* @dst_composer: destination framebuffer's metadata * @src_composer: source framebuffer's metadata * * Blend value at vaddr_src with value at vaddr_dst.
@@ -62,11 +73,10 @@ static uint32_t compute_crc(const u8 *vaddr,* instead of overwriting it. */ static void blend (void *vaddr_dst,void *vaddr_src, -struct vkms_composer *dest_composer, +struct vkms_composer *dst_composer,struct vkms_composer *src_composer) { -int i, j, j_dst, i_dst; -int offset_src, offset_dst; +int y, x, j_dst, i_dst;int x_src = src_composer->src.x1 >>16 ;int y_src = src_composer->src.y1 >>16 ;
@@ -79,17 +89,16 @@ static void blend(void *vaddr_dst, void *vaddr_src,int y_limit = y_src + h_dst;int x_limit = x_src + w_dst; -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 = dest_composer->offset - + (i_dst * dest_composer->pitch) - + (j_dst++ * dest_composer->cpp); - offset_src = src_composer->offset - + (i * src_composer->pitch) - + (j * src_composer->cpp); - -memcpy (vaddr_dst + offset_dst, - vaddr_src + offset_src,sizeof (u32)); +u32 pixel_src; + +for (y = y_src, i_dst = y_dst; y < y_limit; ++y) { +for (x = x_src, j_dst = x_dst; x < x_limit; ++x) { + pixel_src =get_pixel_from_buffer (x, y, + vaddr_src, + src_composer); +set_pixel (j_dst, i_dst, vaddr_dst, dest_composer, + pixel_src); + j_dst++; } i_dst++; }
Signature · 1 line
2.21.0
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/2 drm/vkms: Use alpha channel for blending cursor with primary
In reply to Rodrigo SiqueiraCurrently, the blend function overwriting the cursor value into the primary plane. This patch utilizes the alpha value for a fully transparent blend of the cursor (vaddr_src) with primary (vaddr_dst) instead of overwriting it in blend().
--- drivers/gpu/drm/vkms/vkms_composer.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/gpu/drm/vkms/vkms_composer.c +18 -3
@@ -26,6 +26,17 @@ static void set_pixel(int x, int y, u8 *buffer, *dst = value; } +static u32 apply_alpha (u32 src,u32 dst) +{ +u8 alpha; +u32 k; + + alpha = src >>24 ; + alpha = (alpha +1 ) >>8 ; + k = (alpha <<24 ) - alpha; +return (k & src) | (~k & dst); +} +/** * compute_crc - Compute CRC value on output frame *
@@ -89,15 +100,19 @@ static void blend(void *vaddr_dst, void *vaddr_src,int y_limit = y_src + h_dst;int x_limit = x_src + w_dst; -u32 pixel_src; +u32 pixel_src, pixel_dst, new_pixel;for (y = y_src, i_dst = y_dst; y < y_limit; ++y) {for (x = x_src, j_dst = x_dst; x < x_limit; ++x) { pixel_src =get_pixel_from_buffer (x, y, vaddr_src, src_composer); -set_pixel (j_dst, i_dst, vaddr_dst, dest_composer, - pixel_src); + pixel_dst =get_pixel_from_buffer (j_dst, i_dst, + vaddr_dst, + dst_composer); + new_pixel =apply_alpha (pixel_src, pixel_dst); +set_pixel (j_dst, i_dst, vaddr_dst, dst_composer, + new_pixel); j_dst++; } i_dst++;
Signature · 1 line
2.21.0
Quoted 5 lines · Rodrigo Siqueira
The first patch of this series reworks part of the blend function to improve the readability and also for preparing it for using alpha value. The second patch updates the blend function for applying alpha value for a fully transparent blend. After applying this patchset, pipe-a-cursor-alpha-transparent in
kms_cursor_crcstart to pass.
Looking at the series I wonder whether we should go right ahead to reworking the entire composer pipeline to future proof it for multiple planes and other pixel modes. Or whether enabling alpha blending with what we have now is a better idea, but that means more complicated refactoring later on ...
Quoted 2 lines
This patchset depends on:
https://patchwork.freedesktop.org/series/61738/
Ok I guess I need to look at this one here first.
-Daniel
Quoted 10 lines
Rodrigo Siqueira (2):
drm/vkms: Rework blend function
drm/vkms: Use alpha channel for blending cursor with primarydrivers/gpu/drm/vkms/vkms_composer.c | 54 ++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 15 deletions(-)Signature · 1 line
2.21.0
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel