* [PATCH 0/3] drm/draw: add check API to avoid spurious WARN
@ 2025-10-05 20:21 Francesco Valla
2025-10-05 20:21 ` [PATCH 1/3] drm/draw: add drm_draw_can_convert_from_xrgb8888 Francesco Valla
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Francesco Valla @ 2025-10-05 20:21 UTC (permalink / raw)
To: Jocelyn Falempe, Javier Martinez Canillas, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter
Cc: dri-devel, linux-kernel, Francesco Valla
When using the DRM draw support, the only way to check if a color can be
converted from XRGB8888 to a target format is currently to attempt an
actual conversion using drm_draw_color_from_xrgb8888(). This function
however will print a WARN the first time a conversion cannot be
performed, leading to two potential issues:
- a WARN is emitted without a real reason if the caller is only
attempting a conversion to check if a format can be supported (which
is the case for two of the current user of this API);
- a failing call following the first one is not emitting a WARN, but a
"valid" color value (0x00000000) is returned nevertheless.
The first issue was observed while using drm_log on a Beagleplay, which
lists AR12 as the first format for its HDMI modesets.
The target of this patch set is to improve this situation; the first
patch introduces a new API devoted only to check if a conversion from
XRGB8888 to the specified format can be performed, while the other two
substitute drm_draw_color_from_xrgb8888() with this new API in the
current users (drm_panic and drm_log) where relevant.
Signed-off-by: Francesco Valla <francesco@valla.it>
---
Francesco Valla (3):
drm/draw: add drm_draw_can_convert_from_xrgb8888
drm/log: avoid WARN when searching for usable format
drm/log: avoid WARN when checking format support
drivers/gpu/drm/clients/drm_log.c | 2 +-
drivers/gpu/drm/drm_draw.c | 84 +++++++++++++++++++++++++++----------
drivers/gpu/drm/drm_draw_internal.h | 2 +
drivers/gpu/drm/drm_panic.c | 2 +-
4 files changed, 65 insertions(+), 25 deletions(-)
---
base-commit: 7a405dbb0f036f8d1713ab9e7df0cd3137987b07
change-id: 20251003-drm_draw_conv_check-9cc3050ebd57
Best regards,
--
Francesco Valla <francesco@valla.it>
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 1/3] drm/draw: add drm_draw_can_convert_from_xrgb8888 2025-10-05 20:21 [PATCH 0/3] drm/draw: add check API to avoid spurious WARN Francesco Valla @ 2025-10-05 20:21 ` Francesco Valla 2025-10-06 6:48 ` Jani Nikula 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 2 siblings, 1 reply; 8+ messages in thread From: Francesco Valla @ 2025-10-05 20:21 UTC (permalink / raw) To: Jocelyn Falempe, Javier Martinez Canillas, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter Cc: dri-devel, linux-kernel, Francesco Valla 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) { 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; 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; } + + 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, -- 2.51.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] drm/draw: add drm_draw_can_convert_from_xrgb8888 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 2025-10-06 8:06 ` Jocelyn Falempe 2025-10-06 21:38 ` Francesco Valla 0 siblings, 2 replies; 8+ messages in thread From: Jani Nikula @ 2025-10-06 6:48 UTC (permalink / raw) To: Francesco Valla, Jocelyn Falempe, Javier Martinez Canillas, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter Cc: dri-devel, linux-kernel, Francesco Valla 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] drm/draw: add drm_draw_can_convert_from_xrgb8888 2025-10-06 6:48 ` Jani Nikula @ 2025-10-06 8:06 ` Jocelyn Falempe 2025-10-06 9:05 ` Jani Nikula 2025-10-06 21:38 ` Francesco Valla 1 sibling, 1 reply; 8+ messages in thread From: Jocelyn Falempe @ 2025-10-06 8:06 UTC (permalink / raw) To: Jani Nikula, Francesco Valla, Javier Martinez Canillas, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter Cc: dri-devel, linux-kernel On 10/6/25 08:48, Jani Nikula wrote: > 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. I think the problem is that 0, is also a valid color. 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. Best regards, -- Jocelyn > >> { >> 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, > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] drm/draw: add drm_draw_can_convert_from_xrgb8888 2025-10-06 8:06 ` Jocelyn Falempe @ 2025-10-06 9:05 ` Jani Nikula 0 siblings, 0 replies; 8+ messages in thread From: Jani Nikula @ 2025-10-06 9:05 UTC (permalink / raw) To: Jocelyn Falempe, Francesco Valla, Javier Martinez Canillas, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter Cc: dri-devel, linux-kernel On Mon, 06 Oct 2025, Jocelyn Falempe <jfalempe@redhat.com> wrote: > On 10/6/25 08:48, Jani Nikula wrote: >> 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. > > 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] drm/draw: add drm_draw_can_convert_from_xrgb8888 2025-10-06 6:48 ` Jani Nikula 2025-10-06 8:06 ` Jocelyn Falempe @ 2025-10-06 21:38 ` Francesco Valla 1 sibling, 0 replies; 8+ messages in thread From: Francesco Valla @ 2025-10-06 21:38 UTC (permalink / raw) To: Jocelyn Falempe, Javier Martinez Canillas, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter, Jani Nikula Cc: dri-devel, linux-kernel On Monday, 6 October 2025 at 08:48:51 Jani Nikula <jani.nikula@linux.intel.com> wrote: > 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. > Is because 0 might be a valid color (e.g black for RGB888), as Jocelyn correctly pointed out in another thread. I'll add this detail to the commit message for the V2. > > { > > 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. > Noted. > > 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. > Whops, you're right. I'll return -ENOTSUPP. > > } > > + > > + 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, > > Thank you. Best regards, -- Francesco ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/3] drm/log: avoid WARN when searching for usable format 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-05 20:21 ` Francesco Valla 2025-10-05 20:21 ` [PATCH 3/3] drm/log: avoid WARN when checking format support Francesco Valla 2 siblings, 0 replies; 8+ messages in thread From: Francesco Valla @ 2025-10-05 20:21 UTC (permalink / raw) To: Jocelyn Falempe, Javier Martinez Canillas, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter Cc: dri-devel, linux-kernel, Francesco Valla Use drm_draw_can_convert_from_xrgb8888() instead of drm_draw_color_from_xrgb8888() while searching for a usable color format. This avoids a WARN in case the first format is not usable. Signed-off-by: Francesco Valla <francesco@valla.it> --- drivers/gpu/drm/clients/drm_log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/clients/drm_log.c b/drivers/gpu/drm/clients/drm_log.c index d239f1e3c456397ad64007b20dde716f5d3d0881..c0150f0c3b4b395e6e2126cf0d9660c967c182ec 100644 --- a/drivers/gpu/drm/clients/drm_log.c +++ b/drivers/gpu/drm/clients/drm_log.c @@ -182,7 +182,7 @@ static u32 drm_log_find_usable_format(struct drm_plane *plane) int i; for (i = 0; i < plane->format_count; i++) - if (drm_draw_color_from_xrgb8888(0xffffff, plane->format_types[i]) != 0) + if (drm_draw_can_convert_from_xrgb8888(plane->format_types[i])) return plane->format_types[i]; return DRM_FORMAT_INVALID; } -- 2.51.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/3] drm/log: avoid WARN when checking format support 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-05 20:21 ` [PATCH 2/3] drm/log: avoid WARN when searching for usable format Francesco Valla @ 2025-10-05 20:21 ` Francesco Valla 2 siblings, 0 replies; 8+ messages in thread From: Francesco Valla @ 2025-10-05 20:21 UTC (permalink / raw) To: Jocelyn Falempe, Javier Martinez Canillas, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter Cc: dri-devel, linux-kernel, Francesco Valla Use drm_draw_can_convert_from_xrgb8888() instead of drm_draw_color_from_xrgb8888() while checking if a color format is usable. This avoids a WARN in case the first format is not usable. Signed-off-by: Francesco Valla <francesco@valla.it> --- drivers/gpu/drm/drm_panic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_panic.c b/drivers/gpu/drm/drm_panic.c index 1d6312fa142935fcf763381920ad889ca4cf4b27..4ba961e445e576d03cfb58953eead90d32b40151 100644 --- a/drivers/gpu/drm/drm_panic.c +++ b/drivers/gpu/drm/drm_panic.c @@ -785,7 +785,7 @@ static bool drm_panic_is_format_supported(const struct drm_format_info *format) { if (format->num_planes != 1) return false; - return drm_draw_color_from_xrgb8888(0xffffff, format->format) != 0; + return drm_draw_can_convert_from_xrgb8888(format->format); } static void draw_panic_dispatch(struct drm_scanout_buffer *sb) -- 2.51.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-10-06 21:39 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 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
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.