public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@linux.intel.com>
To: Francesco Valla <francesco@valla.it>,
	Jocelyn Falempe <jfalempe@redhat.com>,
	Javier Martinez Canillas <javierm@redhat.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	Francesco Valla <francesco@valla.it>
Subject: Re: [PATCH 1/3] drm/draw: add drm_draw_can_convert_from_xrgb8888
Date: Mon, 06 Oct 2025 09:48:51 +0300	[thread overview]
Message-ID: <a669b2ee89865e9150efd38e181cdc838c2ac522@intel.com> (raw)
In-Reply-To: <20251005-drm_draw_conv_check-v1-1-9c814d9362f6@valla.it>

On Sun, 05 Oct 2025, Francesco Valla <francesco@valla.it> wrote:
> Add drm_draw_can_convert_from_xrgb8888() function that can be used to
> determine if a XRGB8888 color can be converted to the specified format.
>
> Signed-off-by: Francesco Valla <francesco@valla.it>
> ---
>  drivers/gpu/drm/drm_draw.c          | 84 +++++++++++++++++++++++++++----------
>  drivers/gpu/drm/drm_draw_internal.h |  2 +
>  2 files changed, 63 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_draw.c b/drivers/gpu/drm/drm_draw.c
> index 9dc0408fbbeadbe8282a2d6b210e0bfb0672967f..2641026a103d3b28cab9f5d378604b0604520fe4 100644
> --- a/drivers/gpu/drm/drm_draw.c
> +++ b/drivers/gpu/drm/drm_draw.c
> @@ -15,45 +15,83 @@
>  #include "drm_draw_internal.h"
>  #include "drm_format_internal.h"
>  
> -/**
> - * drm_draw_color_from_xrgb8888 - convert one pixel from xrgb8888 to the desired format
> - * @color: input color, in xrgb8888 format
> - * @format: output format
> - *
> - * Returns:
> - * Color in the format specified, casted to u32.
> - * Or 0 if the format is not supported.
> - */
> -u32 drm_draw_color_from_xrgb8888(u32 color, u32 format)
> +static int __drm_draw_color_from_xrgb8888(u32 color, u32 format, u32 *out_color)

Is there any reason to change the return value of this function and
return the result via out_color? It already returns 0 if the format is
not supported. If there's a reason, it needs to be in the commit
message.

