From 772512c8ff471721d0bd6824a87475c1a2c9708b Mon Sep 17 00:00:00 2001 From: Simon McVittie <smcv@collabora.com> Date: Fri, 11 Dec 2020 16:59:20 +0000 Subject: [PATCH] runtime: Factor out collection of s2tc compatibility shim Signed-off-by: Simon McVittie <smcv@collabora.com> --- pressure-vessel/runtime.c | 69 ++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/pressure-vessel/runtime.c b/pressure-vessel/runtime.c index 1c06eae55..85d33a964 100644 --- a/pressure-vessel/runtime.c +++ b/pressure-vessel/runtime.c @@ -1334,6 +1334,43 @@ pv_runtime_get_capsule_capture_libs (PvRuntime *self, return ret; } +static gboolean +collect_s2tc (PvRuntime *self, + RuntimeArchitecture *arch, + const char *libdir, + GError **error) +{ + g_autofree gchar *s2tc = g_build_filename (libdir, "libtxc_dxtn.so", NULL); + g_autofree gchar *s2tc_in_current_namespace = g_build_filename ( + self->provider_in_current_namespace, + s2tc, + NULL); + + if (g_file_test (s2tc_in_current_namespace, G_FILE_TEST_EXISTS)) + { + g_autoptr(FlatpakBwrap) temp_bwrap = NULL; + g_autofree gchar *expr = NULL; + + g_debug ("Collecting s2tc \"%s\" and its dependencies...", s2tc); + expr = g_strdup_printf ("path-match:%s", s2tc); + + if (!pv_runtime_provide_container_access (self, error)) + return FALSE; + + temp_bwrap = pv_runtime_get_capsule_capture_libs (self, arch); + flatpak_bwrap_add_args (temp_bwrap, + "--dest", arch->libdir_in_current_namespace, + expr, + NULL); + flatpak_bwrap_finish (temp_bwrap); + + if (!pv_bwrap_run_sync (temp_bwrap, NULL, error)) + return FALSE; + } + + return TRUE; +} + static gboolean try_bind_dri (PvRuntime *self, RuntimeArchitecture *arch, @@ -1347,11 +1384,6 @@ try_bind_dri (PvRuntime *self, self->provider_in_current_namespace, dri, NULL); - g_autofree gchar *s2tc = g_build_filename (libdir, "libtxc_dxtn.so", NULL); - g_autofree gchar *s2tc_in_current_namespace = g_build_filename ( - self->provider_in_current_namespace, - s2tc, - NULL); if (g_file_test (dri_in_current_namespace, G_FILE_TEST_IS_DIR)) { @@ -1409,28 +1441,6 @@ try_bind_dri (PvRuntime *self, } } - if (g_file_test (s2tc_in_current_namespace, G_FILE_TEST_EXISTS)) - { - g_autoptr(FlatpakBwrap) temp_bwrap = NULL; - g_autofree gchar *expr = NULL; - - g_debug ("Collecting s2tc \"%s\" and its dependencies...", s2tc); - expr = g_strdup_printf ("path-match:%s", s2tc); - - if (!pv_runtime_provide_container_access (self, error)) - return FALSE; - - temp_bwrap = pv_runtime_get_capsule_capture_libs (self, arch); - flatpak_bwrap_add_args (temp_bwrap, - "--dest", arch->libdir_in_current_namespace, - expr, - NULL); - flatpak_bwrap_finish (temp_bwrap); - - if (!pv_bwrap_run_sync (temp_bwrap, NULL, error)) - return FALSE; - } - return TRUE; } @@ -3528,6 +3538,11 @@ pv_runtime_use_provider_graphics_stack (PvRuntime *self, g_ptr_array_index (dirs, dirs->len - 1 - j), error)) return FALSE; + + if (!collect_s2tc (self, arch, + g_ptr_array_index (dirs, dirs->len - 1 - j), + error)) + return FALSE; } /* Unfortunately VDPAU_DRIVER_PATH can hold just a single path, so we can't -- GitLab