Commit 31eea29d authored by Thomas Zimmermann's avatar Thomas Zimmermann
Browse files

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: default avatarThomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: default avatarJavier Martinez Canillas <javierm@redhat.com>
Link: https://lore.kernel.org/r/20250714151513.309475-4-tzimmermann@suse.de
parent d6d05e2a
Loading
Loading
Loading
Loading
+9 −12
Original line number Diff line number Diff line
@@ -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;

		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);
		const struct drm_sysfb_format *f = &formats[i];

		if (pixel_format_equal(&pixel, &f->pixel)) {
			format = drm_format_info(f->fourcc);
			break;
		}
	}