Mesa (main): egl/wayland: replace EGL_DRI2_MAX_FORMATS by EGL_DRI2_NUM_FORMATS

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Nov 26 20:00:50 UTC 2021


Module: Mesa
Branch: main
Commit: 3022ad7e158cc2c387bea9a90cddca0a8631d7e0
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=3022ad7e158cc2c387bea9a90cddca0a8631d7e0

Author: Leandro Ribeiro <leandro.ribeiro at collabora.com>
Date:   Mon Jun 28 13:57:19 2021 -0300

egl/wayland: replace EGL_DRI2_MAX_FORMATS by EGL_DRI2_NUM_FORMATS

Currently we have a weird design. We have a hardcoded array (named
dri2_wl_visuals) with all the formats that we support, which are 9.

And we also have EGL_DRI2_MAX_FORMATS, which is a constant set to 10. In
patches in which people added new formats to dri2_wl_visuals, this
constant had its value increased. This is confusing, as its name gives
the idea that we can't support more formats.

This constant is only used to define the bitset size of
dri2_egl_display::formats. And it should work just fine if we created
this bitset with the number of formats supported.

To make things clearer, replace EGL_DRI2_MAX_FORMATS by
EGL_DRI2_NUM_FORMATS, which must be equal to ARRAY_SIZE(dri2_wl_visuals)
(i.e. the number of supported formats).

In the next commits we get rid of this constant completely, as it is
prone to errors.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro at collabora.com>
Reviewed-by: Daniel Stone <daniels at collabora.com>
Reviewed-by: Simon Ser <contact at emersion.fr>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11248>

---

 src/egl/drivers/dri2/egl_dri2.h         | 4 ++--
 src/egl/drivers/dri2/platform_wayland.c | 9 +++++----
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 996606c4502..039863b34f3 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -89,7 +89,7 @@ struct zwp_linux_dmabuf_v1;
 #include "util/u_vector.h"
 #include "util/bitset.h"
 
-#define EGL_DRI2_MAX_FORMATS 11
+#define EGL_DRI2_NUM_FORMATS 11
 
 struct wl_buffer;
 
@@ -246,7 +246,7 @@ struct dri2_egl_display
    struct zwp_linux_dmabuf_v1 *wl_dmabuf;
    struct u_vector *wl_modifiers;
    bool authenticated;
-   BITSET_DECLARE(formats, EGL_DRI2_MAX_FORMATS);
+   BITSET_DECLARE(formats, EGL_DRI2_NUM_FORMATS);
    uint32_t capabilities;
    char *device_name;
 #endif
diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c
index e1f445e1de3..817ecb7373a 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -151,9 +151,10 @@ static const struct dri2_wl_visual {
    },
 };
 
-static_assert(ARRAY_SIZE(dri2_wl_visuals) <= EGL_DRI2_MAX_FORMATS,
-              "dri2_egl_display::formats is not large enough for "
-              "the formats in dri2_wl_visuals");
+static_assert(ARRAY_SIZE(dri2_wl_visuals) == EGL_DRI2_NUM_FORMATS,
+              "dri2_egl_display::formats and dri2_wl_visuals must "
+              "have the same size. If you are adding a new format "
+              "to dri2_wl_visuals, increment EGL_DRI2_NUM_FORMATS");
 
 static int
 dri2_wl_visual_idx_from_config(struct dri2_egl_display *dri2_dpy,
@@ -2112,7 +2113,7 @@ dri2_initialize_wayland_swrast(_EGLDisplay *disp)
       goto cleanup;
 
    if (roundtrip(dri2_dpy) < 0 || !BITSET_TEST_RANGE(dri2_dpy->formats,
-                                                     0, EGL_DRI2_MAX_FORMATS))
+                                                     0, EGL_DRI2_NUM_FORMATS))
       goto cleanup;
 
    dri2_dpy->driver_name = strdup("swrast");



More information about the mesa-commit mailing list