egl: Fix attrib_list[0] == EGL_NONE check

_eglGetSurfacelessDisplay(), _eglGetWaylandDisplay() and
_eglGetGbmDisplay() handle the attrib_list[0] == EGL_NONE
case incorrectly by returning an EGL_BAD_ATTRIBUTE error.

Fix this bug, and switch the functions to use switch/case
in order to have the same structure as the sibling
_eglGetXXXDisplay() functions which support multiple attributes.

Fixes: c237539d62 ("egl: Implement EGL_EXT_explicit_device")

Signed-off-by: Robert Foss <rfoss@kernel.org>
Reviewed-by: Eric Engestrom <eric@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24394>
This commit is contained in:
Robert Foss 2023-07-31 11:40:23 +02:00 committed by Marge Bot
parent 1440a0f95b
commit 1efaa85889

View file

@ -570,14 +570,23 @@ _eglGetGbmDisplay(struct gbm_device *native_display,
/* This platform recognizes only EXT_explicit_device */
if (attrib_list) {
if (attrib_list[0] != EGL_DEVICE_EXT) {
_eglError(EGL_BAD_ATTRIBUTE, "eglGetPlatformDisplay");
return NULL;
}
dev = _eglLookupDevice((void *)attrib_list[1]);
if (!dev) {
_eglError(EGL_BAD_DEVICE_EXT, "eglGetPlatformDisplay");
return NULL;
for (int i = 0; attrib_list[i] != EGL_NONE; i += 2) {
EGLAttrib attrib = attrib_list[i];
EGLAttrib value = attrib_list[i + 1];
switch (attrib) {
case EGL_DEVICE_EXT:
dev = _eglLookupDevice((void *)value);
if (!dev) {
_eglError(EGL_BAD_DEVICE_EXT, "eglGetPlatformDisplay");
return NULL;
}
break;
default:
_eglError(EGL_BAD_ATTRIBUTE, "eglGetPlatformDisplay");
return NULL;
}
}
}
@ -600,14 +609,23 @@ _eglGetWaylandDisplay(struct wl_display *native_display,
/* This platform recognizes only EXT_explicit_device */
if (attrib_list) {
if (attrib_list[0] != EGL_DEVICE_EXT) {
_eglError(EGL_BAD_ATTRIBUTE, "eglGetPlatformDisplay");
return NULL;
}
dev = _eglLookupDevice((void *)attrib_list[1]);
if (!dev) {
_eglError(EGL_BAD_DEVICE_EXT, "eglGetPlatformDisplay");
return NULL;
for (int i = 0; attrib_list[i] != EGL_NONE; i += 2) {
EGLAttrib attrib = attrib_list[i];
EGLAttrib value = attrib_list[i + 1];
switch (attrib) {
case EGL_DEVICE_EXT:
dev = _eglLookupDevice((void *)value);
if (!dev) {
_eglError(EGL_BAD_DEVICE_EXT, "eglGetPlatformDisplay");
return NULL;
}
break;
default:
_eglError(EGL_BAD_ATTRIBUTE, "eglGetPlatformDisplay");
return NULL;
}
}
}
@ -633,14 +651,23 @@ _eglGetSurfacelessDisplay(void *native_display, const EGLAttrib *attrib_list)
/* This platform recognizes only EXT_explicit_device */
if (attrib_list) {
if (attrib_list[0] != EGL_DEVICE_EXT) {
_eglError(EGL_BAD_ATTRIBUTE, "eglGetPlatformDisplay");
return NULL;
}
if ((native_display && native_display != (void *)attrib_list[1]) ||
(native_display != _eglLookupDevice(native_display))) {
_eglError(EGL_BAD_DEVICE_EXT, "eglGetPlatformDisplay");
return NULL;
for (int i = 0; attrib_list[i] != EGL_NONE; i += 2) {
EGLAttrib attrib = attrib_list[i];
EGLAttrib value = attrib_list[i + 1];
switch (attrib) {
case EGL_DEVICE_EXT:
if ((native_display && native_display != (void *)value) ||
(native_display != _eglLookupDevice(native_display))) {
_eglError(EGL_BAD_DEVICE_EXT, "eglGetPlatformDisplay");
return NULL;
}
break;
default:
_eglError(EGL_BAD_ATTRIBUTE, "eglGetPlatformDisplay");
return NULL;
}
}
}