>  {
>  	switch (format) {
>  	case DRM_FORMAT_RGB565:
> -		return drm_pixel_xrgb8888_to_rgb565(color);
> +		*out_color = drm_pixel_xrgb8888_to_rgb565(color);
> +		break;
>  	case DRM_FORMAT_RGBA5551:
> -		return drm_pixel_xrgb8888_to_rgba5551(color);
> +		*out_color = drm_pixel_xrgb8888_to_rgba5551(color);
> +		break;
>  	case DRM_FORMAT_XRGB1555:
> -		return drm_pixel_xrgb8888_to_xrgb1555(color);
> +		*out_color = drm_pixel_xrgb8888_to_xrgb1555(color);
> +		break;
>  	case DRM_FORMAT_ARGB1555:
> -		return drm_pixel_xrgb8888_to_argb1555(color);
> +		*out_color = drm_pixel_xrgb8888_to_argb1555(color);
> +		break;
>  	case DRM_FORMAT_RGB888:
> +		fallthrough;

That's not necessary for back to back case labels. Please don't add it.

>  	case DRM_FORMAT_XRGB8888:
> -		return color;
> +		*out_color = color;
> +		break;
>  	case DRM_FORMAT_ARGB8888:
> -		return drm_pixel_xrgb8888_to_argb8888(color);
> +		*out_color = drm_pixel_xrgb8888_to_argb8888(color);
> +		break;
>  	case DRM_FORMAT_XBGR8888:
> -		return drm_pixel_xrgb8888_to_xbgr8888(color);
> +		*out_color = drm_pixel_xrgb8888_to_xbgr8888(color);
> +		break;
>  	case DRM_FORMAT_ABGR8888:
> -		return drm_pixel_xrgb8888_to_abgr8888(color);
> +		*out_color = drm_pixel_xrgb8888_to_abgr8888(color);
> +		break;
>  	case DRM_FORMAT_XRGB2101010:
> -		return drm_pixel_xrgb8888_to_xrgb2101010(color);
> +		*out_color = drm_pixel_xrgb8888_to_xrgb2101010(color);
> +		break;
>  	case DRM_FORMAT_ARGB2101010:
> -		return drm_pixel_xrgb8888_to_argb2101010(color);
> +		*out_color = drm_pixel_xrgb8888_to_argb2101010(color);
> +		break;
>  	case DRM_FORMAT_ABGR2101010:
> -		return drm_pixel_xrgb8888_to_abgr2101010(color);
> +		*out_color = drm_pixel_xrgb8888_to_abgr2101010(color);
> +		break;
>  	default:
> -		WARN_ONCE(1, "Can't convert to %p4cc\n", &format);
> -		return 0;
> +		return -1;

Please don't use -1 as a generic error code. -1 is -EPERM.

>  	}
> +
> +	return 0;
> +}
> +
> +/**
> + * drm_draw_can_convert_from_xrgb8888 - check if xrgb8888 can be converted to the desired format
> + * @format: format
> + *
> + * Returns:
> + * True if XRGB8888 can be converted to the specified format, false otherwise.
> + */
> +bool drm_draw_can_convert_from_xrgb8888(u32 format)
> +{
> +	u32 out_color;
> +
> +	return __drm_draw_color_from_xrgb8888(0, format, &out_color) == 0;
> +}
> +EXPORT_SYMBOL(drm_draw_can_convert_from_xrgb8888);
> +
> +/**
> + * drm_draw_color_from_xrgb8888 - convert one pixel from xrgb8888 to the desired format
> + * @color: input color, in xrgb8888 format
> + * @format: output format
> + *
> + * Returns:
> + * Color in the format specified, casted to u32.
> + * Or 0 if the format is not supported.
> + */
> +u32 drm_draw_color_from_xrgb8888(u32 color, u32 format)
> +{
> +	u32 out_color = 0;
> +
> +	if (__drm_draw_color_from_xrgb8888(color, format, &out_color))
> +		WARN_ONCE(1, "Can't convert to %p4cc\n", &format);
> +
> +	return out_color;
>  }
>  EXPORT_SYMBOL(drm_draw_color_from_xrgb8888);
>  
> diff --git a/drivers/gpu/drm/drm_draw_internal.h b/drivers/gpu/drm/drm_draw_internal.h
> index f121ee7339dc11537f677c833f0ee94fe0e799cd..2ab4cb341df94fc4173dd6f5e7a512bdcfa5e55c 100644
> --- a/drivers/gpu/drm/drm_draw_internal.h
> +++ b/drivers/gpu/drm/drm_draw_internal.h
> @@ -24,6 +24,8 @@ static inline const u8 *drm_draw_get_char_bitmap(const struct font_desc *font,
>  	return font->data + (c * font->height) * font_pitch;
>  }
>  
> +bool drm_draw_can_convert_from_xrgb8888(u32 format);
> +
>  u32 drm_draw_color_from_xrgb8888(u32 color, u32 format);
>  
>  void drm_draw_blit16(struct iosys_map *dmap, unsigned int dpitch,

-- 
Jani Nikula, Intel

  reply	other threads:[~2025-10-06  6:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-05 20:21 [PATCH 0/3] drm/draw: add check API to avoid spurious WARN Francesco Valla
2025-10-05 20:21 ` [PATCH 1/3] drm/draw: add drm_draw_can_convert_from_xrgb8888 Francesco Valla
2025-10-06  6:48   ` Jani Nikula [this message]
2025-10-06  8:06     ` Jocelyn Falempe
2025-10-06  9:05       ` Jani Nikula
2025-10-06 21:38     ` Francesco Valla
2025-10-05 20:21 ` [PATCH 2/3] drm/log: avoid WARN when searching for usable format Francesco Valla
2025-10-05 20:21 ` [PATCH 3/3] drm/log: avoid WARN when checking format support Francesco Valla

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a669b2ee89865e9150efd38e181cdc838c2ac522@intel.com \
    --to=jani.nikula@linux.intel.com \
    --cc=airlied@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=francesco@valla.it \
    --cc=javierm@redhat.com \
    --cc=jfalempe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox