diff options
author | Eric Engestrom <[email protected]> | 2018-11-27 12:27:45 +0000 |
---|---|---|
committer | Eric Engestrom <[email protected]> | 2019-07-01 18:35:54 +0100 |
commit | fbf7c38da35afe7f1de05c3896695a7a302ff925 (patch) | |
tree | 5ccff0925393c1171697dd41abcab1ae8b11f827 /src/egl | |
parent | d5f63990b4bdf0458b48da34dddb7656b8393ec7 (diff) |
egl/wayland: use bitset.h for `formats` bit set
Currently only 7 formats are supported, but we don't want the 16 limit
(it's an `unsigned`) to hit us by surprise :]
Let's use bitset.h's BITSET magic to allow us to have any number of
formats, with a static assert to make sure we don't forget to update it.
Signed-off-by: Eric Engestrom <[email protected]>
Reviewed-by: Lionel Landwerlin <[email protected]>
Diffstat (limited to 'src/egl')
-rw-r--r-- | src/egl/drivers/dri2/egl_dri2.h | 5 | ||||
-rw-r--r-- | src/egl/drivers/dri2/platform_wayland.c | 25 |
2 files changed, 19 insertions, 11 deletions
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h index 943ff180861..fa04e3bb616 100644 --- a/src/egl/drivers/dri2/egl_dri2.h +++ b/src/egl/drivers/dri2/egl_dri2.h @@ -81,6 +81,9 @@ struct zwp_linux_dmabuf_v1; #include "eglsync.h" #include "util/u_vector.h" +#include "util/bitset.h" + +#define EGL_DRI2_MAX_FORMATS 8 struct wl_buffer; @@ -232,7 +235,7 @@ struct dri2_egl_display struct zwp_linux_dmabuf_v1 *wl_dmabuf; struct u_vector *wl_modifiers; bool authenticated; - unsigned formats; + BITSET_DECLARE(formats, EGL_DRI2_MAX_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 d7e7eaa2c95..2a2d6fe357d 100644 --- a/src/egl/drivers/dri2/platform_wayland.c +++ b/src/egl/drivers/dri2/platform_wayland.c @@ -114,6 +114,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 int dri2_wl_visual_idx_from_config(struct dri2_egl_display *dri2_dpy, const __DRIconfig *config) @@ -487,7 +491,7 @@ get_back_bo(struct dri2_egl_surface *dri2_surf) num_modifiers = u_vector_length(&dri2_dpy->wl_modifiers[visual_idx]); /* Substitute dri image format if server does not support original format */ - if (!(dri2_dpy->formats & (1 << visual_idx))) + if (!BITSET_TEST(dri2_dpy->formats, visual_idx)) linear_dri_image_format = dri2_wl_visuals[visual_idx].alt_dri_image_format; /* These asserts hold, as long as dri2_wl_visuals[] is self-consistent and @@ -495,8 +499,8 @@ get_back_bo(struct dri2_egl_surface *dri2_surf) * of bugs. */ assert(linear_dri_image_format != __DRI_IMAGE_FORMAT_NONE); - assert(dri2_dpy->formats & - (1 << dri2_wl_visual_idx_from_dri_image_format(linear_dri_image_format))); + assert(BITSET_TEST(dri2_dpy->formats, + dri2_wl_visual_idx_from_dri_image_format(linear_dri_image_format))); /* There might be a buffer release already queued that wasn't processed */ wl_display_dispatch_queue_pending(dri2_dpy->wl_dpy, dri2_surf->wl_queue); @@ -1106,7 +1110,7 @@ dri2_wl_create_wayland_buffer_from_image(_EGLDriver *drv, if (visual_idx == -1) goto bad_format; - if (!(dri2_dpy->formats & (1u << visual_idx))) + if (!BITSET_TEST(dri2_dpy->formats, visual_idx)) goto bad_format; buffer = create_wl_buffer(dri2_dpy, NULL, image); @@ -1196,7 +1200,7 @@ drm_handle_format(void *data, struct wl_drm *drm, uint32_t format) if (visual_idx == -1) return; - dri2_dpy->formats |= (1u << visual_idx); + BITSET_SET(dri2_dpy->formats, visual_idx); } static void @@ -1245,7 +1249,7 @@ dmabuf_handle_modifier(void *data, struct zwp_linux_dmabuf_v1 *dmabuf, modifier_lo == (DRM_FORMAT_MOD_INVALID & 0xffffffff)) return; - dri2_dpy->formats |= (1u << visual_idx); + BITSET_SET(dri2_dpy->formats, visual_idx); mod = u_vector_add(&dri2_dpy->wl_modifiers[visual_idx]); *mod = combine_u32_into_u64(modifier_hi, modifier_lo); @@ -1346,7 +1350,7 @@ dri2_wl_add_configs_for_visuals(_EGLDriver *drv, _EGLDisplay *disp) for (unsigned j = 0; j < ARRAY_SIZE(dri2_wl_visuals); j++) { struct dri2_egl_config *dri2_conf; - if (!(dri2_dpy->formats & (1u << j))) + if (!BITSET_TEST(dri2_dpy->formats, j)) continue; dri2_conf = dri2_add_config(disp, dri2_dpy->driver_configs[i], @@ -1374,7 +1378,7 @@ dri2_wl_add_configs_for_visuals(_EGLDriver *drv, _EGLDisplay *disp) alt_dri_image_format = dri2_wl_visuals[c].alt_dri_image_format; s = dri2_wl_visual_idx_from_dri_image_format(alt_dri_image_format); - if (s == -1 || !(dri2_dpy->formats & (1 << s))) + if (s == -1 || !BITSET_TEST(dri2_dpy->formats, s)) continue; /* Visual s works for the Wayland server, and c can be converted into s @@ -2008,7 +2012,7 @@ shm_handle_format(void *data, struct wl_shm *shm, uint32_t format) if (visual_idx == -1) return; - dri2_dpy->formats |= (1u << visual_idx); + BITSET_SET(dri2_dpy->formats, visual_idx); } static const struct wl_shm_listener shm_listener = { @@ -2115,7 +2119,8 @@ dri2_initialize_wayland_swrast(_EGLDriver *drv, _EGLDisplay *disp) if (roundtrip(dri2_dpy) < 0 || dri2_dpy->wl_shm == NULL) goto cleanup; - if (roundtrip(dri2_dpy) < 0 || dri2_dpy->formats == 0) + if (roundtrip(dri2_dpy) < 0 || !BITSET_TEST_RANGE(dri2_dpy->formats, + 0, EGL_DRI2_MAX_FORMATS)) goto cleanup; dri2_dpy->driver_name = strdup("swrast"); |