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:
parent
46619573e0
commit
8234f5bc7e
4 changed files with 66 additions and 36 deletions
|
@ -169,6 +169,25 @@ set_egl_error (GError **error)
|
|||
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
|
||||
meta_extensions_string_has_extensions_valist (const char *extensions_str,
|
||||
const char ***missing_extensions,
|
||||
|
@ -781,25 +800,32 @@ meta_egl_query_devices (MetaEgl *egl,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
const char *
|
||||
meta_egl_query_device_string (MetaEgl *egl,
|
||||
EGLDeviceEXT device,
|
||||
EGLint name,
|
||||
GError **error)
|
||||
gboolean
|
||||
meta_egl_query_device_string (MetaEgl *egl,
|
||||
EGLDeviceEXT device,
|
||||
EGLint name,
|
||||
const char **out_string,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr (GError) local_error = NULL;
|
||||
const char *device_string;
|
||||
|
||||
if (!is_egl_proc_valid (egl->eglQueryDeviceStringEXT, error))
|
||||
return NULL;
|
||||
return FALSE;
|
||||
|
||||
device_string = egl->eglQueryDeviceStringEXT (device, name);
|
||||
if (!device_string)
|
||||
{
|
||||
set_egl_error (error);
|
||||
return NULL;
|
||||
check_egl_error (&local_error);
|
||||
if (local_error)
|
||||
{
|
||||
g_propagate_error (error, local_error);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return device_string;
|
||||
*out_string = device_string;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
@ -812,14 +838,18 @@ meta_egl_egl_device_has_extensions (MetaEgl *egl,
|
|||
va_list var_args;
|
||||
const char *extensions_str;
|
||||
gboolean has_extensions;
|
||||
GError *error = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
|
||||
extensions_str = meta_egl_query_device_string (egl, device, EGL_EXTENSIONS,
|
||||
&error);
|
||||
if (!extensions_str)
|
||||
if (!meta_egl_query_device_string (egl, device, EGL_EXTENSIONS,
|
||||
&extensions_str, &error))
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -173,10 +173,11 @@ gboolean meta_egl_query_devices (MetaEgl *egl,
|
|||
EGLint *num_devices,
|
||||
GError **error);
|
||||
|
||||
const char * meta_egl_query_device_string (MetaEgl *egl,
|
||||
EGLDeviceEXT device,
|
||||
EGLint name,
|
||||
GError **error);
|
||||
gboolean meta_egl_query_device_string (MetaEgl *egl,
|
||||
EGLDeviceEXT device,
|
||||
EGLint name,
|
||||
const char **out_string,
|
||||
GError **error);
|
||||
|
||||
gboolean meta_egl_egl_device_has_extensions (MetaEgl *egl,
|
||||
EGLDeviceEXT device,
|
||||
|
|
|
@ -64,10 +64,11 @@ get_egl_device_display (MetaRenderDevice *render_device,
|
|||
error);
|
||||
}
|
||||
|
||||
static const char *
|
||||
get_drm_device_file (MetaEgl *egl,
|
||||
EGLDeviceEXT device,
|
||||
GError **error)
|
||||
static gboolean
|
||||
get_drm_device_file (MetaEgl *egl,
|
||||
EGLDeviceEXT device,
|
||||
const char **out_device_file_path,
|
||||
GError **error)
|
||||
{
|
||||
if (!meta_egl_egl_device_has_extensions (egl, device,
|
||||
NULL,
|
||||
|
@ -77,12 +78,11 @@ get_drm_device_file (MetaEgl *egl,
|
|||
g_set_error (error, G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED,
|
||||
"Missing required EGLDevice extension EGL_EXT_device_drm");
|
||||
return NULL;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return meta_egl_query_device_string (egl, device,
|
||||
EGL_DRM_DEVICE_FILE_EXT,
|
||||
error);
|
||||
return meta_egl_query_device_string (egl, device, EGL_DRM_DEVICE_FILE_EXT,
|
||||
out_device_file_path, error);
|
||||
}
|
||||
|
||||
static EGLDeviceEXT
|
||||
|
@ -133,8 +133,8 @@ find_egl_device (MetaRenderDevice *render_device,
|
|||
|
||||
g_clear_error (error);
|
||||
|
||||
egl_device_drm_path = get_drm_device_file (egl, devices[i], error);
|
||||
if (!egl_device_drm_path)
|
||||
if (!get_drm_device_file (egl, devices[i], &egl_device_drm_path, error) ||
|
||||
!egl_device_drm_path)
|
||||
continue;
|
||||
|
||||
if (g_str_equal (egl_device_drm_path, device_file_path))
|
||||
|
|
|
@ -1821,10 +1821,9 @@ meta_wayland_dma_buf_manager_new (MetaWaylandCompositor *compositor,
|
|||
"EGL_EXT_device_drm_render_node",
|
||||
NULL))
|
||||
{
|
||||
device_path = meta_egl_query_device_string (egl, egl_device,
|
||||
EGL_DRM_RENDER_NODE_FILE_EXT,
|
||||
&local_error);
|
||||
if (local_error)
|
||||
if (!meta_egl_query_device_string (egl, egl_device,
|
||||
EGL_DRM_RENDER_NODE_FILE_EXT,
|
||||
&device_path, &local_error))
|
||||
{
|
||||
g_warning ("Failed to query EGL render node path: %s",
|
||||
local_error->message);
|
||||
|
@ -1837,13 +1836,13 @@ meta_wayland_dma_buf_manager_new (MetaWaylandCompositor *compositor,
|
|||
"EGL_EXT_device_drm",
|
||||
NULL))
|
||||
{
|
||||
device_path = meta_egl_query_device_string (egl, egl_device,
|
||||
EGL_DRM_DEVICE_FILE_EXT,
|
||||
&local_error);
|
||||
if (local_error)
|
||||
if (!meta_egl_query_device_string (egl, egl_device,
|
||||
EGL_DRM_DEVICE_FILE_EXT,
|
||||
&device_path, &local_error))
|
||||
{
|
||||
g_warning ("Failed to query EGL render node path: %s",
|
||||
local_error->message);
|
||||
g_clear_error (&local_error);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue