diff --git a/bin/system-info.c b/bin/system-info.c index 1577047503d78c6417c3ed6e749a93d644daba63..a6199a77c2b93e9ae81479cd356bce721ebaa4a0 100644 --- a/bin/system-info.c +++ b/bin/system-info.c @@ -513,9 +513,18 @@ print_vdpau_details (JsonBuilder *builder, { for (iter = vdpau_list; iter != NULL; iter = iter->next) { + const gchar *library; + gchar *resolved = NULL; json_builder_begin_object (builder); + library = srt_vdpau_driver_get_library_path (iter->data); json_builder_set_member_name (builder, "library_path"); - json_builder_add_string_value (builder, srt_vdpau_driver_get_library_path (iter->data)); + json_builder_add_string_value (builder, library); + resolved = srt_vdpau_driver_resolve_library_path (iter->data); + if (g_strcmp0 (library, resolved) != 0) + { + json_builder_set_member_name (builder, "library_path_resolved"); + json_builder_add_string_value (builder, resolved); + } if (srt_vdpau_driver_get_library_link (iter->data) != NULL) { json_builder_set_member_name (builder, "library_link"); @@ -526,6 +535,7 @@ print_vdpau_details (JsonBuilder *builder, json_builder_set_member_name (builder, "is_extra"); json_builder_add_boolean_value (builder, TRUE); } + g_free (resolved); json_builder_end_object (builder); } } diff --git a/bin/system-info.md b/bin/system-info.md index 1c60ef6b746b0c71a6ec1af6b1f94f4ce0a91bbf..9028725ffdffcdecfb1dad5be89ad2eb812d0c57 100644 --- a/bin/system-info.md +++ b/bin/system-info.md @@ -480,6 +480,10 @@ keys: **library_path** : Path to the driver module that has been found. + **library_path_resolved** + : Absolute path to the driver module that has been found. + This key is present only if **library_path** is relative. + **library_link** : Content of the **library_path** symbolic link. This key is optional and if is not provided, it should be assumed that **library_path** diff --git a/steam-runtime-tools/graphics.c b/steam-runtime-tools/graphics.c index 17e754723a5f651226b95e2b5d47ccc95fd6cfef..f7ae403bd61dc95a6c43956cccd94544287b6b4c 100644 --- a/steam-runtime-tools/graphics.c +++ b/steam-runtime-tools/graphics.c @@ -3448,6 +3448,7 @@ enum VDPAU_DRIVER_PROP_LIBRARY_PATH, VDPAU_DRIVER_PROP_LIBRARY_LINK, VDPAU_DRIVER_PROP_IS_EXTRA, + VDPAU_DRIVER_PROP_RESOLVED_LIBRARY_PATH, N_VDPAU_DRIVER_PROPERTIES }; @@ -3480,6 +3481,10 @@ srt_vdpau_driver_get_property (GObject *object, g_value_set_boolean (value, self->is_extra); break; + case VDPAU_DRIVER_PROP_RESOLVED_LIBRARY_PATH: + g_value_take_string (value, srt_vdpau_driver_resolve_library_path (self)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -3538,7 +3543,9 @@ srt_vdpau_driver_class_init (SrtVdpauDriverClass *cls) vdpau_driver_properties[VDPAU_DRIVER_PROP_LIBRARY_PATH] = g_param_spec_string ("library-path", "Library path", - "Absolute path to the VDPAU driver library", + "Path to the VDPAU driver library. It might be absolute " + "(e.g. /usr/lib/vdpau/libvdpau_radeonsi.so) or relative " + "(e.g. custom/vdpau/libvdpau_radeonsi.so)", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); @@ -3557,6 +3564,14 @@ srt_vdpau_driver_class_init (SrtVdpauDriverClass *cls) G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + vdpau_driver_properties[VDPAU_DRIVER_PROP_RESOLVED_LIBRARY_PATH] = + g_param_spec_string ("resolved-library-path", "Resolved library path", + "Absolute path to the VDPAU driver library. This is similar " + "to 'library-path', but is guaranteed to be an " + "absolute path (e.g. /usr/lib/vdpau/libvdpau_radeonsi.so)", + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_properties (object_class, N_VDPAU_DRIVER_PROPERTIES, vdpau_driver_properties); } @@ -3589,7 +3604,7 @@ srt_vdpau_driver_new (const gchar *library_path, * * Return the library path for this VDPAU driver. * - * Returns: (type filename) (transfer none) (nullable): #SrtVdpauDriver:library-path + * Returns: (type filename) (transfer none): #SrtVdpauDriver:library-path */ const gchar * srt_vdpau_driver_get_library_path (SrtVdpauDriver *self) @@ -3629,6 +3644,36 @@ srt_vdpau_driver_is_extra (SrtVdpauDriver *self) return self->is_extra; } +/** + * srt_vdpau_driver_resolve_library_path: + * @self: The VDPAU driver + * + * Return the absolute library path for this VDPAU driver. + * If srt_vdpau_driver_get_library_path() is already an absolute path, a copy + * of the same value will be returned. + * + * Returns: (type filename) (transfer full): A copy of + * #SrtVdpauDriver:resolved-library-path. Free with g_free(). + */ +gchar * +srt_vdpau_driver_resolve_library_path (SrtVdpauDriver *self) +{ + gchar *base; + gchar *ret; + + g_return_val_if_fail (SRT_IS_VDPAU_DRIVER (self), NULL); + g_return_val_if_fail (self->library_path != NULL, NULL); + + /* We can't use g_canonicalize_filename() because we are targeting an earlier glib version */ + if (self->library_path[0] == '/') + return g_strdup (self->library_path); + + base = g_get_current_dir (); + ret = g_build_filename (base, self->library_path, NULL); + g_free (base); + return ret; +} + /** * SrtVulkanIcd: * diff --git a/steam-runtime-tools/graphics.h b/steam-runtime-tools/graphics.h index d45c128845a59a91b0d0eb87ddc8c18f34b2214e..28be49e6faaf84b9e5cd4568d135ff59c4477233 100644 --- a/steam-runtime-tools/graphics.h +++ b/steam-runtime-tools/graphics.h @@ -197,6 +197,7 @@ GType srt_vdpau_driver_get_type (void); const gchar *srt_vdpau_driver_get_library_path (SrtVdpauDriver *self); const gchar *srt_vdpau_driver_get_library_link (SrtVdpauDriver *self); gboolean srt_vdpau_driver_is_extra (SrtVdpauDriver *self); +gchar *srt_vdpau_driver_resolve_library_path (SrtVdpauDriver *self); typedef struct _SrtVulkanIcd SrtVulkanIcd; typedef struct _SrtVulkanIcdClass SrtVulkanIcdClass; diff --git a/tests/graphics.c b/tests/graphics.c index d00d6c4a07e3b0f4a2857649c4a7880141101bcb..7a06821b45ca3b2dde7312306276a4c62d07772d 100644 --- a/tests/graphics.c +++ b/tests/graphics.c @@ -1807,6 +1807,68 @@ check_list_links (const GList *list, g_assert_cmpstr (suffixes[i], ==, NULL); } +static void +check_paths_are_absolute (const GList *list, + SrtGraphicsModule module) +{ + const gchar *library_path = NULL; + gchar *absolute_path = NULL; + for (const GList *iter = list; iter != NULL; iter = iter->next) + { + switch (module) + { + case SRT_GRAPHICS_VDPAU_MODULE: + library_path = srt_vdpau_driver_get_library_path (iter->data); + absolute_path = srt_vdpau_driver_resolve_library_path (iter->data); + break; + + case SRT_GRAPHICS_DRI_MODULE: + case SRT_GRAPHICS_VAAPI_MODULE: + case SRT_GRAPHICS_GLX_MODULE: + case NUM_SRT_GRAPHICS_MODULES: + default: + g_return_if_reached (); + } + g_assert_cmpstr (library_path, ==, absolute_path); + g_assert_nonnull (library_path); + g_assert_cmpint (library_path[0], ==, '/'); + g_free (absolute_path); + } +} + +static void +check_paths_are_relative (const GList *list, + SrtGraphicsModule module) +{ + const gchar *library_path = NULL; + gchar *absolute_path = NULL; + gsize i = 0; + for (const GList *iter = list; iter != NULL; iter = iter->next, i++) + { + switch (module) + { + case SRT_GRAPHICS_VDPAU_MODULE: + library_path = srt_vdpau_driver_get_library_path (iter->data); + absolute_path = srt_vdpau_driver_resolve_library_path (iter->data); + break; + + case SRT_GRAPHICS_DRI_MODULE: + case SRT_GRAPHICS_VAAPI_MODULE: + case SRT_GRAPHICS_GLX_MODULE: + case NUM_SRT_GRAPHICS_MODULES: + default: + g_return_if_reached (); + } + g_assert_cmpstr (library_path, !=, absolute_path); + g_assert_nonnull (library_path); + g_assert_nonnull (absolute_path); + g_assert_cmpint (library_path[0], !=, '/'); + g_assert_cmpint (absolute_path[0], ==, '/'); + assert_same_file (library_path, absolute_path); + g_free (absolute_path); + } +} + static void test_dri_debian10 (Fixture *f, gconstpointer context) @@ -2132,11 +2194,13 @@ test_vdpau_debian10 (Fixture *f, vdpau = srt_system_info_list_vdpau_drivers (info, multiarch_tuples[0], SRT_DRIVER_FLAGS_NONE); check_list_suffixes (vdpau, vdpau_suffixes_i386, SRT_GRAPHICS_VDPAU_MODULE); check_list_links (vdpau, vdpau_links_i386, SRT_GRAPHICS_VDPAU_MODULE); + check_paths_are_absolute (vdpau, SRT_GRAPHICS_VDPAU_MODULE); g_list_free_full (vdpau, g_object_unref); vdpau = srt_system_info_list_vdpau_drivers (info, multiarch_tuples[1], SRT_DRIVER_FLAGS_NONE); check_list_suffixes (vdpau, vdpau_suffixes_x86_64, SRT_GRAPHICS_VDPAU_MODULE); check_list_links (vdpau, vdpau_links_x86_64, SRT_GRAPHICS_VDPAU_MODULE); + check_paths_are_absolute (vdpau, SRT_GRAPHICS_VDPAU_MODULE); g_list_free_full (vdpau, g_object_unref); g_object_unref (info); @@ -2250,6 +2314,17 @@ test_vdpau_with_env (Fixture *f, check_list_extra (vdpau, G_N_ELEMENTS(vdpau_suffixes)-1, SRT_GRAPHICS_VDPAU_MODULE); g_list_free_full (vdpau, g_object_unref); + /* Test a vdpau relative path */ + g_free (vdpau_path); + vdpau_path = g_build_filename ("sysroots", "no-os-release", "custom_path32", "vdpau", NULL); + envp = g_environ_setenv (envp, "VDPAU_DRIVER_PATH", vdpau_path, TRUE); + srt_system_info_set_environ (info, envp); + vdpau = srt_system_info_list_vdpau_drivers (info, multiarch_tuples[0], SRT_DRIVER_FLAGS_NONE); + check_list_suffixes (vdpau, vdpau_suffixes, SRT_GRAPHICS_VDPAU_MODULE); + check_list_links (vdpau, vdpau_links, SRT_GRAPHICS_VDPAU_MODULE); + check_paths_are_relative (vdpau, SRT_GRAPHICS_VDPAU_MODULE); + g_list_free_full (vdpau, g_object_unref); + g_object_unref (info); g_free (sysroot); g_free (vdpau_path);