diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index d2fb4b61..cbc1e2af 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -33,7 +33,7 @@ jobs: - name: Install dependencies run: > - sudo apt-get update && sudo apt-get install libvulkan-dev libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libavahi-client-dev libavahi-glib-dev libeigen3-dev glslang-tools libudev-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev libpulse-dev xz-utils libpipewire-0.3-dev libcli11-dev libboost-all-dev librsvg2-bin libssl-dev libnotify-dev + sudo apt-get update && sudo apt-get install libvulkan-dev libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libavahi-client-dev libavahi-glib-dev libeigen3-dev glslang-tools libudev-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev libpulse-dev xz-utils libpipewire-0.3-dev libcli11-dev libboost-all-dev librsvg2-bin libssl-dev libnotify-dev librsvg2-dev - name: Prepare Vulkan SDK uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 with: @@ -87,7 +87,7 @@ jobs: - name: Install dependencies run: > - apt-get update && apt-get install --yes libvulkan-dev libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev qt6-base-dev qt6-tools-dev libcap-dev pkexec libboost-all-dev librsvg2-bin libssl-dev libnotify-dev qt6-declarative-dev extra-cmake-modules libkirigami-dev libkf6i18n-dev libkf6coreaddons-dev libkf6qqc2desktopstyle-dev libkf6iconthemes-dev jq sudo cmake gcc g++ git qcoro-qt6-dev + apt-get update && apt-get install --yes libvulkan-dev libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev qt6-base-dev qt6-tools-dev libcap-dev pkexec libboost-all-dev librsvg2-bin libssl-dev libnotify-dev qt6-declarative-dev extra-cmake-modules libkirigami-dev libkf6i18n-dev libkf6coreaddons-dev libkf6qqc2desktopstyle-dev libkf6iconthemes-dev jq sudo cmake gcc g++ git qcoro-qt6-dev librsvg2-dev # runtime: qml6-module-qtqml-workerscript qml6-module-qtquick-dialogs - name: Prepare Vulkan SDK uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944 @@ -192,7 +192,7 @@ jobs: - name: install server dependencies run: > - sudo apt-get update && sudo apt-get install libavahi-glib-dev nlohmann-json3-dev libpulse-dev xz-utils libpipewire-0.3-dev libcli11-dev qt6-base-dev qt6-tools-dev libcap-dev pkexec libnotify-dev + sudo apt-get update && sudo apt-get install libavahi-glib-dev nlohmann-json3-dev libpulse-dev xz-utils libpipewire-0.3-dev libcli11-dev qt6-base-dev qt6-tools-dev libcap-dev pkexec libnotify-dev librsvg2-dev - name: Configure CMake run: > @@ -467,7 +467,7 @@ jobs: - name: Install dependencies run: | apt update - apt install --yes libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libavahi-client-dev libavahi-glib-dev libeigen3-dev glslang-tools libudev-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev libpulse-dev xz-utils libpipewire-0.3-dev libcli11-dev qt6-base-dev qt6-tools-dev libcap-dev pkexec libboost-all-dev librsvg2-bin dpkg-dev pkg-config debhelper-compat build-essential lintian cmake libnotify-dev qt6-declarative-dev extra-cmake-modules libkirigami-dev libkf6i18n-dev libkf6coreaddons-dev libkf6qqc2desktopstyle-dev libkf6iconthemes-dev jq sudo cmake gcc g++ git wget libssl-dev qcoro-qt6-dev + apt install --yes libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libavahi-client-dev libavahi-glib-dev libeigen3-dev glslang-tools libudev-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev libpulse-dev xz-utils libpipewire-0.3-dev libcli11-dev qt6-base-dev qt6-tools-dev libcap-dev pkexec libboost-all-dev librsvg2-bin dpkg-dev pkg-config debhelper-compat build-essential lintian cmake libnotify-dev qt6-declarative-dev extra-cmake-modules libkirigami-dev libkf6i18n-dev libkf6coreaddons-dev libkf6qqc2desktopstyle-dev libkf6iconthemes-dev jq sudo cmake gcc g++ git wget libssl-dev qcoro-qt6-dev librsvg2-dev - uses: actions/checkout@v4 with: @@ -489,6 +489,13 @@ jobs: patch -p1 --fuzz=0 --forward < "$p" done + - name: Download stb + run: | + wget https://github.com/nothings/stb/archive/013ac3beddff3dbffafd5177e7972067cd2b5083.tar.gz -O stb.tar.gz + + mkdir wivrn/stb-src + tar xzf stb.tar.gz --strip-components=1 -C wivrn/stb-src + - name: Edit changelog working-directory: wivrn run: > diff --git a/CMakeLists.txt b/CMakeLists.txt index cad020f5..fa271ff3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -183,6 +183,11 @@ if (WIVRN_BUILD_SERVER) pkg_check_modules(libnotify REQUIRED IMPORTED_TARGET libnotify) endif() +if (WIVRN_BUILD_DASHBOARD OR WIVRN_BUILD_SERVER) + pkg_check_modules(librsvg-2.0 REQUIRED IMPORTED_TARGET librsvg-2.0) + find_package(PNG) +endif() + if (WIVRN_BUILD_DASHBOARD) find_package(Qt6 REQUIRED COMPONENTS Core Quick Test Gui QuickControls2 Widgets Network) diff --git a/README.md b/README.md index e4ed644e..71490763 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,7 @@ WiVRn uses the following software: - [FreeType](https://freetype.org/) - [glm](http://glm.g-truc.net/) - [HarfBuzz](https://harfbuzz.github.io/) +- [librsvg](https://wiki.gnome.org/Projects/LibRsvg) - [Monado](https://monado.freedesktop.org/) - [nvenc](https://developer.nvidia.com/nvidia-video-codec-sdk) optional, for hardware encoding on Nvidia - [qCoro](https://qcoro.dev/) diff --git a/assets/default_icon.png b/assets/default_icon.png new file mode 100644 index 00000000..414191f3 Binary files /dev/null and b/assets/default_icon.png differ diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 01059ded..7c903461 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -240,6 +240,10 @@ if(ANDROID) COMMAND ${TOKTX} --encode astc --astc_blk_d 4x4 --astc_quality 100 --genmipmap ${ASSETS_DIR}/wivrn.ktx2 ${ASSETS_DIR}/wivrn.png DEPENDS ${ASSETS_DIR}/wivrn.png) + add_custom_command(OUTPUT ${ASSETS_DIR}/default_icon.ktx2 + COMMAND ${TOKTX} --encode astc --astc_blk_d 4x4 --astc_quality 100 --genmipmap ${ASSETS_DIR}/wivrn-pride.ktx2 ${ASSETS_DIR}/default_icon.png + DEPENDS ${ASSETS_DIR}/default_icon.png) + add_custom_command(OUTPUT ${ASSETS_DIR}/WoodFloor051_1K-JPG_Color.ktx2 COMMAND ${TOKTX} --encode astc --astc_blk_d 12x12 --astc_quality 100 --genmipmap ${ASSETS_DIR}/WoodFloor051_1K-JPG_Color.ktx2 ${AST_SRC_DIR}/WoodFloor051_1K-JPG_Color.jpg DEPENDS ${AST_SRC_DIR}/WoodFloor051_1K-JPG_Color.jpg) diff --git a/client/constants.h b/client/constants.h index 69d817d8..994404c5 100644 --- a/client/constants.h +++ b/client/constants.h @@ -28,9 +28,6 @@ namespace constants::gui // Minimum distance between a GUI layer and a fingertip/controller to register a click constexpr float min_pointer_distance = -0.1; -// Number of combined image samplers in ImGui descriptor pool -constexpr unsigned int nb_combined_image_samplers = 100; - // Font to use (desktop only) constexpr const char font_name[] = "Noto Sans"; @@ -39,7 +36,7 @@ constexpr int font_size_small = 30; constexpr int font_size_large = 75; // Ratio between joystick position and scroll distance/s -constexpr float scroll_ratio = 3; +constexpr float scroll_ratio = 10; // Threshold on the trigger value to register a click constexpr float trigger_click_thd = 0.8; diff --git a/client/render/growable_descriptor_pool.cpp b/client/render/growable_descriptor_pool.cpp index 2cccd9d5..7d9bf52d 100644 --- a/client/render/growable_descriptor_pool.cpp +++ b/client/render/growable_descriptor_pool.cpp @@ -23,13 +23,41 @@ struct descriptor_set { - growable_descriptor_pool & growable_pool; + growable_descriptor_pool * growable_pool; vk::DescriptorPool pool; vk::raii::DescriptorSet ds; + descriptor_set(const descriptor_set &) = delete; + descriptor_set & operator=(const descriptor_set &) = delete; + + descriptor_set(growable_descriptor_pool * growable_pool, + vk::DescriptorPool pool, + vk::raii::DescriptorSet ds) : + growable_pool(growable_pool), + pool(pool), + ds(std::move(ds)) + { + } + + descriptor_set(descriptor_set && other) : + growable_pool(std::exchange(other.growable_pool, nullptr)), + pool(other.pool), + ds(std::move(other.ds)) + { + } + + descriptor_set & operator=(descriptor_set && other) + { + std::swap(*this, other); + return *this; + } + ~descriptor_set() { - for (auto & i: growable_pool.pools) + if (not growable_pool) + return; + + for (auto & i: growable_pool->pools) { if (*i.descriptor_pool == pool) { @@ -43,7 +71,7 @@ struct descriptor_set growable_descriptor_pool::growable_descriptor_pool( vk::raii::Device & device, vk::raii::DescriptorSetLayout & layout, - std::span bindings, + std::span bindings, int descriptorsets_per_pool) : device(device), layout_(nullptr), @@ -84,7 +112,7 @@ std::shared_ptr growable_descriptor_pool::allocate() i.free_count--; alloc_info.descriptorPool = *i.descriptor_pool; - auto ds = std::make_shared(*this, *i.descriptor_pool, std::move(device.allocateDescriptorSets(alloc_info)[0])); + auto ds = std::make_shared(this, *i.descriptor_pool, std::move(device.allocateDescriptorSets(alloc_info)[0])); return std::shared_ptr(ds, &ds->ds); } @@ -103,7 +131,7 @@ std::shared_ptr growable_descriptor_pool::allocate() alloc_info.descriptorPool = *pools.back().descriptor_pool; - auto ds = std::make_shared(*this, *pools.back().descriptor_pool, std::move(device.allocateDescriptorSets(alloc_info)[0])); + auto ds = std::make_shared(this, *pools.back().descriptor_pool, std::move(device.allocateDescriptorSets(alloc_info)[0])); return std::shared_ptr(ds, &ds->ds); } diff --git a/client/render/growable_descriptor_pool.h b/client/render/growable_descriptor_pool.h index 56a93412..9ade4c24 100644 --- a/client/render/growable_descriptor_pool.h +++ b/client/render/growable_descriptor_pool.h @@ -40,7 +40,7 @@ class growable_descriptor_pool std::vector pools; public: - growable_descriptor_pool(vk::raii::Device & device, vk::raii::DescriptorSetLayout & layout, std::span bindings, int descriptorsets_per_pool = 100); + growable_descriptor_pool(vk::raii::Device & device, vk::raii::DescriptorSetLayout & layout, std::span bindings, int descriptorsets_per_pool = 100); std::shared_ptr allocate(); }; diff --git a/client/render/image_loader.cpp b/client/render/image_loader.cpp index 2c34e0f3..16dfe4cd 100644 --- a/client/render/image_loader.cpp +++ b/client/render/image_loader.cpp @@ -471,6 +471,41 @@ static constexpr bool starts_with(std::span data, std::span= prefix.size() && !memcmp(data.data(), prefix.data(), prefix.size()); } +template +void premultiply_alpha_aux(T * pixels, float alpha_scale, int width, int height) +{ + for (int i = 0, n = width * height; i < n; i++) + { + float alpha = pixels[4 * i + 3] * alpha_scale; + + pixels[4 * i + 0] = pixels[4 * i + 0] * alpha; + pixels[4 * i + 1] = pixels[4 * i + 1] * alpha; + pixels[4 * i + 2] = pixels[4 * i + 2] * alpha; + } +} + +static void premultiply_alpha(void * pixels, vk::Extent3D extent, vk::Format format) +{ + switch (format) + { + case vk::Format::eR8G8B8A8Srgb: // TODO: sRGB + case vk::Format::eR8G8B8A8Unorm: + premultiply_alpha_aux((uint8_t *)pixels, 1. / 255., extent.width, extent.height); + break; + + case vk::Format::eR16G16B16A16Unorm: + premultiply_alpha_aux((uint16_t *)pixels, 1. / 65535., extent.width, extent.height); + break; + + case vk::Format::eR32G32B32A32Sfloat: + premultiply_alpha_aux((float *)pixels, 1, extent.width, extent.height); + break; + + default: + break; + } +} + // Load a PNG/JPEG/KTX2 file void image_loader::load(std::span bytes, bool srgb) { @@ -517,6 +552,8 @@ void image_loader::load(std::span bytes, bool srgb) extent.height = h; extent.depth = 1; + premultiply_alpha(pixels.get(), extent, format); + do_load_raw(pixels.get(), extent, format); } } diff --git a/client/render/imgui_impl.cpp b/client/render/imgui_impl.cpp index 3ff6186f..06945c2f 100644 --- a/client/render/imgui_impl.cpp +++ b/client/render/imgui_impl.cpp @@ -289,32 +289,21 @@ imgui_context::imgui_frame & imgui_context::get_frame(vk::Image destination) return frame; } -static const std::array pool_sizes = - { - vk::DescriptorPoolSize{ - .type = vk::DescriptorType::eCombinedImageSampler, - .descriptorCount = constants::gui::nb_combined_image_samplers, - }}; - -static const vk::DescriptorSetLayoutBinding layout_bindings{ - .binding = 0, - .descriptorType = vk::DescriptorType::eCombinedImageSampler, - .descriptorCount = 1, - .stageFlags = vk::ShaderStageFlagBits::eFragment}; +static const std::array layout_bindings = { + vk::DescriptorSetLayoutBinding{ + .binding = 0, + .descriptorType = vk::DescriptorType::eCombinedImageSampler, + .descriptorCount = 1, + .stageFlags = vk::ShaderStageFlagBits::eFragment, + }}; imgui_context::imgui_context(vk::raii::PhysicalDevice physical_device, vk::raii::Device & device, uint32_t queue_family_index, vk::raii::Queue & queue, std::span controllers_, xr::swapchain & swapchain, std::vector layers) : physical_device(physical_device), device(device), queue_family_index(queue_family_index), queue(queue), - descriptor_pool(device, - vk::DescriptorPoolCreateInfo{ - .flags = vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, - .maxSets = pool_sizes[0].descriptorCount, - .poolSizeCount = pool_sizes.size(), - .pPoolSizes = pool_sizes.data(), - }), - ds_layout(device, vk::DescriptorSetLayoutCreateInfo{.bindingCount = 1, .pBindings = &layout_bindings}), + ds_layout(device, vk::DescriptorSetLayoutCreateInfo{.bindingCount = layout_bindings.size(), .pBindings = layout_bindings.data()}), + descriptor_pool(device, ds_layout, layout_bindings), renderpass(create_renderpass(device, swapchain.format(), true)), command_pool(device, vk::CommandPoolCreateInfo{ @@ -353,13 +342,13 @@ imgui_context::imgui_context(vk::raii::PhysicalDevice physical_device, vk::raii: .Device = *application::get_device(), .QueueFamily = application::queue_family_index(), .Queue = *application::get_queue(), - .DescriptorPool = *descriptor_pool, .RenderPass = *renderpass, .MinImageCount = 2, .ImageCount = (uint32_t)swapchain.images().size(), // used to cycle between VkBuffers in ImGui_ImplVulkan_RenderDrawData .MSAASamples = VK_SAMPLE_COUNT_1_BIT, .PipelineCache = *application::get_pipeline_cache(), .Subpass = 0, + .DescriptorPoolSize = 100, .Allocator = nullptr, .CheckVkResultFn = check_vk_result, }; @@ -722,7 +711,7 @@ void imgui_context::new_frame(XrTime display_time) ImPlot::SetCurrentContext(plot_context); if (last_display_time) - io.DeltaTime = std::min((display_time - last_display_time) * 1e-9f, 0.1f); + io.DeltaTime = std::min((display_time - last_display_time) * 1e-9f, 0.0166f); last_display_time = display_time; // Uses the window list from last frame @@ -752,7 +741,10 @@ void imgui_context::new_frame(XrTime display_time) io.AddMousePosEvent(position->x, position->y); if (glm::length(scroll) > constants::gui::scroll_value_thd) - io.AddMouseWheelEvent(scroll.x, scroll.y); + { + io.MouseWheel = scroll.y; + io.MouseWheelH = scroll.x; + } } } @@ -1018,16 +1010,17 @@ imgui_context::~imgui_context() } ImTextureID imgui_context::load_texture(const std::string & filename, vk::raii::Sampler && sampler) +{ + return load_texture(std::span{asset{filename}}, std::move(sampler)); +} + +ImTextureID imgui_context::load_texture(const std::span & bytes, vk::raii::Sampler && sampler) { bool srgb = true; image_loader loader(physical_device, device, queue, command_pool); - loader.load(asset{filename}, srgb); + loader.load(bytes, srgb); - vk::raii::DescriptorSet ds = std::move(device.allocateDescriptorSets({ - .descriptorPool = *descriptor_pool, - .descriptorSetCount = 1, - .pSetLayouts = &*ds_layout, - })[0]); + std::shared_ptr ds = descriptor_pool.allocate(); vk::DescriptorImageInfo image_info{ .sampler = *sampler, @@ -1036,14 +1029,14 @@ ImTextureID imgui_context::load_texture(const std::string & filename, vk::raii:: }; vk::WriteDescriptorSet ds_write{ - .dstSet = *ds, + .dstSet = **ds, .descriptorCount = 1, .descriptorType = vk::DescriptorType::eCombinedImageSampler, .pImageInfo = &image_info}; device.updateDescriptorSets(ds_write, nullptr); - ImTextureID id = reinterpret_cast(VkDescriptorSet(*ds)); + ImTextureID id = reinterpret_cast(VkDescriptorSet(**ds)); textures.emplace( id, @@ -1057,6 +1050,24 @@ ImTextureID imgui_context::load_texture(const std::string & filename, vk::raii:: return id; } +ImTextureID imgui_context::load_texture(const std::span & bytes) +{ + return load_texture( + bytes, + vk::raii::Sampler{ + device, + vk::SamplerCreateInfo{ + .magFilter = vk::Filter::eLinear, + .minFilter = vk::Filter::eLinear, + .mipmapMode = vk::SamplerMipmapMode::eLinear, + .addressModeU = vk::SamplerAddressMode::eClampToEdge, + .addressModeV = vk::SamplerAddressMode::eClampToEdge, + .addressModeW = vk::SamplerAddressMode::eClampToEdge, + .borderColor = vk::BorderColor::eFloatTransparentBlack, + }, + }); +} + ImTextureID imgui_context::load_texture(const std::string & filename) { return load_texture( @@ -1067,6 +1078,9 @@ ImTextureID imgui_context::load_texture(const std::string & filename) .magFilter = vk::Filter::eLinear, .minFilter = vk::Filter::eLinear, .mipmapMode = vk::SamplerMipmapMode::eLinear, + .addressModeU = vk::SamplerAddressMode::eClampToEdge, + .addressModeV = vk::SamplerAddressMode::eClampToEdge, + .addressModeW = vk::SamplerAddressMode::eClampToEdge, .borderColor = vk::BorderColor::eFloatTransparentBlack, }, }); diff --git a/client/render/imgui_impl.h b/client/render/imgui_impl.h index cedb31a1..025661ad 100644 --- a/client/render/imgui_impl.h +++ b/client/render/imgui_impl.h @@ -18,6 +18,7 @@ #pragma once +#include "render/growable_descriptor_pool.h" #include "wivrn_config.h" #include "xr/hand_tracker.h" #include "xr/space.h" @@ -46,7 +47,7 @@ class imgui_context { vk::raii::Sampler sampler; std::shared_ptr image_view; - vk::raii::DescriptorSet descriptor_set; + std::shared_ptr descriptor_set; }; public: @@ -121,8 +122,8 @@ private: vk::raii::Queue & queue; vk::raii::Pipeline pipeline = nullptr; - vk::raii::DescriptorPool descriptor_pool; vk::raii::DescriptorSetLayout ds_layout; + growable_descriptor_pool descriptor_pool; vk::raii::RenderPass renderpass; vk::raii::CommandPool command_pool; @@ -207,6 +208,8 @@ public: ImTextureID load_texture(const std::string & filename, vk::raii::Sampler && sampler); ImTextureID load_texture(const std::string & filename); + ImTextureID load_texture(const std::span & bytes, vk::raii::Sampler && sampler); + ImTextureID load_texture(const std::span & bytes); void free_texture(ImTextureID); void set_current(); diff --git a/client/scenes/lobby.cpp b/client/scenes/lobby.cpp index d4d4727f..cd328c19 100644 --- a/client/scenes/lobby.cpp +++ b/client/scenes/lobby.cpp @@ -906,6 +906,16 @@ void scenes::lobby::on_focused() { about_picture = imgui_ctx->load_texture(image + ".png"); } + + try + { + default_icon = imgui_ctx->load_texture("default_icon.ktx2"); + } + catch (...) + { + default_icon = imgui_ctx->load_texture("default_icon.png"); + } + setup_passthrough(); session.set_refresh_rate(application::get_config().preferred_refresh_rate.value_or(0)); multicast = application::get_wifi_lock().get_multicast_lock(); @@ -926,6 +936,8 @@ void scenes::lobby::on_unfocused() renderer->wait_idle(); // Must be before the scene data because the renderer uses its descriptor sets about_picture = 0; + default_icon = 0; + app_icons.clear(); imgui_ctx.reset(); world.clear(); // Must be cleared before the renderer so that the descriptor sets are freed before their pools diff --git a/client/scenes/lobby.h b/client/scenes/lobby.h index 86d8a77b..1ef69eae 100644 --- a/client/scenes/lobby.h +++ b/client/scenes/lobby.h @@ -118,6 +118,8 @@ class lobby : public scene_impl tab last_current_tab = tab::server_list; int optional_feature_index = 0; // Which step of the first run screen are we in ImTextureID about_picture; + ImTextureID default_icon; + std::unordered_map app_icons; virtual_keyboard keyboard; diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index 35dd784f..f01abf9a 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -32,40 +32,65 @@ #include "stream.h" #include "utils/i18n.h" #include "utils/overloaded.h" +#include "utils/ranges.h" #include "version.h" +#include #include +#include #include #include #include #include #include +#include #include #include "IconsFontAwesome6.h" -static void ScrollWhenDraggingOnVoid() +using namespace std::chrono_literals; + +// https://github.com/ocornut/imgui/issues/3379#issuecomment-2943903877 +static void ScrollWhenDragging() { ImVec2 delta{0.0f, -ImGui::GetIO().MouseDelta.y}; + const ImGuiMouseButton mouse_button = ImGuiMouseButton_Left; - // https://github.com/ocornut/imgui/issues/3379#issuecomment-1678718752 ImGuiContext & g = *ImGui::GetCurrentContext(); ImGuiWindow * window = g.CurrentWindow; - bool hovered = false; - bool held = false; - static bool held_prev = false; - - // Don't drag for the first frame because the current controller might have just changed and have a large delta - ImGuiID id = window->GetID("##scrolldraggingoverlay"); ImGui::KeepAliveID(id); - if (g.HoveredId == 0) // If nothing hovered so far in the frame (not same as IsAnyItemHovered()!) - ImGui::ButtonBehavior(window->Rect(), id, &hovered, &held, ImGuiButtonFlags_MouseButtonLeft); - if (held and held_prev and delta.x != 0.0f) - ImGui::SetScrollX(window, window->Scroll.x + delta.x); - if (held and held_prev and delta.y != 0.0f) - ImGui::SetScrollY(window, window->Scroll.y + delta.y); - held_prev = held; + static int active_id; + static ImVec2 cumulated_delta; + + bool HoveredIdAllowOverlap_backup = std::exchange(g.HoveredIdAllowOverlap, true); + bool ActiveIdAllowOverlap_backup = std::exchange(g.ActiveIdAllowOverlap, true); + if (active_id == 0 and ImGui::ItemHoverable(window->Rect(), 0, g.CurrentItemFlags) and ImGui::IsMouseClicked(mouse_button, ImGuiInputFlags_None, /*id*/ ImGuiKeyOwner_Any)) + { + active_id = id; + + // Don't scroll on the first step, in case the active controller just changed + delta = {}; + cumulated_delta = {}; + } + + if (not g.IO.MouseDown[mouse_button]) + active_id = 0; + + if (active_id == id) + { + if (delta.x != 0.0f) + ImGui::SetScrollX(window, window->Scroll.x + delta.x); + if (delta.y != 0.0f) + ImGui::SetScrollY(window, window->Scroll.y + delta.y); + + cumulated_delta += delta; + if (std::max(std::abs(cumulated_delta.x), std::abs(cumulated_delta.y)) > 50) + ImGui::ClearActiveID(); + } + + g.HoveredIdAllowOverlap = HoveredIdAllowOverlap_backup; + g.ActiveIdAllowOverlap = ActiveIdAllowOverlap_backup; } static void CenterTextH(const std::string & text) @@ -147,6 +172,54 @@ static void display_recentering_tip(imgui_context & ctx, const std::string & tip ImGui::PopFont(); } +// Display a button with an image and a text centred horizontally +static bool icon(const std::string & text, ImTextureRef tex_ref, const ImVec2 & image_size, ImGuiButtonFlags flags = 0, const ImVec2 & size_arg = ImVec2(0, 0), const ImVec2 & uv0 = ImVec2(0, 0), const ImVec2 & uv1 = ImVec2(1, 1), const ImVec4 & tint_col = ImVec4(1, 1, 1, 1)) +{ + // Based on ImGui::ButtonEx and ImGui::ImageButtonEx + ImGuiWindow * window = ImGui::GetCurrentWindow(); + const ImGuiStyle & style = ImGui::GetStyle(); + + if (window->SkipItems) + return false; + + const ImVec2 label_size = ImGui::CalcTextSize(text.c_str(), nullptr, true); + + ImVec2 size = ImGui::CalcItemSize( + size_arg, + std::max(image_size.x, label_size.x) + style.FramePadding.x * 2.0f, + image_size.y + style.ItemInnerSpacing.y + label_size.y + style.FramePadding.y * 2.0f); + + const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size); + + ImRect image_pos( + {(bb.Min.x + bb.Max.x - image_size.x) / 2, bb.Min.y + style.FramePadding.y}, + {(bb.Min.x + bb.Max.x + image_size.x) / 2, bb.Min.y + style.FramePadding.y + image_size.y}); + + ImRect label_pos( + {bb.Min.x + style.FramePadding.x, image_pos.Max.y + style.ItemInnerSpacing.y}, + {bb.Max.x - style.FramePadding.x, bb.Max.y - style.FramePadding.y}); + + ImGui::ItemSize(bb); + + ImGuiID id = window->GetID(text.c_str()); + if (!ImGui::ItemAdd(bb, id)) + return false; + + bool hovered, held; + bool pressed = ImGui::ButtonBehavior(bb, id, &hovered, &held, flags); + + // Render + const ImU32 col = ImGui::GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered + : ImGuiCol_Button); + ImGui::RenderNavCursor(bb, id); + ImGui::RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding); + + window->DrawList->AddImage(tex_ref, image_pos.Min, image_pos.Max, uv0, uv1, ImGui::GetColorU32(tint_col)); + ImGui::RenderTextClipped(label_pos.Min, label_pos.Max, text.c_str(), NULL, &label_size, style.ButtonTextAlign, &bb); + + return pressed; +} + std::string openxr_post_processing_flag_name(XrCompositionLayerSettingsFlagsFB flag) { switch (flag) @@ -307,6 +380,11 @@ void scenes::lobby::gui_connected() if (not next_scene) { current_tab = tab::server_list; + + for (const auto & [app_id, app_icon]: app_icons) + imgui_ctx->free_texture(app_icon); + app_icons.clear(); + return; } @@ -328,21 +406,72 @@ void scenes::lobby::gui_connected() } else { + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {20, 0}); ImGui::BeginChild("Main", ImGui::GetWindowSize() - ImGui::GetCursorPos() - ImVec2(0, disconnect_size.y + 80), 0); + + ImGui::Indent(20); if (server_name.empty()) ImGui::Text("%s", _S("Start an application on your computer or select one to start streaming.")); else ImGui::Text("%s", fmt::format(_F("Start an application on {} or select one to start streaming."), server_name).c_str()); - for (const auto & app: apps->applications) + ImGui::Unindent(); + + float icon_width = 400; + float icon_spacing = ImGui::GetStyle().ItemSpacing.x; + float usable_window_width = ImGui::GetWindowSize().x - ImGui::GetCurrentWindow()->ScrollbarSizes.x; + + int icons_per_line = (usable_window_width + icon_spacing) / (icon_width + icon_spacing); + float icon_line_width = icons_per_line * icon_width + (icons_per_line - 1) * icon_spacing; + + ImGui::Indent((usable_window_width - icon_line_width) / 2); + + auto t0 = std::chrono::steady_clock::now(); + for (const auto [index, app]: utils::enumerate(apps->applications)) { - if (ImGui::Button(fmt::format(ICON_FA_PLAY "##{}", app.id).c_str())) + ImTextureID texture = [&]() -> ImTextureID { + if (app.image.empty()) + return default_icon; + else + { + auto it = app_icons.find(app.id); + if (it == app_icons.end()) + { + // Don't load too many textures at the same time to keep the GUI responsive + if (std::chrono::steady_clock::now() - t0 > 10ms) + return default_icon; + + it = app_icons.emplace(app.id, imgui_ctx->load_texture(app.image)).first; + } + return it->second; + } + }(); + + ImGui::PushStyleColor(ImGuiCol_Button, 0); + if (icon(app.name + "##" + app.id, texture, {256, 256}, 0, {icon_width, 0})) next_scene->start_application(app.id); imgui_ctx->vibrate_on_hover(); - ImGui::SameLine(); - ImGui::Text("%s", app.name.c_str()); + ImGui::PopStyleColor(); // ImGuiCol_Button + + if (index % 3 != 2) + ImGui::SameLine(); } - ScrollWhenDraggingOnVoid(); + ImGui::Unindent(); + + std::vector> to_be_removed; + for (const auto & [app_id, app_icon]: app_icons) + { + if (not std::ranges::contains(apps->applications, app_id, &to_headset::application_list::application::id)) + to_be_removed.emplace_back(app_id, app_icon); + } + for (const auto & [app_id, app_icon]: to_be_removed) + { + imgui_ctx->free_texture(app_icon); + app_icons.erase(app_id); + } + + ScrollWhenDragging(); ImGui::EndChild(); + ImGui::PopStyleVar(); // ImGuiStyleVar_WindowPadding } ImGui::PopStyleVar(); @@ -358,7 +487,7 @@ void scenes::lobby::gui_connected() current_tab = tab::server_list; } imgui_ctx->vibrate_on_hover(); - ImGui::PopStyleColor(3); + ImGui::PopStyleColor(3); // ImGuiCol_Button, ImGuiCol_ButtonHovered, ImGuiCol_ButtonActive } void scenes::lobby::gui_new_server() @@ -1746,14 +1875,14 @@ std::vector> scenes::lobby::draw_gui(XrTi } else if (current_tab == tab::connected) { - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {20, 20}); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {0, 20}); ImGui::SetNextWindowSize({1400, 900}); ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 10); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {10, 10}); ImGui::Begin("WiVRn", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove); gui_connected(); ImGui::End(); - ImGui::PopStyleVar(3); // ImGuiStyleVar_WindowPadding + ImGui::PopStyleVar(3); // ImGuiStyleVar_WindowPadding, ImGuiStyleVar_FrameRounding, ImGuiStyleVar_FramePadding } else { @@ -1816,7 +1945,7 @@ std::vector> scenes::lobby::draw_gui(XrTi ImGui::Dummy(ImVec2(0, 20)); - ScrollWhenDraggingOnVoid(); + ScrollWhenDragging(); ImGui::EndChild(); ImGui::PopStyleVar(2); // ImGuiStyleVar_FrameRounding, ImGuiStyleVar_WindowPadding diff --git a/client/scenes/stream_tracking.cpp b/client/scenes/stream_tracking.cpp index 73576d0f..afc3c958 100644 --- a/client/scenes/stream_tracking.cpp +++ b/client/scenes/stream_tracking.cpp @@ -156,6 +156,7 @@ public: }; XrSpaceLocations spc_locations{ .type = XR_TYPE_SPACE_LOCATIONS, + .next = &spc_velocities, .locationCount = uint32_t(locations.size()), .locations = locations.data(), }; diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index a606adda..c580a4fd 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -44,9 +44,13 @@ add_library(wivrn-common STATIC EXCLUDE_FROM_ALL if (WIVRN_BUILD_DASHBOARD OR WIVRN_BUILD_SERVER) add_library(wivrn-common-server STATIC EXCLUDE_FROM_ALL utils/flatpak.cpp + utils/xdg_icon_lookup.cpp + utils/steam_app_info.cpp + utils/load_icon.cpp + utils/ini.cpp application.cpp ) - target_link_libraries(wivrn-common-server PRIVATE nlohmann_json::nlohmann_json PUBLIC wivrn-common-base) + target_link_libraries(wivrn-common-server PRIVATE nlohmann_json::nlohmann_json PNG::PNG PkgConfig::librsvg-2.0 PUBLIC wivrn-common-base) if (WIVRN_BUILD_TEST) add_executable(list-apps diff --git a/common/application.cpp b/common/application.cpp index ccd888e5..370b6437 100644 --- a/common/application.cpp +++ b/common/application.cpp @@ -20,7 +20,10 @@ #include "application.h" #include "utils/flatpak.h" +#include "utils/load_icon.h" +#include "utils/steam_app_info.h" #include "utils/xdg_base_directory.h" +#include "utils/xdg_icon_lookup.h" #include #include @@ -32,7 +35,6 @@ namespace wivrn namespace { - std::string read_file(const std::filesystem::path & path) { std::ifstream f(path); @@ -47,30 +49,82 @@ std::filesystem::path home() return home ? home : ""; } -std::pair read_vr_manifest() +std::pair> find_steam() { // system Steam - auto manifest = read_file(xdg_data_home() / "Steam/config/steamapps.vrmanifest"); - if (not manifest.empty()) - return {"steam", manifest}; + if (std::filesystem::exists(xdg_data_home() / "Steam")) + return {"steam", xdg_data_home() / "Steam"}; auto h = home(); // system Steam (accessed from flatpak) - manifest = read_file(h / ".local/share/Steam/config/steamapps.vrmanifest"); - if (not manifest.empty()) - return {"steam", manifest}; + if (std::filesystem::exists(h / ".local/share/Steam")) + return {"steam", h / ".local/share/Steam"}; // Flatpak Steam - manifest = read_file(h / ".var/app/com.valvesoftware.Steam/.steam/steam/config/steamapps.vrmanifest"); - if (not manifest.empty()) - return {"flatpak run com.valvesoftware.Steam", manifest}; + if (std::filesystem::exists(h / ".var/app/com.valvesoftware.Steam/.steam/steam")) + return {"flatpak run com.valvesoftware.Steam", h / ".var/app/com.valvesoftware.Steam/.steam/steam"}; + + return {}; +} + +std::string read_vr_manifest(const std::filesystem::path & root) +{ + return read_file(root / "config/steamapps.vrmanifest"); +} + +steam_app_info read_steam_app_info(const std::filesystem::path & root) +{ + try + { + return steam_app_info{root / "appcache/appinfo.vdf"}; + } + catch (...) + {} + + return {}; +} + +std::vector load_steam_icon(const std::filesystem::path & root, int app_id, const steam_app_info & info) +{ + const auto & app_info = info.get(app_id); + + try + { + std::string icon{std::get(app_info.at("common.clienticon"))}; + + auto image = load_icon(root / "steam/games" / (icon + ".ico"), 128); + if (not image.empty()) + return image; + } + catch (...) + { + } + + try + { + std::string icon{std::get(app_info.at("common.LinuxClientIcon"))}; + + auto image = load_icon(root / "steam/games" / (icon + ".zip"), 128); + if (not image.empty()) + return image; + } + catch (...) + { + } + return {}; } void read_steam_vr_apps(std::unordered_map & res) { - auto [command, manifest] = read_vr_manifest(); + auto [command, root] = find_steam(); + if (not root) + return; + + auto manifest = read_vr_manifest(*root); + auto info = read_steam_app_info(*root); + if (manifest.empty()) return; nlohmann::json json = nlohmann::json::parse(manifest); @@ -112,6 +166,19 @@ void read_steam_vr_apps(std::unordered_map & res) } } + try + { + const char prefix[] = "steam.app."; + if (app_key.starts_with(prefix)) + { + uint32_t app_id = stoll(app_key.substr(strlen(prefix))); + app.image = load_steam_icon(*root, app_id, info); + } + } + catch (...) + { + } + if (not app.exec.empty()) res[app_key] = std::move(app); } @@ -253,6 +320,11 @@ std::optional do_desktop_entry(const std::filesystem::path & filena res->exec = unescape(item.value); if (item.key == "Path") res->path = unescape(item.value); + if (item.key == "Icon") + { + if (auto filename = xdg_icon_lookup(std::string{item.value}, 256)) + res->image = load_icon(*filename, 256); + } } if (res->exec.empty() or not res->name.contains("")) @@ -299,8 +371,10 @@ std::unordered_map list_applications(bool include_stea read_steam_vr_apps(res); do_data_dir(xdg_data_home(), res); + for (auto && dir: xdg_data_dirs()) do_data_dir(std::move(dir), res); + if (wivrn::is_flatpak()) { // Try to guess host data dirs diff --git a/common/application.h b/common/application.h index 33d97e8f..6c9314dd 100644 --- a/common/application.h +++ b/common/application.h @@ -21,6 +21,7 @@ #include #include #include +#include namespace wivrn { @@ -30,6 +31,7 @@ struct application // localised names, with empty locale for default std::unordered_map name; std::string exec; + std::vector image; // In PNG std::optional path; }; diff --git a/common/utils/ini.cpp b/common/utils/ini.cpp new file mode 100644 index 00000000..156176b4 --- /dev/null +++ b/common/utils/ini.cpp @@ -0,0 +1,92 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2025 Guillaume Meunier + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ini.h" +#include + +static constexpr std::string_view strip(std::string_view sv) +{ + size_t prefix_size = sv.find_first_not_of(' '); + + if (prefix_size == std::string_view::npos) + return {}; + + sv.remove_prefix(prefix_size); + + size_t suffix_size = sv.find_last_not_of(' '); + if (suffix_size == std::string_view::npos) + return {}; + + sv.remove_suffix(sv.size() - suffix_size - 1); + + return sv; +} + +static constexpr std::optional parse_key_value(std::string_view section, std::string_view line) +{ + size_t equal_sign = line.find('='); + if (equal_sign == std::string_view::npos) + return {}; + + auto key = strip(line.substr(0, equal_sign)); // TODO locale + auto value = strip(line.substr(equal_sign + 1)); + + return wivrn::ini::key_value{ + .section = section, + .key = key, + .locale = "", + .value = value, + }; +} + +std::optional wivrn::ini::get_optional(std::string_view section, std::string_view key) const +{ + for (const auto & line: lines) + { + if (line.section == section and line.key == key) + return line.value; + } + + return std::nullopt; +} + +wivrn::ini::ini(std::istream & file) +{ + contents = {std::istreambuf_iterator{file}, {}}; + + std::string_view current_section; + + for (auto bounds: contents | std::views::split('\n')) + { + auto line = strip({bounds.begin(), bounds.end()}); + + if (line.starts_with('#')) + continue; + + if (line.starts_with('[') and line.ends_with(']')) + { + current_section = line.substr(1, line.size() - 2); + continue; + } + + auto kv = parse_key_value(current_section, line); + + if (kv) + lines.push_back(*kv); + } +} diff --git a/common/utils/ini.h b/common/utils/ini.h new file mode 100644 index 00000000..2a63faab --- /dev/null +++ b/common/utils/ini.h @@ -0,0 +1,82 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2025 Guillaume Meunier + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace wivrn +{ +class ini +{ +public: + struct key_value + { + std::string_view section; + std::string_view key; + std::string_view locale; + std::string_view value; + }; + +private: + std::string contents; + std::vector lines; + +public: + ini() = default; + ini(ini &&) = default; + ini(const ini &) = delete; + ini & operator=(ini &&) = default; + ini & operator=(const ini &) = delete; + + ini(std::istream & file); + + std::optional get_optional(std::string_view section, std::string_view key) const; + + template + T get(std::string_view section, std::string_view key, const T & default_value = T{}) const + { + using return_type = std::decay_t; + + auto value = get_optional(section, key); + + if (not value) + return default_value; + + if constexpr (std::is_same_v) + return *value; + + if constexpr (std::is_same_v) + return std::string{*value}; + + if constexpr (std::is_integral_v) + { + return_type v; + if (std::from_chars(value->data(), value->data() + value->size(), v).ec != std::errc{}) + return default_value; + + return v; + } + } +}; +} // namespace wivrn diff --git a/common/utils/load_icon.cpp b/common/utils/load_icon.cpp new file mode 100644 index 00000000..dd70af54 --- /dev/null +++ b/common/utils/load_icon.cpp @@ -0,0 +1,450 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2025 Guillaume Meunier + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "load_icon.h" + +#include +#include +#include +#include +#include +#include +#include + +namespace +{ +std::vector load_file(const std::filesystem::path & filename) +{ + std::ifstream file(filename, std::ios::binary | std::ios::ate); + file.exceptions(std::ios_base::badbit | std::ios_base::failbit); + + size_t size = file.tellg(); + file.seekg(0); + + std::vector bytes(size); + + file.read(reinterpret_cast(bytes.data()), size); + return bytes; +} + +template + requires std::is_integral_v +T read(std::span & buffer) +{ + if (sizeof(T) > buffer.size()) + throw std::runtime_error{"File truncated"}; + + T value; + memcpy(&value, buffer.data(), sizeof(T)); + buffer = buffer.subspan(sizeof(T)); + + static_assert(std::endian::native == std::endian::big or std::endian::native == std::endian::little); + + if constexpr (std::endian::native == std::endian::big) + return std::byteswap(value); + else + return value; +} + +std::span read(std::span & buffer, size_t size) +{ + if (size > buffer.size()) + throw std::runtime_error{"File truncated"}; + + std::span value{buffer.data(), size}; + buffer = buffer.subspan(size); + return value; +} + +std::vector load_svg(const std::filesystem::path & filename, int size) +{ + // TODO check if aspect ratio needs to be handled, dpi + + struct deleter + { + void operator()(GFile * ptr) + { + g_object_unref(ptr); + } + + void operator()(RsvgHandle * ptr) + { + g_object_unref(ptr); + } + + void operator()(cairo_surface_t * ptr) + { + cairo_surface_destroy(ptr); + } + + void operator()(cairo_t * ptr) + { + cairo_destroy(ptr); + } + }; + + using GFile_ptr = std::unique_ptr; + using RsvgHandle_ptr = std::unique_ptr; + using cairo_surface_t_ptr = std::unique_ptr; + using cairo_t_ptr = std::unique_ptr; + + GError * error{}; + GFile_ptr file{g_file_new_for_path(filename.c_str())}; + + RsvgHandle_ptr handle{rsvg_handle_new_from_gfile_sync(file.get(), RSVG_HANDLE_FLAGS_NONE, nullptr, &error)}; + + // Create a Cairo image surface and a rendering context for it + cairo_surface_t_ptr surface{cairo_image_surface_create(CAIRO_FORMAT_ARGB32, size, size)}; + cairo_t_ptr cr{cairo_create(surface.get())}; + + // Set the dots-per-inch + rsvg_handle_set_dpi(handle.get(), 96.0); + + // Render the handle scaled proportionally into that whole surface + RsvgRectangle viewport = { + .x = 0.0, + .y = 0.0, + .width = (double)size, + .height = (double)size, + }; + + if (!rsvg_handle_render_document(handle.get(), cr.get(), &viewport, &error)) + { + g_printerr("could not render: %s", error->message); + return {}; + } + + // Write a PNG file + std::vector png; + auto cb = [](void * closure, const unsigned char * data, unsigned int length) -> cairo_status_t { + std::vector & png = *reinterpret_cast *>(closure); + + size_t old_size = png.size(); + png.resize(old_size + length); + memcpy(&png[old_size], data, length); + + return CAIRO_STATUS_SUCCESS; + }; + + if (cairo_surface_write_to_png_stream(surface.get(), cb, &png) != CAIRO_STATUS_SUCCESS) + { + g_printerr("could not write output file"); + return {}; + } + + return png; +} + +// See https://gitlab.gnome.org/GNOME/gimp/-/tree/master/plug-ins/file-ico?ref_type=heads + +struct ico_file_entry +{ + int width; // Width of icon in pixels + int height; // Height of icon in pixels + int bpp; // 1, 4, 8, 16, 24 or 32 bits per pixel + std::span data; +}; + +int rowstride(int width, int bpp) +{ + switch (bpp) + { + case 1: + if ((width % 32) == 0) + return width / 8; + else + return 4 * (width / 32 + 1); + + // case 4: + // if ((width % 8) == 0) + // return width / 2; + // else + // return 4 * (width / 8 + 1); + // + // case 8: + // if ((width % 4) == 0) + // return width; + // else + // return 4 * (width / 4 + 1); + + case 24: + if (((width * 3) % 4) == 0) + return width * 3; + else + return 4 * (width * 3 / 4 + 1); + + case 32: + return width * 4; + + default: + return 0; + } +} + +std::vector load_ico(const std::filesystem::path & filename, int size, int index = -1) +{ + const uint32_t ICO_PNG_MAGIC = 0x474e5089; + + try + { + auto ico = load_file(filename); + + std::span header{ico}; + + auto reserved = read(header); + auto resource_type = read(header); + auto icon_count = read(header); + + if (reserved != 0 or resource_type != 1) + return {}; + + std::vector entries; + int max_bpp = 0; + + for (int i = 0; i < icon_count; i++) + { + ico_file_entry entry; + entry.width = read(header); + entry.height = read(header); + auto num_colors = read(header); + auto reserved = read(header); // reserved + auto planes = read(header); + entry.bpp = read(header); + auto size = read(header); + auto offset = read(header); + + entry.data = std::span{ico}.subspan(offset, size); + + if (entry.width == 0) + entry.width = 256; + if (entry.height == 0) + entry.height = 256; + if (reserved != 0) + return {}; + if (planes != 0 and planes != 1) + return {}; + + // Ignore 16bpp and less + if (entry.bpp < 24) + continue; + + entries.push_back(entry); + + max_bpp = std::max(max_bpp, entry.bpp); + } + + const ico_file_entry & best_entry = index >= 0 ? entries.at(index) : [&]() { + const ico_file_entry * best_entry; + + // Look for the smallest multiple of the requested size + int criterion = std::numeric_limits::max(); + + for (const auto & entry: entries) + { + if (entry.bpp != max_bpp) + continue; + + if (entry.width % size != 0 or entry.height % size != 0) + continue; + + if (std::min(entry.width, entry.height) / size < criterion) + { + criterion = std::min(entry.width, entry.height); + best_entry = &entry; + } + } + if (best_entry) + return *best_entry; + + // No multiple found: pick the largest icon + criterion = 0; + + for (const auto & entry: entries) + { + if (entry.bpp != max_bpp) + continue; + + if (entry.width * entry.height > criterion) + { + criterion = entry.width * entry.height; + best_entry = &entry; + } + } + return *best_entry; + }(); + + auto data = best_entry.data; + auto magic = read(data); + + if (magic == ICO_PNG_MAGIC) + { + // PNG file + std::vector png_data; + png_data.insert(png_data.end(), data.begin(), data.end()); + return png_data; + } + else if (magic == 40) + { + auto width = read(data); // Width of image in pixels + auto height = read(data); // Height of image in pixels + auto planes = read(data); // Must be 1 + auto bpp = read(data); // 1, 4, 8, 16, 24, 32 + auto compression = read(data); // Must be 0 for icons + auto image_size = read(data); // Size of image (without this header) + auto x_res = read(data); + auto y_res = read(data); + auto used_colors = read(data); + auto important_colors = read(data); + + if (planes != 1 or compression != 0) + return {}; + + if (bpp != 1 and + bpp != 4 and + bpp != 8 and + bpp != 16 and + bpp != 24 and + bpp != 32) + return {}; + + auto w = width; + auto h = height / 2; + + // Don't bother supporting paletted icons + // std::vector palette; + // + // if (bpp <= 8) + // { + // // Load the palette + // if (used_colors == 0) + // used_colors = 1 << bpp; + // + // palette.resize(used_colors); + // for (int i = 0; i < palette.size(); i++) + // palette[i] = read(data); + // } + + size_t xor_stride = rowstride(w, bpp); + size_t and_stride = rowstride(w, 1); + size_t dst_stride = 4 * w; + + std::span xor_map = read(data, xor_stride * h); + std::span and_map = read(data, and_stride * h); + + std::vector dest_buffer; + dest_buffer.resize(h * dst_stride); + + switch (bpp) + { + case 24: + for (int y = 0; y < h; y++) + { + uint8_t * src_xor_row = (uint8_t *)xor_map.data() + xor_stride * y; + uint8_t * src_and_row = (uint8_t *)and_map.data() + and_stride * y; + uint8_t * dst_row = dest_buffer.data() + dst_stride * (h - 1 - y); + + for (int x = 0, i = 0; x < w; x++) + { + uint8_t b = *src_xor_row++; // Red + uint8_t g = *src_xor_row++; // Green + uint8_t r = *src_xor_row++; // Blue + + // Get alpha from AND mask (0: opaque => 0xff, 1: transparent => 0) + uint8_t a = src_and_row[x / 8] & (1 << (7 - x % 8)) ? 0 : 0xff; + + *dst_row++ = b; + *dst_row++ = g; + *dst_row++ = r; + *dst_row++ = a; + } + } + + case 32: + for (int y = 0; y < h; y++) + { + uint8_t * src_xor_row = (uint8_t *)xor_map.data() + xor_stride * y; + uint8_t * dst_row = dest_buffer.data() + dst_stride * (h - 1 - y); + + memcpy(dst_row, src_xor_row, dst_stride); + } + break; + } + + png_image png{ + .version = PNG_IMAGE_VERSION, + .width = w, + .height = h, + .format = PNG_FORMAT_BGRA, + }; + + std::vector png_data{65536}; + png_alloc_size_t png_size = png_data.size(); + png_image_write_to_memory(&png, png_data.data(), &png_size, false /* convert_to_8_bit*/, dest_buffer.data(), w * 4, nullptr); + + if (png_size > png_data.size()) + { + png_data.resize(png_size); + png_image_write_to_memory(&png, png_data.data(), &png_size, false /* convert_to_8_bit*/, dest_buffer.data(), w * 4, nullptr); + } + else + png_data.resize(png_size); + + return png_data; + } + } + catch (std::exception & e) + { + } + + return {}; +} + +std::unordered_map> icon_cache; + +} // namespace + +const std::vector & wivrn::load_icon(const std::filesystem::path & filename, int size) +{ + auto it = icon_cache.find(filename); + if (it != icon_cache.end()) + return it->second; + + std::vector icon; + + if (filename.extension() == ".svg") + { + icon = load_svg(filename, size); + } + else if (filename.extension() == ".ico") + { + // Steam icon (Windows) + icon = load_ico(filename, size); + } + else if (filename.extension() == ".zip") + { + // Steam icon (Linux) + // TODO + } + else + { + // TODO read arbitrary format / rewrite as png + icon = load_file(filename); + } + + return icon_cache.emplace(filename, std::move(icon)).first->second; +} diff --git a/common/utils/load_icon.h b/common/utils/load_icon.h new file mode 100644 index 00000000..d89d8fdc --- /dev/null +++ b/common/utils/load_icon.h @@ -0,0 +1,27 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2025 Guillaume Meunier + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include +#include + +namespace wivrn +{ +const std::vector & load_icon(const std::filesystem::path & filename, int size); +} diff --git a/common/utils/steam_app_info.cpp b/common/utils/steam_app_info.cpp new file mode 100644 index 00000000..9e8e69dd --- /dev/null +++ b/common/utils/steam_app_info.cpp @@ -0,0 +1,183 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2025 Guillaume Meunier + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "steam_app_info.h" +#include +#include +#include +#include +#include + +namespace +{ +template +T read(std::span & buffer); + +template + requires std::is_integral_v +T read(std::span & buffer) +{ + if (sizeof(T) > buffer.size()) + throw std::runtime_error{"File truncated"}; + + T value; + memcpy(&value, buffer.data(), sizeof(T)); + buffer = buffer.subspan(sizeof(T)); + + static_assert(std::endian::native == std::endian::big or std::endian::native == std::endian::little); + + if constexpr (std::endian::native == std::endian::big) + return std::byteswap(value); + else + return value; +} + +template <> +std::string_view read(std::span & buffer) +{ + size_t size = strnlen((char *)buffer.data(), buffer.size()); + if (size == buffer.size()) + throw std::runtime_error{"File truncated"}; + + char * str = buffer.data(); + buffer = buffer.subspan(size + 1); + return {str, size}; +} + +std::span read(std::span & buffer, size_t size) +{ + if (size > buffer.size()) + throw std::runtime_error{"File truncated"}; + + std::span value{buffer.data(), size}; + buffer = buffer.subspan(size); + return value; +} + +std::vector read_string_table(std::span buffer) +{ + std::vector string_table; + + uint32_t count = read(buffer); + string_table.reserve(count); + + for (size_t i = 0; i < count; i++) + string_table.emplace_back(read(buffer)); + + return string_table; +} + +void read_vdf(wivrn::steam_app_info::info & info, const std::string & prefix, std::span & bindata, const std::vector & string_table) +{ + int type = read(bindata); + + while (type != 8) + { + std::string name{string_table.at(read(bindata))}; + + // https://github.com/ValveResourceFormat/ValveKeyValue/blob/master/ValveKeyValue/ValveKeyValue/KeyValues1/KV1BinaryNodeType.cs + switch (type) + { + case 0: // Dictionary + read_vdf(info, prefix + name + ".", bindata, string_table); + break; + + case 1: // UTF-8 string + info.emplace(prefix + name, read(bindata)); + break; + + case 2: // uint32_t + info.emplace(prefix + name, read(bindata)); + break; + + // case 3: // float + // break; + + default: + throw std::runtime_error{"Unknown object type " + std::to_string(type)}; + } + + type = read(bindata); + } +} +} // namespace + +wivrn::steam_app_info::steam_app_info(std::filesystem::path path) +{ + std::vector string_table; + + { + std::ifstream f{path}; + data = std::vector{std::istreambuf_iterator{f}, {}}; + } + std::span buffer = data; + + // See https://github.com/SteamDatabase/SteamAppInfo/blob/master/README.md#file-header + uint32_t magic = read(buffer); + if ((magic & 0xff'ff'ff'00) != 0x07'56'44'00) + throw std::runtime_error{"Wrong magic number"}; + int version = magic & 0xff; + + if (version < 41) + throw std::runtime_error{"Unsupported version"}; + + int universe = read(buffer); + if (version >= 41) + { + size_t string_offset = read(buffer); + string_table = read_string_table(std::span{data}.subspan(string_offset)); + } + else + throw std::runtime_error{"Unsupported version"}; + + while (true) + { + // See https://github.com/SteamDatabase/SteamAppInfo/blob/master/README.md#app-entry-repeated + + auto app_id = read(buffer); + if (app_id == 0) + break; + + auto size_data = read(buffer); + char * current_offset = buffer.data(); + + read(buffer); // info_state + read(buffer); // last_updated + read(buffer); // pics_token + read(buffer, 20); // SHA1 of the app info + read(buffer); // change number + // if (version < 38) + // read(buffer); // section type + read(buffer, 20); // SHA1 of the bin data + auto bindata = read(buffer, size_data - (buffer.data() - current_offset)); + + try + { + bindata = bindata.subspan(4 + 1); // Skip the checksum + type (must be 0) + + info app_info; + read_vdf(app_info, "", bindata, string_table); + + app_data.emplace(app_id, app_info); + } + catch (...) + { + // Ignore errors + } + } +} diff --git a/common/utils/steam_app_info.h b/common/utils/steam_app_info.h new file mode 100644 index 00000000..bc53788c --- /dev/null +++ b/common/utils/steam_app_info.h @@ -0,0 +1,51 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2025 Guillaume Meunier + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include +#include +#include +#include + +namespace wivrn +{ +class steam_app_info +{ +public: + using info = std::unordered_map>; + +private: + std::vector data; + + std::unordered_map app_data; + +public: + steam_app_info(std::filesystem::path path); + steam_app_info() = default; + steam_app_info(const steam_app_info &) = delete; + steam_app_info(steam_app_info &&) = default; + steam_app_info & operator=(const steam_app_info &) = delete; + steam_app_info & operator=(steam_app_info &&) = default; + + const auto & get(int appid) const + { + return app_data.at(appid); + } +}; +} // namespace wivrn diff --git a/common/utils/xdg_icon_lookup.cpp b/common/utils/xdg_icon_lookup.cpp new file mode 100644 index 00000000..75186c9a --- /dev/null +++ b/common/utils/xdg_icon_lookup.cpp @@ -0,0 +1,218 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2025 Guillaume Meunier + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "xdg_icon_lookup.h" + +#include "ini.h" +#include "strings.h" +#include "utils/flatpak.h" +#include "xdg_base_directory.h" + +#include +#include +#include +#include +#include + +namespace +{ +enum class icon_theme_type +{ + fixed, + scalable, + threshold +}; + +struct icon_theme_dir +{ + std::filesystem::path path; + + int size; + int scale; + icon_theme_type type; + int min_size; + int max_size; + int threshold; + + bool match_size(int required_size, int required_scale) const + { + if (scale != required_scale) + return false; + + switch (type) + { + case icon_theme_type::fixed: + return size == required_size; + + case icon_theme_type::scalable: + return min_size <= required_size and required_size <= max_size; + + case icon_theme_type::threshold: + return size - threshold <= required_size and required_size <= size + threshold; + } + + return false; + } + + int size_distance(int required_size, int required_scale) const + { + switch (type) + { + case icon_theme_type::fixed: + return abs(size * scale - required_size * required_scale); + + case icon_theme_type::scalable: + if (required_size * required_scale < min_size * scale) + return min_size * scale - required_size * required_scale; + + if (required_size * required_scale > max_size * scale) + return required_size * required_scale - max_size * scale; + + return 0; + + case icon_theme_type::threshold: + if (required_size * required_scale < (size - threshold) * scale) + return min_size * scale - required_size * required_scale; + + if (required_size * required_scale > (size + threshold) * scale) + return required_size * required_scale - max_size * scale; + + return 0; + } + + return std::numeric_limits::max(); + } +}; + +void find_icon_theme_dirs_helper(const std::vector & base_dirs, std::vector & dirs, std::vector & themes, std::string theme) +{ + // Theme is passed by copy because the themes vector might be resized + for (const auto & base_dir: base_dirs) + { + const auto theme_dir = base_dir / "icons" / theme; + const auto index_theme = theme_dir / "index.theme"; + + if (not std::filesystem::exists(index_theme)) + continue; + + try + { + std::ifstream file{index_theme}; + wivrn::ini index{file}; + + for (const auto & inherited_theme: utils::split(index.get("Icon Theme", "Inherits", ""), ",")) + { + if (inherited_theme != "" and not std::ranges::contains(themes, inherited_theme)) + themes.push_back(inherited_theme); + } + + for (auto directory: utils::split(index.get("Icon Theme", "Directories", ""), ",")) + { + int size = index.get(directory, "Size"); + int scale = index.get(directory, "Scale", 1); + int min_size = index.get(directory, "MinSize", size); + int max_size = index.get(directory, "MaxSize", size); + int threshold = index.get(directory, "Threshold", 2); + + std::string type_str = index.get(directory, "Type", "Threshold"); + + icon_theme_type type = icon_theme_type::threshold; + if (type_str == "Fixed") + type = icon_theme_type::fixed; + else if (type_str == "Scalable") + type = icon_theme_type::scalable; + else if (type_str == "Threshold") + type = icon_theme_type::threshold; + + dirs.push_back(icon_theme_dir{ + .path = theme_dir / directory, + .size = size, + .scale = scale, + .type = type, + .min_size = min_size, + .max_size = max_size, + .threshold = threshold, + }); + } + } + catch (std::exception & e) + { + } + } +} + +std::vector find_icon_theme_dirs(std::vector themes) +{ + std::vector dirs; + std::vector base_dirs = xdg_data_dirs(); + + if (wivrn::is_flatpak()) + { + // Try to guess host data dirs + base_dirs.push_back("/run/host/usr/share"); + } + + for (size_t i = 0; i < themes.size(); ++i) + find_icon_theme_dirs_helper(base_dirs, dirs, themes, themes[i]); + + if (not std::ranges::contains(themes, "hicolor")) + find_icon_theme_dirs_helper(base_dirs, dirs, themes, "hicolor"); + + return dirs; +} +} // namespace + +std::optional wivrn::xdg_icon_lookup(const std::string & icon_name, int size, int scale) +{ + if (std::filesystem::exists(icon_name)) + return icon_name; + + static const std::vector dirs = find_icon_theme_dirs({"hicolor"}); + + for (const auto & dir: dirs) + { + if (dir.match_size(size, scale)) + { + for (const auto & ext: {".png", ".svg", ".xpm"}) + { + if (std::filesystem::exists(dir.path / (icon_name + ext))) + return dir.path / (icon_name + ext); + } + } + } + + int best_distance = std::numeric_limits::max(); + std::optional best_path; + + for (const auto & dir: dirs) + { + if (dir.size_distance(size, scale) < best_distance) + { + for (const auto & ext: {".png", ".svg", ".xpm"}) + { + if (std::filesystem::exists(dir.path / (icon_name + ext))) + { + best_distance = dir.size_distance(size, scale); + best_path = dir.path / (icon_name + ext); + } + } + } + } + + return best_path; +} diff --git a/common/utils/xdg_icon_lookup.h b/common/utils/xdg_icon_lookup.h new file mode 100644 index 00000000..df81fd83 --- /dev/null +++ b/common/utils/xdg_icon_lookup.h @@ -0,0 +1,28 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2025 Guillaume Meunier + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include +#include +#include + +namespace wivrn +{ +std::optional xdg_icon_lookup(const std::string & icon_name, int size, int scale = 1); +} diff --git a/common/wivrn_packets.h b/common/wivrn_packets.h index 064b1a7b..68ccc398 100644 --- a/common/wivrn_packets.h +++ b/common/wivrn_packets.h @@ -675,6 +675,7 @@ struct application_list { std::string id; std::string name; + std::vector image; // In PNG }; std::vector applications; }; diff --git a/common/wivrn_sockets.cpp b/common/wivrn_sockets.cpp index 52ee823e..7a0be218 100644 --- a/common/wivrn_sockets.cpp +++ b/common/wivrn_sockets.cpp @@ -471,14 +471,14 @@ wivrn::deserialization_packet wivrn::TCP::receive_raw() { ssize_t expected_size; - if (data.size_bytes() < sizeof(uint16_t)) + if (data.size_bytes() < sizeof(uint32_t)) { - expected_size = sizeof(uint16_t) - data.size_bytes(); + expected_size = sizeof(uint32_t) - data.size_bytes(); } else { - uint32_t payload_size = *reinterpret_cast(data.data()); - expected_size = payload_size + sizeof(uint16_t) - data.size_bytes(); + uint32_t payload_size = *reinterpret_cast(data.data()); + expected_size = payload_size + sizeof(uint32_t) - data.size_bytes(); } if (expected_size > capacity_left) @@ -518,35 +518,35 @@ wivrn::deserialization_packet wivrn::TCP::receive_raw() capacity_left -= received_size; } - if (data.size_bytes() < sizeof(uint16_t)) + if (data.size_bytes() < sizeof(uint32_t)) return {}; - uint32_t payload_size = *reinterpret_cast(data.data()); + uint32_t payload_size = *reinterpret_cast(data.data()); if (payload_size == 0) throw std::runtime_error("Invalid packet: 0 size"); - if (data.size_bytes() < sizeof(uint16_t) + payload_size) + if (data.size_bytes() < sizeof(uint32_t) + payload_size) return {}; - auto span = data.subspan(sizeof(uint16_t), payload_size); - data = data.subspan(sizeof(uint16_t) + payload_size); + auto span = data.subspan(sizeof(uint32_t), payload_size); + data = data.subspan(sizeof(uint32_t) + payload_size); return deserialization_packet{buffer, span}; } wivrn::deserialization_packet wivrn::TCP::receive_pending() { - if (data.size_bytes() < sizeof(uint16_t)) + if (data.size_bytes() < sizeof(uint32_t)) return {}; - uint32_t payload_size = *reinterpret_cast(data.data()); + uint32_t payload_size = *reinterpret_cast(data.data()); if (payload_size == 0) throw std::runtime_error("Invalid packet: 0 size"); - if (data.size_bytes() < sizeof(uint16_t) + payload_size) + if (data.size_bytes() < sizeof(uint32_t) + payload_size) return {}; - auto span = data.subspan(sizeof(uint16_t), payload_size); - data = data.subspan(sizeof(uint16_t) + payload_size); + auto span = data.subspan(sizeof(uint32_t), payload_size); + data = data.subspan(sizeof(uint32_t) + payload_size); return deserialization_packet{buffer, span}; } @@ -557,7 +557,7 @@ void wivrn::TCP::send_raw(serialization_packet && packet) std::vector> & data = packet; - uint16_t size = 0; + uint32_t size = 0; iovecs.emplace_back(&size, sizeof(size)); for (const auto & span: data) { @@ -611,7 +611,7 @@ void wivrn::TCP::send_raw(serialization_packet && packet) void wivrn::TCP::send_many_raw(std::span packets) { thread_local std::vector iovecs; - thread_local std::vector sizes; + thread_local std::vector sizes; thread_local std::vector> spans; if (packets.empty()) diff --git a/docs/building.md b/docs/building.md index 199ddbc6..0340c73c 100644 --- a/docs/building.md +++ b/docs/building.md @@ -4,7 +4,7 @@ ## Dependencies -WiVRn requires avahi-client, eigen3, gettext, libpulse, libsystemd, nlohmann_json. +WiVRn requires avahi-client, eigen3, gettext, libpulse, libsystemd, nlohmann_json, librsvg2. It also requires at least one encoder: diff --git a/flake.nix b/flake.nix index fede2923..dde66d16 100644 --- a/flake.nix +++ b/flake.nix @@ -7,15 +7,18 @@ systems = [ "x86_64-linux" ]; perSystem = { lib, pkgs, ... }: let # Tools used for development work (clangd, clang-format) - devTools = with pkgs; [ - clang-tools - gdb - ktx-tools + devTools = [ + pkgs.clang-tools + pkgs.gdb + pkgs.ktx-tools ]; # Extra build inputs not yet in the nixpkgs recipe. - extraBuildInputs = with pkgs; [ + extraBuildInputs = [ # XRT_FEATURE_DEBUG_GUI requires SDL2 - sdl2-compat + pkgs.sdl2-compat + + pkgs.librsvg + pkgs.libpng ]; package = pkgs.enableDebugging (pkgs.wivrn.overrideAttrs (finalAttrs: oldAttrs: { diff --git a/server/driver/wivrn_controller.cpp b/server/driver/wivrn_controller.cpp index b5e69019..29578bd8 100644 --- a/server/driver/wivrn_controller.cpp +++ b/server/driver/wivrn_controller.cpp @@ -498,7 +498,9 @@ static std::ostream & operator<<(std::ostream & out, const xrt_space_relation_cs } } out << "x,y,z,"; - out << "qw,qx,qy,qz"; + out << "qw,qx,qy,qz,"; + out << "vx,vy,vz,"; + out << "avx,avy,avz"; return out; } @@ -506,13 +508,17 @@ static std::ostream & operator<<(std::ostream & out, const xrt_space_relation & { const auto & pos = rel.pose.position; const auto & o = rel.pose.orientation; + const auto & v = rel.linear_velocity; + const auto & av = rel.angular_velocity; for (const auto & [value, name]: magic_enum::enum_entries()) { if (value and value != XRT_SPACE_RELATION_BITMASK_ALL) out << bool(rel.relation_flags & value) << ','; } out << pos.x << ',' << pos.y << ',' << pos.z << ','; - out << o.w << ',' << o.x << ',' << o.y << ',' << o.z; + out << o.w << ',' << o.x << ',' << o.y << ',' << o.z << ','; + out << v.x << ',' << v.y << ',' << v.z << ','; + out << av.x << ',' << av.y << ',' << av.z; return out; } diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp index c0e4c3c4..eec2dd11 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -739,7 +739,8 @@ void wivrn_session::operator()(from_headset::get_application_list && request) response.applications.emplace_back( std::move(id), // FIXME: use locale - app.name.at("")); + app.name.at(""), + app.image); } send_control(std::move(response)); }