egl: Return success status from meta_egl_query_device_string

QueryDeviceString can successfully return NULL. The convention however
is that when NULL is returned, the error will be set.

This commit makes the returned string an output parameter which allows
us to return the success status and have the error set accordingly.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3614>
This commit is contained in:
Sebastian Wick 2024-02-24 21:56:13 +01:00 committed by Marge Bot
parent 46619573e0
commit 8234f5bc7e
4 changed files with 66 additions and 36 deletions

View File

@ -169,6 +169,25 @@ set_egl_error (GError **error)
error_str); error_str);
} }
static void
check_egl_error (GError **error)
{
EGLint error_number;
const char *error_str;
if (!error)
return;
error_number = eglGetError ();
if (error_number == EGL_SUCCESS)
return;
error_str = get_egl_error_str (error_number);
g_set_error_literal (error, META_EGL_ERROR,
error_number,
error_str);
}
gboolean gboolean
meta_extensions_string_has_extensions_valist (const char *extensions_str, meta_extensions_string_has_extensions_valist (const char *extensions_str,
const char ***missing_extensions, const char ***missing_extensions,
@ -781,25 +800,32 @@ meta_egl_query_devices (MetaEgl *egl,
return TRUE; return TRUE;
} }
const char * gboolean
meta_egl_query_device_string (MetaEgl *egl, meta_egl_query_device_string (MetaEgl *egl,
EGLDeviceEXT device, EGLDeviceEXT device,
EGLint name, EGLint name,
GError **error) const char **out_string,
GError **error)
{ {
g_autoptr (GError) local_error = NULL;
const char *device_string; const char *device_string;
if (!is_egl_proc_valid (egl->eglQueryDeviceStringEXT, error)) if (!is_egl_proc_valid (egl->eglQueryDeviceStringEXT, error))
return NULL; return FALSE;
device_string = egl->eglQueryDeviceStringEXT (device, name); device_string = egl->eglQueryDeviceStringEXT (device, name);
if (!device_string) if (!device_string)
{ {
set_egl_error (error); check_egl_error (&local_error);
return NULL; if (local_error)
{
g_propagate_error (error, local_error);
return FALSE;
}
} }
return device_string; *out_string = device_string;
return TRUE;
} }
gboolean gboolean
@ -812,14 +838,18 @@ meta_egl_egl_device_has_extensions (MetaEgl *egl,
va_list var_args; va_list var_args;
const char *extensions_str; const char *extensions_str;
gboolean has_extensions; gboolean has_extensions;
GError *error = NULL; g_autoptr (GError) error = NULL;
extensions_str = meta_egl_query_device_string (egl, device, EGL_EXTENSIONS, if (!meta_egl_query_device_string (egl, device, EGL_EXTENSIONS,
&error); &extensions_str, &error))
if (!extensions_str)
{ {
g_warning ("Failed to query device string: %s", error->message); g_warning ("Failed to query device string: %s", error->message);
g_error_free (error); return FALSE;
}
if (!extensions_str)
{
g_warning ("EGL_EXTENSIONS device string returned NULL");
return FALSE; return FALSE;
} }

View File

@ -173,10 +173,11 @@ gboolean meta_egl_query_devices (MetaEgl *egl,
EGLint *num_devices, EGLint *num_devices,
GError **error); GError **error);
const char * meta_egl_query_device_string (MetaEgl *egl, gboolean meta_egl_query_device_string (MetaEgl *egl,
EGLDeviceEXT device, EGLDeviceEXT device,
EGLint name, EGLint name,
GError **error); const char **out_string,
GError **error);
gboolean meta_egl_egl_device_has_extensions (MetaEgl *egl, gboolean meta_egl_egl_device_has_extensions (MetaEgl *egl,
EGLDeviceEXT device, EGLDeviceEXT device,

View File

@ -64,10 +64,11 @@ get_egl_device_display (MetaRenderDevice *render_device,
error); error);
} }
static const char * static gboolean
get_drm_device_file (MetaEgl *egl, get_drm_device_file (MetaEgl *egl,
EGLDeviceEXT device, EGLDeviceEXT device,
GError **error) const char **out_device_file_path,
GError **error)
{ {
if (!meta_egl_egl_device_has_extensions (egl, device, if (!meta_egl_egl_device_has_extensions (egl, device,
NULL, NULL,
@ -77,12 +78,11 @@ get_drm_device_file (MetaEgl *egl,
g_set_error (error, G_IO_ERROR, g_set_error (error, G_IO_ERROR,
G_IO_ERROR_FAILED, G_IO_ERROR_FAILED,
"Missing required EGLDevice extension EGL_EXT_device_drm"); "Missing required EGLDevice extension EGL_EXT_device_drm");
return NULL; return FALSE;
} }
return meta_egl_query_device_string (egl, device, return meta_egl_query_device_string (egl, device, EGL_DRM_DEVICE_FILE_EXT,
EGL_DRM_DEVICE_FILE_EXT, out_device_file_path, error);
error);
} }
static EGLDeviceEXT static EGLDeviceEXT
@ -133,8 +133,8 @@ find_egl_device (MetaRenderDevice *render_device,
g_clear_error (error); g_clear_error (error);
egl_device_drm_path = get_drm_device_file (egl, devices[i], error); if (!get_drm_device_file (egl, devices[i], &egl_device_drm_path, error) ||
if (!egl_device_drm_path) !egl_device_drm_path)
continue; continue;
if (g_str_equal (egl_device_drm_path, device_file_path)) if (g_str_equal (egl_device_drm_path, device_file_path))

View File

@ -1821,10 +1821,9 @@ meta_wayland_dma_buf_manager_new (MetaWaylandCompositor *compositor,
"EGL_EXT_device_drm_render_node", "EGL_EXT_device_drm_render_node",
NULL)) NULL))
{ {
device_path = meta_egl_query_device_string (egl, egl_device, if (!meta_egl_query_device_string (egl, egl_device,
EGL_DRM_RENDER_NODE_FILE_EXT, EGL_DRM_RENDER_NODE_FILE_EXT,
&local_error); &device_path, &local_error))
if (local_error)
{ {
g_warning ("Failed to query EGL render node path: %s", g_warning ("Failed to query EGL render node path: %s",
local_error->message); local_error->message);
@ -1837,13 +1836,13 @@ meta_wayland_dma_buf_manager_new (MetaWaylandCompositor *compositor,
"EGL_EXT_device_drm", "EGL_EXT_device_drm",
NULL)) NULL))
{ {
device_path = meta_egl_query_device_string (egl, egl_device, if (!meta_egl_query_device_string (egl, egl_device,
EGL_DRM_DEVICE_FILE_EXT, EGL_DRM_DEVICE_FILE_EXT,
&local_error); &device_path, &local_error))
if (local_error)
{ {
g_warning ("Failed to query EGL render node path: %s", g_warning ("Failed to query EGL render node path: %s",
local_error->message); local_error->message);
g_clear_error (&local_error);
} }
} }