From ebdf9ad85cf3d3357c51245da2f4e5c59fd33259 Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Tue, 8 Aug 2023 16:25:27 +0100 Subject: [PATCH] egl/wayland: Add helper to check server format support Often when we look up a dri2_wl_visual, the only thing we want to do with it is check whether or not the server supports it. Add a helper for this common pattern. Part-of: --- src/egl/drivers/dri2/platform_wayland.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c index b523cf467db..87b9999fbfe 100644 --- a/src/egl/drivers/dri2/platform_wayland.c +++ b/src/egl/drivers/dri2/platform_wayland.c @@ -308,6 +308,18 @@ dri2_wl_is_format_supported(void *user_data, uint32_t format) return false; } +static bool +server_supports_format(struct dri2_wl_formats *formats, int idx) +{ + return idx >= 0 && BITSET_TEST(formats->formats_bitmap, idx); +} + +static bool +server_supports_fourcc(struct dri2_wl_formats *formats, uint32_t fourcc) +{ + return server_supports_format(formats, dri2_wl_visual_idx_from_fourcc(fourcc)); +} + static int roundtrip(struct dri2_egl_display *dri2_dpy) { @@ -1651,15 +1663,11 @@ dri2_wl_create_wayland_buffer_from_image(_EGLDisplay *disp, _EGLImage *img) struct dri2_egl_image *dri2_img = dri2_egl_image(img); __DRIimage *image = dri2_img->dri_image; struct wl_buffer *buffer; - int fourcc, visual_idx; + int fourcc; /* Check the upstream display supports this buffer's format. */ dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_FOURCC, &fourcc); - visual_idx = dri2_wl_visual_idx_from_fourcc(fourcc); - if (visual_idx == -1) - goto bad_format; - - if (!BITSET_TEST(dri2_dpy->formats.formats_bitmap, visual_idx)) + if (!server_supports_fourcc(&dri2_dpy->formats, fourcc)) goto bad_format; buffer = create_wl_buffer(dri2_dpy, NULL, image);