From 0ccad4b24f39c34e3b6504c35cb007d6d4c35274 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 26 Jan 2021 14:09:53 +0100 Subject: [PATCH] clients/simple-dmabuf-egl: don't add INVALID to modifier list While this is harmless because gbm_bo_create_with_modifiers will just fail, it's easy to misunderstand that gbm_bo_create_with_modifiers accepts MOD_INVALID. Let's just keep modifiers_count to zero instead and stop even trying to call that function with invalid input. Stop using modifiers_count to decide whether the compositor supports a format. Instead use a separate format_supported flag. Signed-off-by: Simon Ser References: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7601#note_778845 --- clients/simple-dmabuf-egl.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/clients/simple-dmabuf-egl.c b/clients/simple-dmabuf-egl.c index 1475aaee..71479ddf 100644 --- a/clients/simple-dmabuf-egl.c +++ b/clients/simple-dmabuf-egl.c @@ -78,6 +78,7 @@ struct display { struct weston_direct_display_v1 *direct_display; struct zwp_linux_explicit_synchronization_v1 *explicit_sync; uint32_t format; + bool format_supported; uint64_t *modifiers; int modifiers_count; int req_dmabuf_immediate; @@ -997,13 +998,19 @@ dmabuf_modifiers(void *data, struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf, uint32_t format, uint32_t modifier_hi, uint32_t modifier_lo) { struct display *d = data; + uint64_t modifier = ((uint64_t)modifier_hi << 32) | modifier_lo; - if (format == d->format) { + if (format != d->format) { + return; + } + + d->format_supported = true; + + if (modifier != DRM_FORMAT_MOD_INVALID) { ++d->modifiers_count; d->modifiers = realloc(d->modifiers, d->modifiers_count * sizeof(*d->modifiers)); - d->modifiers[d->modifiers_count - 1] = - ((uint64_t)modifier_hi << 32) | modifier_lo; + d->modifiers[d->modifiers_count - 1] = modifier; } } @@ -1380,7 +1387,7 @@ create_display(char const *drm_render_node, uint32_t format, int opts) wl_display_roundtrip(display->display); - if (!display->modifiers_count) { + if (!display->format_supported) { fprintf(stderr, "format 0x%"PRIX32" is not available\n", display->format); goto error;