drm/sysfb: Find screen_info format with helpers

Convert drm_sysfb_get_format_si() to lookup the screen_info color
format as struct pixel_format with screen_info_pixel_format(). Then
search the list of given formats for the screen_info format with
pixel_format_equal().

Replaces custom code with helpers. The pixel-compare helper
pixel_format_equal() also handles indexed color formats. Prepares
for sysfb drivers to support color palettes.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Link: https://lore.kernel.org/r/20250714151513.309475-4-tzimmermann@suse.de
This commit is contained in:
Thomas Zimmermann
2025-07-14 17:13:03 +02:00
parent d6d05e2af7
commit 31eea29d72

View File

@@ -79,22 +79,19 @@ const struct drm_format_info *drm_sysfb_get_format_si(struct drm_device *dev,
const struct screen_info *si)
{
const struct drm_format_info *format = NULL;
u32 bits_per_pixel;
struct pixel_format pixel;
size_t i;
int ret;
bits_per_pixel = __screen_info_lfb_bits_per_pixel(si);
ret = screen_info_pixel_format(si, &pixel);
if (ret)
return NULL;
for (i = 0; i < nformats; ++i) {
const struct pixel_format *f = &formats[i].pixel;
const struct drm_sysfb_format *f = &formats[i];
if (bits_per_pixel == f->bits_per_pixel &&
si->red_size == f->red.length &&
si->red_pos == f->red.offset &&
si->green_size == f->green.length &&
si->green_pos == f->green.offset &&
si->blue_size == f->blue.length &&
si->blue_pos == f->blue.offset) {
format = drm_format_info(formats[i].fourcc);
if (pixel_format_equal(&pixel, &f->pixel)) {
format = drm_format_info(f->fourcc);
break;
}
}