Re: [PATCH 1/3] drm/draw: add drm_draw_can_convert_from_xrgb8888
From: Jani Nikula
Date: Mon Oct 06 2025 - 05:05:06 EST
On Mon, 06 Oct 2025, Jocelyn Falempe <jfalempe@xxxxxxxxxx> wrote:
> On 10/6/25 08:48, Jani Nikula wrote:
>> On Sun, 05 Oct 2025, Francesco Valla <francesco@xxxxxxxx> 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@xxxxxxxx>
>>> ---
>>> 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.
>
> I think the problem is that 0, is also a valid color.
Right, of course.
> Maybe it would be better to split it into 2 functions, and duplicate the
> switch case.
>
> ie:
>
> u32 drm_draw_color_from_xrgb8888(u32 color, u32 format)
> {
> switch(format) {
> case DRM_FORMAT_RGB565:
> return drm_pixel_xrgb8888_to_rgb565(color);
>
> ....
>
>
> bool drm_draw_can_convert_from_xrgb8888(u32 format)
> {
>
> switch(format) {
> case DRM_FORMAT_RGB565:
> return true;
>
> ....
> default:
> return false;
>
>
> I didn't do it this way, because there is a risk to add a format to only
> one of the switch. But after more thinking, that would be simpler overall.
The duplication is a bit annoying, but it might be simpler. Dunno.
BR,
Jani.
>
> Best regards,
--
Jani Nikula, Intel