[igt-dev] [PATCH v2] tests/kms_writeback.c: fix the `fill_fb` function

Petri Latvala petri.latvala at intel.com
Fri Oct 8 10:24:52 UTC 2021


On Thu, Oct 07, 2021 at 02:20:11PM -0300, Igor Torrente wrote:
> From: Igor Matheus Andrade Torrente <igormtorrente at gmail.com>
> 
> Currently, the `fill_fb` function, instead of filling the framebuffer
> with the whole pixel, is only filling it with the rightmost byte.
> 
> This is happening because, even though the memset accepts an int as
> a parameter, it's casting the value to unsigned char and will fill
> the memory with this 8 bits value.
> 
> If we setup the pixel to 0xff0000|f0|, the buffer will filled with:
> 
> | addr     | = 0f
> | addr + 1 | = 0f
> | addr + 2 | = 0f
> | addr + 3 | = 0f
>     ...
> | addr + N | = 0f
> 
> This patch address this issue by manually copying the entire integer.
> 
> Signed-off-by: Igor Torrente <igormtorrente at gmail.com>

Reviewed-by: Petri Latvala <petri.latvala at intel.com>


Merging this shortly, thanks for the patch!


> ---
>  tests/kms_writeback.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/kms_writeback.c b/tests/kms_writeback.c
> index 60dbda2a..a033b44f 100644
> --- a/tests/kms_writeback.c
> +++ b/tests/kms_writeback.c
> @@ -227,14 +227,17 @@ static void writeback_fb_id(igt_output_t *output, igt_fb_t *valid_fb, igt_fb_t *
>  
>  static void fill_fb(igt_fb_t *fb, uint32_t pixel)
>  {
> -	void *ptr;
> +	uint32_t *ptr;
> +	int64_t pixel_count, i;
>  
>  	igt_assert(fb->drm_format == DRM_FORMAT_XRGB8888);
>  
>  	ptr = igt_fb_map_buffer(fb->fd, fb);
>  	igt_assert(ptr);
>  
> -	memset(ptr, pixel, fb->strides[0] * fb->height);
> +	pixel_count = fb->strides[0] * fb->height / sizeof(uint32_t);
> +	for (i = 0; i < pixel_count; i++)
> +		ptr[i] = pixel;
>  
>  	igt_fb_unmap_buffer(fb, ptr);
>  }
> -- 
> 2.30.2
> 


More information about the igt-dev mailing list