diff options
author | Emmanuele Bassi <ebassi@gnome.org> | 2015-12-09 12:45:12 +0000 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2015-12-10 16:38:46 +0000 |
commit | 2c524fbf73cf5348cc1b03cced4a6b1c4c2f0224 (patch) | |
tree | 3cc9cd7be5838c43ef0d220af349b28bbd5087e5 /clutter | |
parent | b47e1616eb1201eae35955aa62aebc352927c67b (diff) | |
download | clutter-2c524fbf73cf5348cc1b03cced4a6b1c4c2f0224.tar.gz |
backend: Allow overriding the Cogl drivers chain
We have an hardcoded list of drivers we have to go through when creating
a Cogl context. Some platforms may expose those drivers, but not be the
preferred ones.
In order to allow users and system integrators to override the list of
drivers, we should crib the same approach used by GDK, and have an
environment variable with a list of drivers to try.
The new environment variable is called `CLUTTER_DRIVER` and accepts a
comma-separated list of driver names, which will be tested in sequence
until one succeeds. There's also an additional '*' token which is used
to ask Clutter to fall back to the internally defined preferred list of
drivers.
https://bugzilla.gnome.org/show_bug.cgi?id=742678
Diffstat (limited to 'clutter')
-rw-r--r-- | clutter/clutter-backend.c | 79 |
1 files changed, 56 insertions, 23 deletions
diff --git a/clutter/clutter-backend.c b/clutter/clutter-backend.c index 312227352..62f33ec0b 100644 --- a/clutter/clutter-backend.c +++ b/clutter/clutter-backend.c @@ -362,39 +362,73 @@ error: return FALSE; } +static const struct { + const char *driver_name; + const char *driver_desc; + CoglDriver driver_id; +} all_known_drivers[] = { + { "gl3", "OpenGL 3.2 core profile", COGL_DRIVER_GL3 }, + { "gl", "OpenGL legacy profile", COGL_DRIVER_GL }, + { "gles2", "OpenGL ES 2.0", COGL_DRIVER_GLES2 }, + { "any", "Default Cogl driver", COGL_DRIVER_ANY }, +}; + +static char *allowed_drivers; + static gboolean clutter_backend_real_create_context (ClutterBackend *backend, GError **error) { - static const struct { - const char *driver_name; - CoglDriver driver_id; - } known_drivers[] = { - { "GL3", COGL_DRIVER_GL3 }, - { "GL (Legacy)", COGL_DRIVER_GL }, - { "GLES 2.0", COGL_DRIVER_GLES2 }, - { "ANY", COGL_DRIVER_ANY }, - }; - GError *internal_error = NULL; + const char *drivers_list; + char **known_drivers; + gboolean allow_any; int i; - for (i = 0; i < G_N_ELEMENTS (known_drivers); i++) - { - CLUTTER_NOTE (BACKEND, "Checking for the %s driver", known_drivers[i].driver_name); + if (allowed_drivers == NULL) + allowed_drivers = "*"; + + allow_any = strstr (allowed_drivers, "*") != NULL; + + drivers_list = g_getenv ("CLUTTER_DRIVER"); + if (drivers_list == NULL) + drivers_list = allowed_drivers; - if (clutter_backend_do_real_create_context (backend, known_drivers[i].driver_id, &internal_error)) - break; + known_drivers = g_strsplit (drivers_list, ",", 0); - if (internal_error) + for (i = 0; backend->cogl_context == NULL && known_drivers[i] != NULL; i++) + { + const char *driver_name = known_drivers[i]; + gboolean is_any = g_str_equal (driver_name, "*"); + int j; + + for (j = 0; j < G_N_ELEMENTS (all_known_drivers); j++) { - CLUTTER_NOTE (BACKEND, "Unable to use the %s driver: %s", - known_drivers[i].driver_name, - internal_error->message); - g_clear_error (&internal_error); + if (!allow_any && !is_any && !strstr (driver_name, all_known_drivers[j].driver_name)) + continue; + + if ((allow_any && is_any) || + (is_any && strstr (allowed_drivers, all_known_drivers[j].driver_name)) || + g_str_equal (all_known_drivers[j].driver_name, driver_name)) + { + CLUTTER_NOTE (BACKEND, "Checking for the %s driver", all_known_drivers[j].driver_desc); + + if (clutter_backend_do_real_create_context (backend, all_known_drivers[j].driver_id, &internal_error)) + break; + + if (internal_error) + { + CLUTTER_NOTE (BACKEND, "Unable to use the %s driver: %s", + all_known_drivers[j].driver_desc, + internal_error->message); + g_clear_error (&internal_error); + } + } } } + g_strfreev (known_drivers); + if (backend->cogl_context == NULL) { if (internal_error != NULL) @@ -402,13 +436,12 @@ clutter_backend_real_create_context (ClutterBackend *backend, else g_set_error_literal (error, CLUTTER_INIT_ERROR, CLUTTER_INIT_ERROR_BACKEND, - _("Unable to initialize the Clutter backend")); + _("Unable to initialize the Clutter backend: no available drivers found.")); return FALSE; } - backend->cogl_source = cogl_glib_source_new (backend->cogl_context, - G_PRIORITY_DEFAULT); + backend->cogl_source = cogl_glib_source_new (backend->cogl_context, G_PRIORITY_DEFAULT); g_source_attach (backend->cogl_source, NULL); return TRUE; |