wsi: add rgb_component_bits_are_equal

Signed-off-by: Oleksii Bozhenko oleksii.bozhenko@globallogic.com

Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Reviewed-by: Eric Engestrom <eric@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22337>
This commit is contained in:
Oleksii Bozhenko 2023-04-11 15:08:41 +03:00 committed by Marge Bot
parent 7704773619
commit 53106c3a4f

View file

@ -799,6 +799,14 @@ format_get_component_bits(VkFormat format, int comp)
return vk_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, comp);
}
static bool
rgb_component_bits_are_equal(VkFormat format, const xcb_visualtype_t* type)
{
return format_get_component_bits(format, 0) == util_bitcount(type->red_mask) &&
format_get_component_bits(format, 1) == util_bitcount(type->green_mask) &&
format_get_component_bits(format, 2) == util_bitcount(type->blue_mask);
}
static bool
get_sorted_vk_formats(VkIcdSurfaceBase *surface, struct wsi_device *wsi_device,
VkFormat *sorted_formats, unsigned *count)
@ -814,18 +822,14 @@ get_sorted_vk_formats(VkIcdSurfaceBase *surface, struct wsi_device *wsi_device,
/* use the root window's visual to set the default */
*count = 0;
for (unsigned i = 0; i < ARRAY_SIZE(formats); i++) {
if (format_get_component_bits(formats[i], 0) == util_bitcount(rootvis->red_mask) &&
format_get_component_bits(formats[i], 1) == util_bitcount(rootvis->green_mask) &&
format_get_component_bits(formats[i], 2) == util_bitcount(rootvis->blue_mask))
if (rgb_component_bits_are_equal(formats[i], rootvis))
sorted_formats[(*count)++] = formats[i];
}
for (unsigned i = 0; i < ARRAY_SIZE(formats); i++) {
if (formats[i] == sorted_formats[0])
continue;
if (format_get_component_bits(formats[i], 0) == util_bitcount(visual->red_mask) &&
format_get_component_bits(formats[i], 1) == util_bitcount(visual->green_mask) &&
format_get_component_bits(formats[i], 2) == util_bitcount(visual->blue_mask))
if (rgb_component_bits_are_equal(formats[i], visual))
sorted_formats[(*count)++] = formats[i];
}