backends/native: Count MetaRenderDeviceEglStream instances externally

`count_mode_setting_devices` was incorrect in both name and in function.
What it was actually doing was counting GPUs that had been registered with
the backend so far (during the `init_gpus` loop). What it was intended to
do was to count the number of `MetaRenderDeviceEglStream` instances, which
is the thing we're limited to only one of. So `count_mode_setting_devices`
would return zero whenever the first GPU initialized happened to be a
`MetaRenderDeviceEglStream`, which would in turn prevent
`MetaRenderDeviceEglStream` from successfully initializing. Seems it only
ever worked in the case of a hybrid system where the first GPU initialized
was GBM-based.

Now we count `MetaRenderDeviceEglStream` instances (zero or one) externally.
This allows initialization to succeed when it happens to be the first (or
only) GPU. And so `MUTTER_DEBUG_FORCE_EGL_STREAM=1` now works.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2905>
This commit is contained in:
Daniel van Vugt 2023-06-22 17:55:07 +08:00
parent 6cb68d39f5
commit 8103ebc21a
2 changed files with 25 additions and 21 deletions

View File

@ -95,6 +95,10 @@ struct _MetaBackendNative
GHashTable *startup_render_devices;
MetaBackendNativeMode mode;
#ifdef HAVE_EGL_DEVICE
MetaRenderDeviceEglStream *render_device_egl_stream;
#endif
};
static GInitableIface *initable_parent_iface;
@ -472,7 +476,6 @@ create_render_device (MetaBackendNative *backend_native,
g_autoptr (MetaRenderDeviceGbm) render_device_gbm = NULL;
g_autoptr (GError) gbm_error = NULL;
#ifdef HAVE_EGL_DEVICE
g_autoptr (MetaRenderDeviceEglStream) render_device_egl_stream = NULL;
g_autoptr (GError) egl_stream_error = NULL;
#endif
@ -544,12 +547,27 @@ create_render_device (MetaBackendNative *backend_native,
#endif
#ifdef HAVE_EGL_DEVICE
render_device_egl_stream =
meta_render_device_egl_stream_new (backend,
if (!backend_native->render_device_egl_stream)
{
MetaRenderDeviceEglStream *device;
device = meta_render_device_egl_stream_new (backend,
device_file,
&egl_stream_error);
if (render_device_egl_stream)
return META_RENDER_DEVICE (g_steal_pointer (&render_device_egl_stream));
if (device)
{
g_object_add_weak_pointer (G_OBJECT (device),
(gpointer *) &backend_native->render_device_egl_stream);
return META_RENDER_DEVICE (device);
}
}
else if (!render_device_gbm)
{
g_set_error (&egl_stream_error,
G_IO_ERROR,
G_IO_ERROR_FAILED,
"it's not GBM-compatible and one EGLDevice was already found");
}
#endif
if (render_device_gbm)

View File

@ -64,12 +64,6 @@ get_egl_device_display (MetaRenderDevice *render_device,
error);
}
static int
count_mode_setting_devices (MetaBackend *backend)
{
return g_list_length (meta_backend_get_gpus (backend));
}
static const char *
get_drm_device_file (MetaEgl *egl,
EGLDeviceEXT device,
@ -175,14 +169,6 @@ meta_render_device_egl_stream_initable_init (GInitable *initable,
EGLDeviceEXT egl_device;
EGLDisplay egl_display;
if (count_mode_setting_devices (backend) != 1)
{
g_set_error (error, G_IO_ERROR,
G_IO_ERROR_FAILED,
"EGLDevice currently only works with single GPU systems");
return FALSE;
}
egl_device = find_egl_device (render_device, error);
if (egl_device == EGL_NO_DEVICE_EXT)
return FALSE;