From 4b001b7e32f17b32f46092ea1c430ab6ffc23677 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Wed, 27 Sep 2023 14:28:23 -0400 Subject: [PATCH 01/51] Initial commit laying down the foundation --- CMakeLists.txt | 2 + src/platforms/CMakeLists.txt | 4 ++ src/platforms/virtual/CMakeLists.txt | 42 +++++++++++++ src/platforms/virtual/display.cpp | 65 ++++++++++++++++++++ src/platforms/virtual/display.h | 52 ++++++++++++++++ src/platforms/virtual/display_buffer.cpp | 69 +++++++++++++++++++++ src/platforms/virtual/display_buffer.h | 55 +++++++++++++++++ src/platforms/virtual/platform.cpp | 41 +++++++++++++ src/platforms/virtual/platform.h | 57 +++++++++++++++++ src/platforms/virtual/platform_symbols.cpp | 71 ++++++++++++++++++++++ src/platforms/virtual/symbols.map.in | 9 +++ 11 files changed, 467 insertions(+) create mode 100644 src/platforms/virtual/CMakeLists.txt create mode 100644 src/platforms/virtual/display.cpp create mode 100644 src/platforms/virtual/display.h create mode 100644 src/platforms/virtual/display_buffer.cpp create mode 100644 src/platforms/virtual/display_buffer.h create mode 100644 src/platforms/virtual/platform.cpp create mode 100644 src/platforms/virtual/platform.h create mode 100644 src/platforms/virtual/platform_symbols.cpp create mode 100644 src/platforms/virtual/symbols.map.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 64df5031da0..53f39bfb0cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -256,6 +256,8 @@ foreach(platform IN LISTS MIR_PLATFORM) endif() endforeach(platform) +set(MIR_BUILD_PLATFORM_VIRTUAL TRUE) + pkg_check_modules(GLM glm) if(NOT GLM_FOUND) find_package(glm REQUIRED) # There's no glm.pc on Fedora, but find_package(glm) fails on Ubuntu... diff --git a/src/platforms/CMakeLists.txt b/src/platforms/CMakeLists.txt index 1b742157588..b5026304136 100644 --- a/src/platforms/CMakeLists.txt +++ b/src/platforms/CMakeLists.txt @@ -67,4 +67,8 @@ if (MIR_BUILD_PLATFORM_WAYLAND) add_subdirectory(wayland) endif() +if (MIR_BUILD_PLATFORM_VIRTUAL) + add_subdirectory(virtual) +endif() + add_subdirectory(evdev/) diff --git a/src/platforms/virtual/CMakeLists.txt b/src/platforms/virtual/CMakeLists.txt new file mode 100644 index 00000000000..2d9a47f67d4 --- /dev/null +++ b/src/platforms/virtual/CMakeLists.txt @@ -0,0 +1,42 @@ +add_library(mirplatformvirtual-graphics STATIC + platform.cpp platform.h + display.cpp display.h + display_buffer.cpp display_buffer.h +) + +target_include_directories(mirplatformvirtual-graphics + PUBLIC + ${server_common_include_dirs} +) + +target_link_libraries(mirplatformvirtual-graphics + PUBLIC + mirplatform +) + +add_library(mirplatformvirtual MODULE + platform_symbols.cpp +) + +target_link_libraries(mirplatformvirtual + PRIVATE + mirplatformvirtual-graphics +) + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/symbols.map.in + ${CMAKE_CURRENT_BINARY_DIR}/symbols.map +) +set(symbol_map ${CMAKE_CURRENT_BINARY_DIR}/symbols.map) + +set_target_properties( + mirplatformvirtual PROPERTIES + OUTPUT_NAME graphics-virtual + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/server-modules + PREFIX "" + SUFFIX ".so.${MIR_SERVER_GRAPHICS_PLATFORM_ABI}" + LINK_FLAGS "-Wl,--exclude-libs=ALL -Wl,--version-script,${symbol_map}" + LINK_DEPENDS ${symbol_map} +) + +install(TARGETS mirplatformvirtual LIBRARY DESTINATION ${MIR_SERVER_PLATFORM_PATH}) diff --git a/src/platforms/virtual/display.cpp b/src/platforms/virtual/display.cpp new file mode 100644 index 00000000000..b7379cbb1ac --- /dev/null +++ b/src/platforms/virtual/display.cpp @@ -0,0 +1,65 @@ +/* + * Copyright © Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 2 or 3, + * as published by the Free Software Foundation. + * + * 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include "display.h" +#include + +namespace mg = mir::graphics; +namespace mgv = mir::graphics::virt; + +void mgv::Display::for_each_display_sync_group(const std::function &f) +{ + for (auto& db_ptr : display_buffers) + f(*db_ptr); +} + +std::unique_ptr mgv::Display::configuration() const +{ + return nullptr; +} + +bool mgv::Display::apply_if_configuration_preserves_display_buffers( + const mir::graphics::DisplayConfiguration &) +{ + return false; +} + +void mgv::Display::configure(const mir::graphics::DisplayConfiguration &) +{ + +} + +void mgv::Display::register_configuration_change_handler( + mir::graphics::EventHandlerRegister &, + const mir::graphics::DisplayConfigurationChangeHandler &) +{ + +} + +void mgv::Display::pause() +{ + +} + +void mgv::Display::resume() +{ + +} + +std::shared_ptr mgv::Display::create_hardware_cursor() +{ + return std::shared_ptr(); +} diff --git a/src/platforms/virtual/display.h b/src/platforms/virtual/display.h new file mode 100644 index 00000000000..c99981d8f20 --- /dev/null +++ b/src/platforms/virtual/display.h @@ -0,0 +1,52 @@ +/* + * Copyright © Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 2 or 3, + * as published by the Free Software Foundation. + * + * 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#ifndef MIR_PLATFORMS_VIRTUAL_DISPLAY_H_ +#define MIR_PLATFORMS_VIRTUAL_DISPLAY_H_ + +#include "display_buffer.h" +#include + +namespace mir +{ +namespace graphics +{ +namespace virt +{ + +class Display : public mir::graphics::Display +{ +public: + void for_each_display_sync_group(const std::function &f) override; + std::unique_ptr configuration() const override; + bool apply_if_configuration_preserves_display_buffers(const DisplayConfiguration &conf) override; + void configure(const DisplayConfiguration &conf) override; + void register_configuration_change_handler( + EventHandlerRegister &handlers, + const DisplayConfigurationChangeHandler &conf_change_handler) override; + void pause() override; + void resume() override; + std::shared_ptr create_hardware_cursor() override; + +private: + std::vector> display_buffers; +}; +} +} +} + + +#endif //MIR_PLATFORMS_VIRTUAL_DISPLAY_H_ diff --git a/src/platforms/virtual/display_buffer.cpp b/src/platforms/virtual/display_buffer.cpp new file mode 100644 index 00000000000..c816ac5ee82 --- /dev/null +++ b/src/platforms/virtual/display_buffer.cpp @@ -0,0 +1,69 @@ +/* + * Copyright © Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 2 or 3, + * as published by the Free Software Foundation. + * + * 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include "display_buffer.h" + +namespace mg = mir::graphics; +namespace mgv = mir::graphics::virt; +namespace geom = mir::geometry; + +mgv::DisplayBuffer::DisplayBuffer(std::shared_ptr provider) + : provider{provider} +{ + +} + +geom::Rectangle mgv::DisplayBuffer::view_area() const +{ + return area; +} + +bool mgv::DisplayBuffer::overlay(std::vector const& renderlist) +{ + (void)renderlist; + return false; +} + +glm::mat2 mgv::DisplayBuffer::transformation() const +{ + return transform; +} + +void mgv::DisplayBuffer::set_next_image(std::unique_ptr content) +{ + (void)content; +} + +auto mgv::DisplayBuffer::display_provider() const -> std::shared_ptr +{ + return provider; +} + +void mgv::DisplayBuffer::for_each_display_buffer(const std::function &f) +{ + f(*this); +} + +void mgv::DisplayBuffer::post() +{ + +} + +std::chrono::milliseconds mgv::DisplayBuffer::recommended_sleep() const +{ + return std::chrono::milliseconds(); +} + diff --git a/src/platforms/virtual/display_buffer.h b/src/platforms/virtual/display_buffer.h new file mode 100644 index 00000000000..99466ab71a5 --- /dev/null +++ b/src/platforms/virtual/display_buffer.h @@ -0,0 +1,55 @@ +/* + * Copyright © Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 2 or 3, + * as published by the Free Software Foundation. + * + * 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 Lesser General Public License for more details. +* + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#ifndef MIR_GRAPHICS_VIRTUAL_DISPLAY_BUFFER_H +#define MIR_GRAPHICS_VIRTUAL_DISPLAY_BUFFER_H + +#include "mir/graphics/display_buffer.h" +#include "mir/graphics/display.h" +#include "mir/graphics/renderable.h" + +namespace mir +{ +namespace graphics +{ +namespace virt +{ +class DisplayBuffer : public mir::graphics::DisplayBuffer, + public graphics::DisplaySyncGroup +{ +public: + DisplayBuffer(std::shared_ptr provider); + + geometry::Rectangle view_area() const override; + bool overlay(std::vector const& renderlist) override; + glm::mat2 transformation() const override; + void set_next_image(std::unique_ptr content) override; + auto display_provider() const -> std::shared_ptr override; + + void for_each_display_buffer(const std::function &f) override; + void post() override; + std::chrono::milliseconds recommended_sleep() const override; + +private: + geometry::Rectangle area; + glm::mat2 transform; + std::shared_ptr provider; +}; +} +} +} + +#endif //MIR_GRAPHICS_VIRTUAL_DISPLAY_BUFFER_H diff --git a/src/platforms/virtual/platform.cpp b/src/platforms/virtual/platform.cpp new file mode 100644 index 00000000000..543f7f542bd --- /dev/null +++ b/src/platforms/virtual/platform.cpp @@ -0,0 +1,41 @@ +/* + * Copyright © Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 2 or 3, + * as published by the Free Software Foundation. + * + * 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include "platform.h" +#include "display.h" +#include "mir/graphics/platform.h" + +namespace mg = mir::graphics; +namespace mgv = mir::graphics::virt; +using namespace std::literals; + +mgv::Platform::Platform(std::shared_ptr const& report) : + report{report} +{ +} + +mir::UniqueModulePtr mgv::Platform::create_display( + std::shared_ptr const&, + std::shared_ptr const&) +{ + return mir::make_module_ptr(); +} + +auto mgv::Platform::interface_for() -> std::shared_ptr +{ + return nullptr; +} + diff --git a/src/platforms/virtual/platform.h b/src/platforms/virtual/platform.h new file mode 100644 index 00000000000..a33e20f1e10 --- /dev/null +++ b/src/platforms/virtual/platform.h @@ -0,0 +1,57 @@ +/* + * Copyright © Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 2 or 3, + * as published by the Free Software Foundation. + * + * 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#ifndef MIR_GRAPHICS_VIRTUAL_PLATFORM_H_ +#define MIR_GRAPHICS_VIRTUAL_PLATFORM_H_ + +#include "mir/graphics/platform.h" +#include "mir/options/option.h" +#include "mir/graphics/display.h" +#include "mir/fd.h" + +#include +#include +#include +#include + +namespace mir +{ +namespace graphics +{ +namespace virt +{ +class Platform : public graphics::DisplayPlatform +{ +public: + Platform(std::shared_ptr const& report); + ~Platform() = default; + + + UniqueModulePtr create_display( + std::shared_ptr const& initial_conf_policy, + std::shared_ptr const& gl_config) override; + +protected: + auto interface_for() -> std::shared_ptr override; +private: + + std::shared_ptr const report; +}; +} +} +} + +#endif // MIR_GRAPHICS_VIRTUAL_PLATFORM_H_ diff --git a/src/platforms/virtual/platform_symbols.cpp b/src/platforms/virtual/platform_symbols.cpp new file mode 100644 index 00000000000..75b62449802 --- /dev/null +++ b/src/platforms/virtual/platform_symbols.cpp @@ -0,0 +1,71 @@ +/* + * Copyright © Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 2 or 3, + * as published by the Free Software Foundation. + * + * 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include +#include + +#include "platform.h" + +#include +#include +#include + +namespace mg = mir::graphics; +namespace mo = mir::options; +namespace mgv = mir::graphics::virt; + +namespace +{ +mir::ModuleProperties const description = { + "mir:virt", + MIR_VERSION_MAJOR, + MIR_VERSION_MINOR, + MIR_VERSION_MICRO, + mir::libname() +}; +} + +mir::UniqueModulePtr create_display_platform( + mg::SupportedDevice const&, + std::shared_ptr const&, + std::shared_ptr const&, + std::shared_ptr const& /*console*/, + std::shared_ptr const& report) +{ + mir::assert_entry_point_signature(&create_display_platform); + return mir::make_module_ptr(report); +} + +void add_graphics_platform_options(boost::program_options::options_description&) +{ + mir::assert_entry_point_signature(&add_graphics_platform_options); +} + +auto probe_display_platform( + std::shared_ptr const&, + std::shared_ptr const&, + mo::ProgramOption const&) -> std::vector +{ + mir::assert_entry_point_signature(&probe_display_platform); + std::vector result; + return result; +} + +mir::ModuleProperties const* describe_graphics_module() +{ + mir::assert_entry_point_signature(&describe_graphics_module); + return &description; +} diff --git a/src/platforms/virtual/symbols.map.in b/src/platforms/virtual/symbols.map.in new file mode 100644 index 00000000000..b27888b99be --- /dev/null +++ b/src/platforms/virtual/symbols.map.in @@ -0,0 +1,9 @@ +@MIR_SERVER_GRAPHICS_PLATFORM_VERSION@ { + global: + add_graphics_platform_options; + create_display_platform; + probe_display_platform; + describe_graphics_module; + local: + *; +}; \ No newline at end of file From a8db7371a563c728272f5d22cdc4c3664daac8ab Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Wed, 27 Sep 2023 14:36:34 -0400 Subject: [PATCH 02/51] First attempt to fix the runtime --- src/platforms/virtual/platform.h | 5 ----- src/platforms/virtual/platform_symbols.cpp | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/platforms/virtual/platform.h b/src/platforms/virtual/platform.h index a33e20f1e10..4d8a2a486fa 100644 --- a/src/platforms/virtual/platform.h +++ b/src/platforms/virtual/platform.h @@ -22,11 +22,6 @@ #include "mir/graphics/display.h" #include "mir/fd.h" -#include -#include -#include -#include - namespace mir { namespace graphics diff --git a/src/platforms/virtual/platform_symbols.cpp b/src/platforms/virtual/platform_symbols.cpp index 75b62449802..9f947e8c203 100644 --- a/src/platforms/virtual/platform_symbols.cpp +++ b/src/platforms/virtual/platform_symbols.cpp @@ -61,6 +61,11 @@ auto probe_display_platform( { mir::assert_entry_point_signature(&probe_display_platform); std::vector result; + result.push_back({ + nullptr, + mg::PlatformPriority::hosted, + nullptr + }); return result; } From d8ffe54dd206075b1abd1814ed6fafb3242973c8 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Thu, 28 Sep 2023 10:40:56 -0400 Subject: [PATCH 03/51] Able to run a Virtual Display, but unsure if it works yet --- src/platforms/virtual/CMakeLists.txt | 1 + src/platforms/virtual/display.cpp | 14 ++- src/platforms/virtual/display.h | 4 + .../virtual/display_configuration.cpp | 89 +++++++++++++++++++ src/platforms/virtual/display_configuration.h | 50 +++++++++++ src/platforms/virtual/platform.cpp | 77 +++++++++++++++- src/platforms/virtual/platform.h | 20 ++++- src/platforms/virtual/platform_symbols.cpp | 31 ++++++- 8 files changed, 276 insertions(+), 10 deletions(-) create mode 100644 src/platforms/virtual/display_configuration.cpp create mode 100644 src/platforms/virtual/display_configuration.h diff --git a/src/platforms/virtual/CMakeLists.txt b/src/platforms/virtual/CMakeLists.txt index 2d9a47f67d4..d0ab29371ab 100644 --- a/src/platforms/virtual/CMakeLists.txt +++ b/src/platforms/virtual/CMakeLists.txt @@ -2,6 +2,7 @@ add_library(mirplatformvirtual-graphics STATIC platform.cpp platform.h display.cpp display.h display_buffer.cpp display_buffer.h + display_configuration.cpp display_configuration.h ) target_include_directories(mirplatformvirtual-graphics diff --git a/src/platforms/virtual/display.cpp b/src/platforms/virtual/display.cpp index b7379cbb1ac..39483ebf8ff 100644 --- a/src/platforms/virtual/display.cpp +++ b/src/platforms/virtual/display.cpp @@ -15,11 +15,17 @@ */ #include "display.h" +#include "display_configuration.h" #include namespace mg = mir::graphics; namespace mgv = mir::graphics::virt; +mgv::Display::Display(std::vector output_sizes) + : output_sizes{output_sizes} +{ +} + void mgv::Display::for_each_display_sync_group(const std::function &f) { for (auto& db_ptr : display_buffers) @@ -28,7 +34,13 @@ void mgv::Display::for_each_display_sync_group(const std::function mgv::Display::configuration() const { - return nullptr; + std::lock_guard lock{mutex}; + std::vector output_configurations; + for (auto const& output : output_sizes) + { + output_configurations.push_back(mgv::DisplayConfiguration::build_output(output.size)); + } + return std::make_unique(output_configurations); } bool mgv::Display::apply_if_configuration_preserves_display_buffers( diff --git a/src/platforms/virtual/display.h b/src/platforms/virtual/display.h index c99981d8f20..f862272d0cf 100644 --- a/src/platforms/virtual/display.h +++ b/src/platforms/virtual/display.h @@ -17,6 +17,7 @@ #ifndef MIR_PLATFORMS_VIRTUAL_DISPLAY_H_ #define MIR_PLATFORMS_VIRTUAL_DISPLAY_H_ +#include "platform.h" #include "display_buffer.h" #include @@ -30,6 +31,7 @@ namespace virt class Display : public mir::graphics::Display { public: + Display(std::vector output_sizes); void for_each_display_sync_group(const std::function &f) override; std::unique_ptr configuration() const override; bool apply_if_configuration_preserves_display_buffers(const DisplayConfiguration &conf) override; @@ -43,6 +45,8 @@ class Display : public mir::graphics::Display private: std::vector> display_buffers; + std::vector output_sizes; + std::mutex mutable mutex; }; } } diff --git a/src/platforms/virtual/display_configuration.cpp b/src/platforms/virtual/display_configuration.cpp new file mode 100644 index 00000000000..6e97c1e2b80 --- /dev/null +++ b/src/platforms/virtual/display_configuration.cpp @@ -0,0 +1,89 @@ +/* + * Copyright © Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 2 or 3, + * as published by the Free Software Foundation. + * + * 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ +#include "display_configuration.h" + +namespace mg = mir::graphics; +namespace mgv = mir::graphics::virt; +namespace geom = mir::geometry; + +int mgv::DisplayConfiguration::last_output_id{0}; + +mg::DisplayConfigurationOutput mgv::DisplayConfiguration::build_output( + geom::Size const size) +{ + // TODO: Some of the values here are placeholder + last_output_id++; + return DisplayConfigurationOutput{ + mg::DisplayConfigurationOutputId{last_output_id}, + mg::DisplayConfigurationCardId{0}, + mg::DisplayConfigurationLogicalGroupId{0}, + mg::DisplayConfigurationOutputType::unknown, + {MirPixelFormat ::mir_pixel_format_argb_8888}, + {mg::DisplayConfigurationMode{size, 60.0}}, + 0, + size, + true, + true, + {0, 0}, + 0, + MirPixelFormat::mir_pixel_format_argb_8888, + mir_power_mode_on, + MirOrientation::mir_orientation_normal, + 1.f, + mir_form_factor_monitor, + mir_subpixel_arrangement_unknown, + {}, + mir_output_gamma_unsupported, + {}, + {}}; +} + +mgv::DisplayConfiguration::DisplayConfiguration(const std::vector &outputs) + : configuration{outputs} +{ +} + +mgv::DisplayConfiguration::DisplayConfiguration(DisplayConfiguration const& other) + : mg::DisplayConfiguration(), + configuration{other.configuration} +{ +} + +void mgv::DisplayConfiguration::for_each_output( + std::function f) const +{ + for (auto const& output: configuration) + f(output); +} + +void mgv::DisplayConfiguration::for_each_output(std::function f) +{ + for (auto& output: configuration) + { + mg::UserDisplayConfigurationOutput user(output); + f(user); + } +} + +std::unique_ptr mgv::DisplayConfiguration::clone() const +{ + return std::make_unique(*this); +} + +bool mgv::DisplayConfiguration::valid() const +{ + return mg::DisplayConfiguration::valid(); +} diff --git a/src/platforms/virtual/display_configuration.h b/src/platforms/virtual/display_configuration.h new file mode 100644 index 00000000000..f1dc2194884 --- /dev/null +++ b/src/platforms/virtual/display_configuration.h @@ -0,0 +1,50 @@ +/* + * Copyright © Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 2 or 3, + * as published by the Free Software Foundation. + * + * 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#ifndef MIR_GRAPHICS_VIRTUAL_DISPLAY_CONFIGURATION_H_ +#define MIR_GRAPHICS_VIRTUAL_DISPLAY_CONFIGURATION_H_ + +#include "mir/graphics/display_configuration.h" +#include + +namespace mir +{ +namespace graphics +{ +namespace virt +{ +class DisplayConfiguration : public mir::graphics::DisplayConfiguration +{ +public: + static DisplayConfigurationOutput build_output(geometry::Size const size); + DisplayConfiguration(std::vector const& outputs); + DisplayConfiguration(DisplayConfiguration const&); + virtual ~DisplayConfiguration() = default; + + void for_each_output(std::function f) const override; + void for_each_output(std::function f) override; + std::unique_ptr clone() const override; + bool valid() const override; + +private: + static int last_output_id; + std::vector configuration; +}; +} +} +} + +#endif //MIR_GRAPHICS_VIRTUAL_DISPLAY_CONFIGURATION_H_ diff --git a/src/platforms/virtual/platform.cpp b/src/platforms/virtual/platform.cpp index 543f7f542bd..a45183602f4 100644 --- a/src/platforms/virtual/platform.cpp +++ b/src/platforms/virtual/platform.cpp @@ -20,10 +20,67 @@ namespace mg = mir::graphics; namespace mgv = mir::graphics::virt; +namespace geom = mir::geometry; using namespace std::literals; -mgv::Platform::Platform(std::shared_ptr const& report) : - report{report} +namespace +{ +// TODO: This is copied from the X11 platform +auto parse_size_dimension(std::string const& str) -> int +{ + try + { + size_t num_end = 0; + int const value = std::stoi(str, &num_end); + if (num_end != str.size()) + BOOST_THROW_EXCEPTION(std::runtime_error("Output dimension \"" + str + "\" is not a valid number")); + if (value <= 0) + BOOST_THROW_EXCEPTION(std::runtime_error("Output dimensions must be greater than zero")); + return value; + } + catch (std::invalid_argument const &) + { + BOOST_THROW_EXCEPTION(std::runtime_error("Output dimension \"" + str + "\" is not a valid number")); + } + catch (std::out_of_range const &) + { + BOOST_THROW_EXCEPTION(std::runtime_error("Output dimension \"" + str + "\" is out of range")); + } +} + +auto parse_size(std::string const& str) -> mgv::VirtualOutputConfig +{ + auto const x = str.find('x'); // "x" between width and height + if (x == std::string::npos || x <= 0 || x >= str.size() - 1) + BOOST_THROW_EXCEPTION(std::runtime_error("Output size \"" + str + "\" does not have two dimensions")); + return mgv::VirtualOutputConfig{ + geom::Size{ + parse_size_dimension(str.substr(0, x)), + parse_size_dimension(str.substr(x + 1))}}; +} +} + +class mgv::Platform::VirtualDisplayInterfaceProvider : public mg::DisplayInterfaceProvider +{ +public: + explicit VirtualDisplayInterfaceProvider() + { + } + +protected: + auto maybe_create_interface(mg::DisplayInterfaceBase::Tag const&) + -> std::shared_ptr + { + return nullptr; + } +}; + +mgv::Platform::Platform( + std::shared_ptr const& report, + std::vector output_sizes) + : report{report}, + provider{std::make_shared()}, + output_sizes{output_sizes} { } @@ -31,11 +88,23 @@ mir::UniqueModulePtr mgv::Platform::create_display( std::shared_ptr const&, std::shared_ptr const&) { - return mir::make_module_ptr(); + return mir::make_module_ptr(output_sizes); } auto mgv::Platform::interface_for() -> std::shared_ptr { - return nullptr; + return provider; } +auto mgv::Platform::parse_output_sizes(std::string output_sizes) -> std::vector +{ + std::vector sizes; + for (int start = 0, end; start - 1 < (int)output_sizes.size(); start = end + 1) + { + end = output_sizes.find(':', start); + if (end == (int)std::string::npos) + end = output_sizes.size(); + sizes.push_back(parse_size(output_sizes.substr(start, end - start))); + } + return sizes; +} \ No newline at end of file diff --git a/src/platforms/virtual/platform.h b/src/platforms/virtual/platform.h index 4d8a2a486fa..54431e5226c 100644 --- a/src/platforms/virtual/platform.h +++ b/src/platforms/virtual/platform.h @@ -28,10 +28,24 @@ namespace graphics { namespace virt { + +struct VirtualOutputConfig +{ + VirtualOutputConfig(geometry::Size const& size) + : size{size} + { + } + + geometry::Size size; +}; + class Platform : public graphics::DisplayPlatform { public: - Platform(std::shared_ptr const& report); + static auto parse_output_sizes(std::string output_sizes) -> std::vector; + Platform( + std::shared_ptr const& report, + std::vector output_sizes); ~Platform() = default; @@ -42,8 +56,10 @@ class Platform : public graphics::DisplayPlatform protected: auto interface_for() -> std::shared_ptr override; private: - + class VirtualDisplayInterfaceProvider; std::shared_ptr const report; + std::shared_ptr const provider; + std::vector const output_sizes; }; } } diff --git a/src/platforms/virtual/platform_symbols.cpp b/src/platforms/virtual/platform_symbols.cpp index 9f947e8c203..31af2a02257 100644 --- a/src/platforms/virtual/platform_symbols.cpp +++ b/src/platforms/virtual/platform_symbols.cpp @@ -36,22 +36,30 @@ mir::ModuleProperties const description = { MIR_VERSION_MICRO, mir::libname() }; +char const* virtual_displays_option_name{"virtual-output"}; } mir::UniqueModulePtr create_display_platform( mg::SupportedDevice const&, - std::shared_ptr const&, + std::shared_ptr const& options, std::shared_ptr const&, std::shared_ptr const& /*console*/, std::shared_ptr const& report) { mir::assert_entry_point_signature(&create_display_platform); - return mir::make_module_ptr(report); + + auto output_sizes = mgv::Platform::parse_output_sizes(options->get(virtual_displays_option_name)); + return mir::make_module_ptr(report, std::move(output_sizes)); } -void add_graphics_platform_options(boost::program_options::options_description&) +void add_graphics_platform_options(boost::program_options::options_description& config) { mir::assert_entry_point_signature(&add_graphics_platform_options); + config.add_options() + (virtual_displays_option_name, + boost::program_options::value()->default_value("1280x1024"), + "[mir-on-virtual specific] Colon separated list of WIDTHxHEIGHT sizes for \"output\" windows." + " ^SCALE may also be appended to any output"); } auto probe_display_platform( @@ -69,6 +77,23 @@ auto probe_display_platform( return result; } +auto probe_rendering_platform( + std::span> const&, + mir::ConsoleServices&, + std::shared_ptr const&, + mir::options::ProgramOption const&) -> std::vector +{ + mir::assert_entry_point_signature(&probe_rendering_platform); + std::vector result; + result.emplace_back( + mg::SupportedDevice { + nullptr, + mg::PlatformPriority::supported, + nullptr + }); + return result; +} + mir::ModuleProperties const* describe_graphics_module() { mir::assert_entry_point_signature(&describe_graphics_module); From 709dd33f0cafa2898b452541627fd1d48b973b25 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Thu, 28 Sep 2023 18:26:30 -0400 Subject: [PATCH 04/51] StubGenericEGLDisplayProvider making the VNC work --- src/platforms/virtual/platform.cpp | 41 +++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/platforms/virtual/platform.cpp b/src/platforms/virtual/platform.cpp index a45183602f4..53c529dc5d9 100644 --- a/src/platforms/virtual/platform.cpp +++ b/src/platforms/virtual/platform.cpp @@ -68,9 +68,48 @@ class mgv::Platform::VirtualDisplayInterfaceProvider : public mg::DisplayInterfa } protected: - auto maybe_create_interface(mg::DisplayInterfaceBase::Tag const&) + auto maybe_create_interface(mg::DisplayInterfaceBase::Tag const& type_tag) -> std::shared_ptr { + class StubGenericEGLDisplayProvider : public GenericEGLDisplayProvider + { + public: + auto get_egl_display() -> EGLDisplay override + { + auto eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); + EGLint major, minor; + if (eglInitialize(eglDisplay, &major, &minor) == EGL_FALSE) + BOOST_THROW_EXCEPTION(std::runtime_error("Failed to initialize EGL display")); + return eglDisplay; + } + + class StubEGLFramebuffer : public EGLFramebuffer + { + public: + StubEGLFramebuffer() = default; + StubEGLFramebuffer(StubEGLFramebuffer const&) {} + void make_current() override {} + void release_current() override {}; + auto clone_handle() -> std::unique_ptr override + { + return std::make_unique(*this); + } + auto size() const -> geom::Size override + { + return geom::Size{}; + } + }; + + auto alloc_framebuffer(GLConfig const&, EGLContext) -> std::unique_ptr override + { + return std::make_unique(); + } + }; + + if (dynamic_cast(&type_tag)) + { + return std::make_shared(); + } return nullptr; } }; From 37f3f1357c9e325209893012cfedfc7c73ae9e9d Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Fri, 29 Sep 2023 11:39:59 -0400 Subject: [PATCH 05/51] Support for any number of --virtual-outputs with their own supported sizes --- src/platforms/virtual/display.cpp | 6 +-- src/platforms/virtual/display.h | 2 +- .../virtual/display_configuration.cpp | 15 +++++--- src/platforms/virtual/display_configuration.h | 3 +- src/platforms/virtual/platform.cpp | 37 +++++++++++-------- src/platforms/virtual/platform.h | 12 +++--- src/platforms/virtual/platform_symbols.cpp | 11 ++++-- 7 files changed, 50 insertions(+), 36 deletions(-) diff --git a/src/platforms/virtual/display.cpp b/src/platforms/virtual/display.cpp index 39483ebf8ff..e2fe92ee538 100644 --- a/src/platforms/virtual/display.cpp +++ b/src/platforms/virtual/display.cpp @@ -22,7 +22,7 @@ namespace mg = mir::graphics; namespace mgv = mir::graphics::virt; mgv::Display::Display(std::vector output_sizes) - : output_sizes{output_sizes} + : outputs{output_sizes} { } @@ -36,9 +36,9 @@ std::unique_ptr mgv::Display::configuration() const { std::lock_guard lock{mutex}; std::vector output_configurations; - for (auto const& output : output_sizes) + for (auto const& output : outputs) { - output_configurations.push_back(mgv::DisplayConfiguration::build_output(output.size)); + output_configurations.push_back(mgv::DisplayConfiguration::build_output(output)); } return std::make_unique(output_configurations); } diff --git a/src/platforms/virtual/display.h b/src/platforms/virtual/display.h index f862272d0cf..5825b738d63 100644 --- a/src/platforms/virtual/display.h +++ b/src/platforms/virtual/display.h @@ -45,7 +45,7 @@ class Display : public mir::graphics::Display private: std::vector> display_buffers; - std::vector output_sizes; + std::vector outputs; std::mutex mutable mutex; }; } diff --git a/src/platforms/virtual/display_configuration.cpp b/src/platforms/virtual/display_configuration.cpp index 6e97c1e2b80..c81df99df62 100644 --- a/src/platforms/virtual/display_configuration.cpp +++ b/src/platforms/virtual/display_configuration.cpp @@ -14,6 +14,7 @@ * along with this program. If not, see . */ #include "display_configuration.h" +#include "platform.h" namespace mg = mir::graphics; namespace mgv = mir::graphics::virt; @@ -21,10 +22,14 @@ namespace geom = mir::geometry; int mgv::DisplayConfiguration::last_output_id{0}; -mg::DisplayConfigurationOutput mgv::DisplayConfiguration::build_output( - geom::Size const size) +mg::DisplayConfigurationOutput mgv::DisplayConfiguration::build_output(mgv::VirtualOutputConfig const& config) { - // TODO: Some of the values here are placeholder + if (config.sizes.size() == 0) + BOOST_THROW_EXCEPTION(std::runtime_error("An output must be specified with at least one size")); + std::vector configuration_modes; + for (auto size : config.sizes) + configuration_modes.push_back({size, 60.0}); + last_output_id++; return DisplayConfigurationOutput{ mg::DisplayConfigurationOutputId{last_output_id}, @@ -32,9 +37,9 @@ mg::DisplayConfigurationOutput mgv::DisplayConfiguration::build_output( mg::DisplayConfigurationLogicalGroupId{0}, mg::DisplayConfigurationOutputType::unknown, {MirPixelFormat ::mir_pixel_format_argb_8888}, - {mg::DisplayConfigurationMode{size, 60.0}}, + std::move(configuration_modes), 0, - size, + config.sizes[0], true, true, {0, 0}, diff --git a/src/platforms/virtual/display_configuration.h b/src/platforms/virtual/display_configuration.h index f1dc2194884..9e866d5910d 100644 --- a/src/platforms/virtual/display_configuration.h +++ b/src/platforms/virtual/display_configuration.h @@ -26,10 +26,11 @@ namespace graphics { namespace virt { +class VirtualOutputConfig; class DisplayConfiguration : public mir::graphics::DisplayConfiguration { public: - static DisplayConfigurationOutput build_output(geometry::Size const size); + static DisplayConfigurationOutput build_output(VirtualOutputConfig const& config); DisplayConfiguration(std::vector const& outputs); DisplayConfiguration(DisplayConfiguration const&); virtual ~DisplayConfiguration() = default; diff --git a/src/platforms/virtual/platform.cpp b/src/platforms/virtual/platform.cpp index 53c529dc5d9..b6cf8f052e5 100644 --- a/src/platforms/virtual/platform.cpp +++ b/src/platforms/virtual/platform.cpp @@ -48,15 +48,14 @@ auto parse_size_dimension(std::string const& str) -> int } } -auto parse_size(std::string const& str) -> mgv::VirtualOutputConfig +auto parse_size(std::string const& str) -> geom::Size { auto const x = str.find('x'); // "x" between width and height if (x == std::string::npos || x <= 0 || x >= str.size() - 1) BOOST_THROW_EXCEPTION(std::runtime_error("Output size \"" + str + "\" does not have two dimensions")); - return mgv::VirtualOutputConfig{ - geom::Size{ - parse_size_dimension(str.substr(0, x)), - parse_size_dimension(str.substr(x + 1))}}; + return geom::Size{ + parse_size_dimension(str.substr(0, x)), + parse_size_dimension(str.substr(x + 1))}; } } @@ -116,10 +115,10 @@ class mgv::Platform::VirtualDisplayInterfaceProvider : public mg::DisplayInterfa mgv::Platform::Platform( std::shared_ptr const& report, - std::vector output_sizes) + std::vector outputs) : report{report}, provider{std::make_shared()}, - output_sizes{output_sizes} + outputs{outputs} { } @@ -127,7 +126,7 @@ mir::UniqueModulePtr mgv::Platform::create_display( std::shared_ptr const&, std::shared_ptr const&) { - return mir::make_module_ptr(output_sizes); + return mir::make_module_ptr(outputs); } auto mgv::Platform::interface_for() -> std::shared_ptr @@ -135,15 +134,21 @@ auto mgv::Platform::interface_for() -> std::shared_ptr return provider; } -auto mgv::Platform::parse_output_sizes(std::string output_sizes) -> std::vector +auto mgv::Platform::parse_output_sizes(std::vector virtual_outputs) -> std::vector { - std::vector sizes; - for (int start = 0, end; start - 1 < (int)output_sizes.size(); start = end + 1) + std::vector configs; + for (auto const& output : virtual_outputs) { - end = output_sizes.find(':', start); - if (end == (int)std::string::npos) - end = output_sizes.size(); - sizes.push_back(parse_size(output_sizes.substr(start, end - start))); + std::vector sizes; + for (int start = 0, end; start - 1 < (int)output.size(); start = end + 1) + { + end = output.find(':', start); + if (end == (int)std::string::npos) + end = output.size(); + sizes.push_back(parse_size(output.substr(start, end - start))); + } + + configs.push_back(VirtualOutputConfig(std::move(sizes))); } - return sizes; + return configs; } \ No newline at end of file diff --git a/src/platforms/virtual/platform.h b/src/platforms/virtual/platform.h index 54431e5226c..8d849df0425 100644 --- a/src/platforms/virtual/platform.h +++ b/src/platforms/virtual/platform.h @@ -31,21 +31,21 @@ namespace virt struct VirtualOutputConfig { - VirtualOutputConfig(geometry::Size const& size) - : size{size} + VirtualOutputConfig(std::vector sizes) + : sizes{sizes} { } - geometry::Size size; + std::vector sizes; }; class Platform : public graphics::DisplayPlatform { public: - static auto parse_output_sizes(std::string output_sizes) -> std::vector; + static auto parse_output_sizes(std::vector virtual_outputs) -> std::vector; Platform( std::shared_ptr const& report, - std::vector output_sizes); + std::vector outputs); ~Platform() = default; @@ -59,7 +59,7 @@ class Platform : public graphics::DisplayPlatform class VirtualDisplayInterfaceProvider; std::shared_ptr const report; std::shared_ptr const provider; - std::vector const output_sizes; + std::vector const outputs; }; } } diff --git a/src/platforms/virtual/platform_symbols.cpp b/src/platforms/virtual/platform_symbols.cpp index 31af2a02257..7618ca3facb 100644 --- a/src/platforms/virtual/platform_symbols.cpp +++ b/src/platforms/virtual/platform_symbols.cpp @@ -48,7 +48,8 @@ mir::UniqueModulePtr create_display_platform( { mir::assert_entry_point_signature(&create_display_platform); - auto output_sizes = mgv::Platform::parse_output_sizes(options->get(virtual_displays_option_name)); + auto outputs = options->get>(virtual_displays_option_name); + auto output_sizes = mgv::Platform::parse_output_sizes(outputs); return mir::make_module_ptr(report, std::move(output_sizes)); } @@ -57,9 +58,11 @@ void add_graphics_platform_options(boost::program_options::options_description& mir::assert_entry_point_signature(&add_graphics_platform_options); config.add_options() (virtual_displays_option_name, - boost::program_options::value()->default_value("1280x1024"), - "[mir-on-virtual specific] Colon separated list of WIDTHxHEIGHT sizes for \"output\" windows." - " ^SCALE may also be appended to any output"); + boost::program_options::value>() + ->default_value(std::vector{"1280x1024"}, "1280x1024") + ->multitoken(), + "[mir-on-virtual specific] Colon separated list of WIDTHxHEIGHT sizes for the \"output\" size." + "Multiple outputs may be specified by providing the argument multiple times."); } auto probe_display_platform( From acf4db5c5852002967fe87e66d2eb117d051a981 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Fri, 29 Sep 2023 14:01:08 -0400 Subject: [PATCH 06/51] Tests for Display and removing DisplayBuffer as it is unncessary for this task --- src/platforms/virtual/CMakeLists.txt | 1 - src/platforms/virtual/display.cpp | 14 +- src/platforms/virtual/display.h | 9 +- src/platforms/virtual/display_buffer.cpp | 69 ---------- src/platforms/virtual/display_buffer.h | 55 -------- tests/unit-tests/platforms/CMakeLists.txt | 4 + .../platforms/virtual/CMakeLists.txt | 32 +++++ .../platforms/virtual/test_display.cpp | 127 ++++++++++++++++++ .../platforms/virtual/test_platform.cpp | 15 +++ 9 files changed, 185 insertions(+), 141 deletions(-) delete mode 100644 src/platforms/virtual/display_buffer.cpp delete mode 100644 src/platforms/virtual/display_buffer.h create mode 100644 tests/unit-tests/platforms/virtual/CMakeLists.txt create mode 100644 tests/unit-tests/platforms/virtual/test_display.cpp create mode 100644 tests/unit-tests/platforms/virtual/test_platform.cpp diff --git a/src/platforms/virtual/CMakeLists.txt b/src/platforms/virtual/CMakeLists.txt index d0ab29371ab..50762c51f63 100644 --- a/src/platforms/virtual/CMakeLists.txt +++ b/src/platforms/virtual/CMakeLists.txt @@ -1,7 +1,6 @@ add_library(mirplatformvirtual-graphics STATIC platform.cpp platform.h display.cpp display.h - display_buffer.cpp display_buffer.h display_configuration.cpp display_configuration.h ) diff --git a/src/platforms/virtual/display.cpp b/src/platforms/virtual/display.cpp index e2fe92ee538..05637d1a607 100644 --- a/src/platforms/virtual/display.cpp +++ b/src/platforms/virtual/display.cpp @@ -15,8 +15,9 @@ */ #include "display.h" -#include "display_configuration.h" #include +#include "display_configuration.h" +#include namespace mg = mir::graphics; namespace mgv = mir::graphics::virt; @@ -26,15 +27,12 @@ mgv::Display::Display(std::vector output_sizes) { } -void mgv::Display::for_each_display_sync_group(const std::function &f) +void mgv::Display::for_each_display_sync_group(const std::function &) { - for (auto& db_ptr : display_buffers) - f(*db_ptr); } std::unique_ptr mgv::Display::configuration() const { - std::lock_guard lock{mutex}; std::vector output_configurations; for (auto const& output : outputs) { @@ -49,26 +47,22 @@ bool mgv::Display::apply_if_configuration_preserves_display_buffers( return false; } -void mgv::Display::configure(const mir::graphics::DisplayConfiguration &) +void mgv::Display::configure(mir::graphics::DisplayConfiguration const&) { - } void mgv::Display::register_configuration_change_handler( mir::graphics::EventHandlerRegister &, const mir::graphics::DisplayConfigurationChangeHandler &) { - } void mgv::Display::pause() { - } void mgv::Display::resume() { - } std::shared_ptr mgv::Display::create_hardware_cursor() diff --git a/src/platforms/virtual/display.h b/src/platforms/virtual/display.h index 5825b738d63..d95ba28a275 100644 --- a/src/platforms/virtual/display.h +++ b/src/platforms/virtual/display.h @@ -18,7 +18,6 @@ #define MIR_PLATFORMS_VIRTUAL_DISPLAY_H_ #include "platform.h" -#include "display_buffer.h" #include namespace mir @@ -33,9 +32,9 @@ class Display : public mir::graphics::Display public: Display(std::vector output_sizes); void for_each_display_sync_group(const std::function &f) override; - std::unique_ptr configuration() const override; - bool apply_if_configuration_preserves_display_buffers(const DisplayConfiguration &conf) override; - void configure(const DisplayConfiguration &conf) override; + std::unique_ptr configuration() const override; + bool apply_if_configuration_preserves_display_buffers(const mir::graphics::DisplayConfiguration &conf) override; + void configure(const mir::graphics::DisplayConfiguration &conf) override; void register_configuration_change_handler( EventHandlerRegister &handlers, const DisplayConfigurationChangeHandler &conf_change_handler) override; @@ -44,9 +43,7 @@ class Display : public mir::graphics::Display std::shared_ptr create_hardware_cursor() override; private: - std::vector> display_buffers; std::vector outputs; - std::mutex mutable mutex; }; } } diff --git a/src/platforms/virtual/display_buffer.cpp b/src/platforms/virtual/display_buffer.cpp deleted file mode 100644 index c816ac5ee82..00000000000 --- a/src/platforms/virtual/display_buffer.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright © Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License version 2 or 3, - * as published by the Free Software Foundation. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -#include "display_buffer.h" - -namespace mg = mir::graphics; -namespace mgv = mir::graphics::virt; -namespace geom = mir::geometry; - -mgv::DisplayBuffer::DisplayBuffer(std::shared_ptr provider) - : provider{provider} -{ - -} - -geom::Rectangle mgv::DisplayBuffer::view_area() const -{ - return area; -} - -bool mgv::DisplayBuffer::overlay(std::vector const& renderlist) -{ - (void)renderlist; - return false; -} - -glm::mat2 mgv::DisplayBuffer::transformation() const -{ - return transform; -} - -void mgv::DisplayBuffer::set_next_image(std::unique_ptr content) -{ - (void)content; -} - -auto mgv::DisplayBuffer::display_provider() const -> std::shared_ptr -{ - return provider; -} - -void mgv::DisplayBuffer::for_each_display_buffer(const std::function &f) -{ - f(*this); -} - -void mgv::DisplayBuffer::post() -{ - -} - -std::chrono::milliseconds mgv::DisplayBuffer::recommended_sleep() const -{ - return std::chrono::milliseconds(); -} - diff --git a/src/platforms/virtual/display_buffer.h b/src/platforms/virtual/display_buffer.h deleted file mode 100644 index 99466ab71a5..00000000000 --- a/src/platforms/virtual/display_buffer.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright © Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License version 2 or 3, - * as published by the Free Software Foundation. - * - * 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 Lesser General Public License for more details. -* - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -#ifndef MIR_GRAPHICS_VIRTUAL_DISPLAY_BUFFER_H -#define MIR_GRAPHICS_VIRTUAL_DISPLAY_BUFFER_H - -#include "mir/graphics/display_buffer.h" -#include "mir/graphics/display.h" -#include "mir/graphics/renderable.h" - -namespace mir -{ -namespace graphics -{ -namespace virt -{ -class DisplayBuffer : public mir::graphics::DisplayBuffer, - public graphics::DisplaySyncGroup -{ -public: - DisplayBuffer(std::shared_ptr provider); - - geometry::Rectangle view_area() const override; - bool overlay(std::vector const& renderlist) override; - glm::mat2 transformation() const override; - void set_next_image(std::unique_ptr content) override; - auto display_provider() const -> std::shared_ptr override; - - void for_each_display_buffer(const std::function &f) override; - void post() override; - std::chrono::milliseconds recommended_sleep() const override; - -private: - geometry::Rectangle area; - glm::mat2 transform; - std::shared_ptr provider; -}; -} -} -} - -#endif //MIR_GRAPHICS_VIRTUAL_DISPLAY_BUFFER_H diff --git a/tests/unit-tests/platforms/CMakeLists.txt b/tests/unit-tests/platforms/CMakeLists.txt index f40038f96d0..a8699ffed5e 100644 --- a/tests/unit-tests/platforms/CMakeLists.txt +++ b/tests/unit-tests/platforms/CMakeLists.txt @@ -10,6 +10,10 @@ if (MIR_BUILD_PLATFORM_X11) add_subdirectory(x11) endif() +if (MIR_BUILD_PLATFORM_VIRTUAL) + add_subdirectory(virtual) +endif () + set(UNIT_TEST_SOURCES ${UNIT_TEST_SOURCES} # ${CMAKE_CURRENT_SOURCE_DIR}/test_rendering_platform.cpp diff --git a/tests/unit-tests/platforms/virtual/CMakeLists.txt b/tests/unit-tests/platforms/virtual/CMakeLists.txt new file mode 100644 index 00000000000..339a70c07f7 --- /dev/null +++ b/tests/unit-tests/platforms/virtual/CMakeLists.txt @@ -0,0 +1,32 @@ +mir_add_wrapped_executable(mir_unit_tests_virtual NOINSTALL + ${CMAKE_CURRENT_SOURCE_DIR}/test_platform.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_display.cpp + $ + $ # Sub-optimal. We really want to link a lib +) + +set_property( + SOURCE test_platform.cpp + PROPERTY COMPILE_OPTIONS -Wno-variadic-macros) + +add_dependencies(mir_unit_tests_virtual GMock) + +set_target_properties( + mir_unit_tests_virtual + PROPERTIES + ENABLE_EXPORTS TRUE +) + +target_link_libraries( + mir_unit_tests_virtual + + mir-test-static + mir-test-doubles-static + mir-test-doubles-platform-static + mir-test-framework-static + server_platform_common +) + +if (MIR_RUN_UNIT_TESTS) + mir_discover_tests_with_fd_leak_detection(mir_unit_tests_virtual G_SLICE=always-malloc G_DEBUG=gc-friendly) +endif (MIR_RUN_UNIT_TESTS) diff --git a/tests/unit-tests/platforms/virtual/test_display.cpp b/tests/unit-tests/platforms/virtual/test_display.cpp new file mode 100644 index 00000000000..70b44acb4b0 --- /dev/null +++ b/tests/unit-tests/platforms/virtual/test_display.cpp @@ -0,0 +1,127 @@ +/* + * Copyright © Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 or 3 as + * published by the Free Software Foundation. + * + * 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 +#include + +#include "mir/graphics/platform.h" +#include "src/platforms/virtual/display.h" +#include "src/platforms/virtual/platform.h" +#include "src/server/report/null/display_report.h" + +#include "mir/graphics/display_configuration.h" + +#include "mir/test/doubles/null_display_configuration_policy.h" +#include "mir/test/doubles/mock_egl.h" +#include "mir/test/fake_shared.h" + + +namespace mg = mir::graphics; +namespace mgv = mg::virt; +namespace mt = mir::test; +namespace mtd = mt::doubles; +namespace geom = mir::geometry; +using namespace testing; + + +namespace +{ + + +class VirtualDisplayTest : public ::testing::Test +{ +public: + VirtualDisplayTest() + { + } + + std::shared_ptr create_display(std::vector sizes) + { + return std::make_shared(sizes); + } + + mtd::NullDisplayConfigurationPolicy null_display_configuration_policy; + ::testing::NiceMock mock_egl; +}; + +TEST_F(VirtualDisplayTest, reports_a_mode_size_that_matches_the_provided_size) +{ + auto display = create_display({ + mgv::VirtualOutputConfig({geom::Size{1280, 1024}}) + }); + auto config = display->configuration(); + int output_count = 0; + config->for_each_output([&output_count](mg::DisplayConfigurationOutput const& output) + { + EXPECT_THAT(output.modes.size(), Eq(1)); + EXPECT_THAT(output.modes[0].size, Eq(geom::Size{1280, 1024})); + output_count++; + }); + + EXPECT_THAT(output_count, Eq(1)); +} + +TEST_F(VirtualDisplayTest, reports_multiple_mode_sizes_that_matches_the_provided_sizes) +{ + auto display = create_display({ + mgv::VirtualOutputConfig({geom::Size{1280, 1024}, geom::Size{800, 600}}) + }); + auto config = display->configuration(); + int output_count = 0; + config->for_each_output([&output_count](mg::DisplayConfigurationOutput const& output) + { + EXPECT_THAT(output.modes.size(), Eq(2)); + EXPECT_THAT(output.modes[0].size, Eq(geom::Size{1280, 1024})); + EXPECT_THAT(output.modes[1].size, Eq(geom::Size{800, 600})); + output_count++; + }); + + EXPECT_THAT(output_count, Eq(1)); +} + +TEST_F(VirtualDisplayTest, reports_multiple_outputs_when_provided_multiple_outputs) +{ + auto display = create_display({ + mgv::VirtualOutputConfig({geom::Size{1280, 1024}}), + mgv::VirtualOutputConfig({geom::Size{1280, 1024}}) + }); + auto config = display->configuration(); + int output_count = 0; + config->for_each_output([&output_count](mg::DisplayConfigurationOutput const&) + { + output_count++; + }); + + EXPECT_THAT(output_count, Eq(2)); +} + +TEST_F(VirtualDisplayTest, for_each_display_group_iterates_no_display_groups) +{ + auto display = create_display({ + mgv::VirtualOutputConfig({geom::Size{1280, 1024}}), + mgv::VirtualOutputConfig({geom::Size{1280, 1024}}) + }); + + int count = 0; + display->for_each_display_sync_group([&count](auto&) + { + count++; + }); + + EXPECT_THAT(count, Eq(0)); +} + +} \ No newline at end of file diff --git a/tests/unit-tests/platforms/virtual/test_platform.cpp b/tests/unit-tests/platforms/virtual/test_platform.cpp new file mode 100644 index 00000000000..0a0fe8c8941 --- /dev/null +++ b/tests/unit-tests/platforms/virtual/test_platform.cpp @@ -0,0 +1,15 @@ +/* + * Copyright © Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 or 3 as + * published by the Free Software Foundation. + * + * 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 . + */ From e90a1cfc5e77c11a22a97a5e2e6c81a07f0fb83d Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Fri, 29 Sep 2023 15:42:19 -0400 Subject: [PATCH 07/51] Some initial tests, and breaking out the option parsing into the platform common lib --- src/platforms/common/server/CMakeLists.txt | 2 + .../common/server/options_parsing_helpers.cpp | 54 ++++++++++++++ .../common/server/options_parsing_helpers.h | 37 ++++++++++ src/platforms/virtual/CMakeLists.txt | 1 + src/platforms/virtual/platform.cpp | 39 +--------- src/platforms/virtual/platform.h | 1 - src/platforms/x11/CMakeLists.txt | 2 +- src/platforms/x11/graphics/CMakeLists.txt | 2 + src/platforms/x11/graphics/platform.cpp | 29 ++------ src/platforms/x11/input/CMakeLists.txt | 2 + .../platforms/virtual/test_display.cpp | 2 - .../platforms/virtual/test_platform.cpp | 72 +++++++++++++++++++ 12 files changed, 178 insertions(+), 65 deletions(-) create mode 100644 src/platforms/common/server/options_parsing_helpers.cpp create mode 100644 src/platforms/common/server/options_parsing_helpers.h diff --git a/src/platforms/common/server/CMakeLists.txt b/src/platforms/common/server/CMakeLists.txt index ba2fd013204..0fc0d9b8eb9 100644 --- a/src/platforms/common/server/CMakeLists.txt +++ b/src/platforms/common/server/CMakeLists.txt @@ -14,6 +14,8 @@ add_library(server_platform_common STATIC one_shot_device_observer.cpp cpu_copy_output_surface.cpp cpu_copy_output_surface.h + options_parsing_helpers.h + options_parsing_helpers.cpp ) target_include_directories( diff --git a/src/platforms/common/server/options_parsing_helpers.cpp b/src/platforms/common/server/options_parsing_helpers.cpp new file mode 100644 index 00000000000..5db5da682eb --- /dev/null +++ b/src/platforms/common/server/options_parsing_helpers.cpp @@ -0,0 +1,54 @@ +/* + * Copyright © Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 2 or 3, + * as published by the Free Software Foundation. + * + * 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include "options_parsing_helpers.h" +#include +#include + +namespace mgc = mir::graphics::common; +namespace geom = mir::geometry; + +auto mgc::parse_size_dimension(std::string const& str) -> int +{ + try + { + size_t num_end = 0; + int const value = std::stoi(str, &num_end); + if (num_end != str.size()) + BOOST_THROW_EXCEPTION(std::runtime_error("Output dimension \"" + str + "\" is not a valid number")); + if (value <= 0) + BOOST_THROW_EXCEPTION(std::runtime_error("Output dimensions must be greater than zero")); + return value; + } + catch (std::invalid_argument const &) + { + BOOST_THROW_EXCEPTION(std::runtime_error("Output dimension \"" + str + "\" is not a valid number")); + } + catch (std::out_of_range const &) + { + BOOST_THROW_EXCEPTION(std::runtime_error("Output dimension \"" + str + "\" is out of range")); + } +} + +auto mgc::parse_size(std::string const& str) -> geom::Size +{ + auto const x = str.find('x'); // "x" between width and height + if (x == std::string::npos || x <= 0 || x >= str.size() - 1) + BOOST_THROW_EXCEPTION(std::runtime_error("Output size \"" + str + "\" does not have two dimensions")); + return geom::Size{ + parse_size_dimension(str.substr(0, x)), + parse_size_dimension(str.substr(x + 1))}; +} \ No newline at end of file diff --git a/src/platforms/common/server/options_parsing_helpers.h b/src/platforms/common/server/options_parsing_helpers.h new file mode 100644 index 00000000000..75332df01c2 --- /dev/null +++ b/src/platforms/common/server/options_parsing_helpers.h @@ -0,0 +1,37 @@ +/* + * Copyright © Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 2 or 3, + * as published by the Free Software Foundation. + * + * 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#ifndef MIR_PLATFORM_OPTIONS_PARSING_HELPERS_H +#define MIR_PLATFORM_OPTIONS_PARSING_HELPERS_H + +#include +#include + +namespace mir +{ +namespace graphics +{ +namespace common +{ + +auto parse_size(std::string const& str) -> mir::geometry::Size; +auto parse_size_dimension(std::string const& str) -> int; + +} +} +} + +#endif //MIR_PLATFORM_OPTIONS_PARSING_HELPERS_H diff --git a/src/platforms/virtual/CMakeLists.txt b/src/platforms/virtual/CMakeLists.txt index 50762c51f63..43877264b61 100644 --- a/src/platforms/virtual/CMakeLists.txt +++ b/src/platforms/virtual/CMakeLists.txt @@ -12,6 +12,7 @@ target_include_directories(mirplatformvirtual-graphics target_link_libraries(mirplatformvirtual-graphics PUBLIC mirplatform + server_platform_common ) add_library(mirplatformvirtual MODULE diff --git a/src/platforms/virtual/platform.cpp b/src/platforms/virtual/platform.cpp index b6cf8f052e5..e636015aa82 100644 --- a/src/platforms/virtual/platform.cpp +++ b/src/platforms/virtual/platform.cpp @@ -17,48 +17,13 @@ #include "platform.h" #include "display.h" #include "mir/graphics/platform.h" +#include "options_parsing_helpers.h" namespace mg = mir::graphics; namespace mgv = mir::graphics::virt; namespace geom = mir::geometry; using namespace std::literals; -namespace -{ -// TODO: This is copied from the X11 platform -auto parse_size_dimension(std::string const& str) -> int -{ - try - { - size_t num_end = 0; - int const value = std::stoi(str, &num_end); - if (num_end != str.size()) - BOOST_THROW_EXCEPTION(std::runtime_error("Output dimension \"" + str + "\" is not a valid number")); - if (value <= 0) - BOOST_THROW_EXCEPTION(std::runtime_error("Output dimensions must be greater than zero")); - return value; - } - catch (std::invalid_argument const &) - { - BOOST_THROW_EXCEPTION(std::runtime_error("Output dimension \"" + str + "\" is not a valid number")); - } - catch (std::out_of_range const &) - { - BOOST_THROW_EXCEPTION(std::runtime_error("Output dimension \"" + str + "\" is out of range")); - } -} - -auto parse_size(std::string const& str) -> geom::Size -{ - auto const x = str.find('x'); // "x" between width and height - if (x == std::string::npos || x <= 0 || x >= str.size() - 1) - BOOST_THROW_EXCEPTION(std::runtime_error("Output size \"" + str + "\" does not have two dimensions")); - return geom::Size{ - parse_size_dimension(str.substr(0, x)), - parse_size_dimension(str.substr(x + 1))}; -} -} - class mgv::Platform::VirtualDisplayInterfaceProvider : public mg::DisplayInterfaceProvider { public: @@ -145,7 +110,7 @@ auto mgv::Platform::parse_output_sizes(std::vector virtual_outputs) end = output.find(':', start); if (end == (int)std::string::npos) end = output.size(); - sizes.push_back(parse_size(output.substr(start, end - start))); + sizes.push_back(common::parse_size(output.substr(start, end - start))); } configs.push_back(VirtualOutputConfig(std::move(sizes))); diff --git a/src/platforms/virtual/platform.h b/src/platforms/virtual/platform.h index 8d849df0425..a8114129513 100644 --- a/src/platforms/virtual/platform.h +++ b/src/platforms/virtual/platform.h @@ -48,7 +48,6 @@ class Platform : public graphics::DisplayPlatform std::vector outputs); ~Platform() = default; - UniqueModulePtr create_display( std::shared_ptr const& initial_conf_policy, std::shared_ptr const& gl_config) override; diff --git a/src/platforms/x11/CMakeLists.txt b/src/platforms/x11/CMakeLists.txt index a7bc2fe09b0..ec74f843b63 100644 --- a/src/platforms/x11/CMakeLists.txt +++ b/src/platforms/x11/CMakeLists.txt @@ -28,6 +28,7 @@ target_link_libraries( mirplatformserverx11 PRIVATE mirplatform + server_platform_common PkgConfig::EGL PkgConfig::GLESv2 PkgConfig::XCB @@ -39,7 +40,6 @@ target_link_libraries( xkbcommon-x11 X11 X11-xcb - server_platform_common Boost::program_options ) diff --git a/src/platforms/x11/graphics/CMakeLists.txt b/src/platforms/x11/graphics/CMakeLists.txt index 25ae3708128..69ff9ae07fc 100644 --- a/src/platforms/x11/graphics/CMakeLists.txt +++ b/src/platforms/x11/graphics/CMakeLists.txt @@ -23,6 +23,7 @@ target_link_libraries(mirplatformgraphicsx11objects-symbols mirplatform mircommon mircore + server_platform_common ) target_link_libraries( @@ -30,4 +31,5 @@ target_link_libraries( PRIVATE mirplatform + server_platform_common ) diff --git a/src/platforms/x11/graphics/platform.cpp b/src/platforms/x11/graphics/platform.cpp index 8a2adabb2f2..26e94b24512 100644 --- a/src/platforms/x11/graphics/platform.cpp +++ b/src/platforms/x11/graphics/platform.cpp @@ -21,6 +21,8 @@ #include "mir/graphics/egl_error.h" #include "mir/graphics/platform.h" #include "mir/options/option.h" +#include "options_parsing_helpers.h" +#include "shm_buffer.h" #include @@ -30,30 +32,9 @@ namespace geom = mir::geometry; namespace { -auto parse_size_dimension(std::string const& str) -> int -{ - try - { - size_t num_end = 0; - int const value = std::stoi(str, &num_end); - if (num_end != str.size()) - BOOST_THROW_EXCEPTION(std::runtime_error("Output dimension \"" + str + "\" is not a valid number")); - if (value <= 0) - BOOST_THROW_EXCEPTION(std::runtime_error("Output dimensions must be greater than zero")); - return value; - } - catch (std::invalid_argument const &) - { - BOOST_THROW_EXCEPTION(std::runtime_error("Output dimension \"" + str + "\" is not a valid number")); - } - catch (std::out_of_range const &) - { - BOOST_THROW_EXCEPTION(std::runtime_error("Output dimension \"" + str + "\" is out of range")); - } -} - auto parse_scale(std::string const& str) -> float { + mg::common::MappableBackedShmBuffer x(nullptr, nullptr); try { size_t num_end = 0; @@ -89,8 +70,8 @@ auto parse_size(std::string const& str) -> mgx::X11OutputConfig } return mgx::X11OutputConfig{ geom::Size{ - parse_size_dimension(str.substr(0, x)), - parse_size_dimension(str.substr(x + 1, scale_start - x - 1))}, + mir::graphics::common::parse_size_dimension(str.substr(0, x)), + mir::graphics::common::parse_size_dimension(str.substr(x + 1, scale_start - x - 1))}, scale}; } } diff --git a/src/platforms/x11/input/CMakeLists.txt b/src/platforms/x11/input/CMakeLists.txt index f2c092907c7..5bb5c84cbd3 100644 --- a/src/platforms/x11/input/CMakeLists.txt +++ b/src/platforms/x11/input/CMakeLists.txt @@ -14,6 +14,7 @@ target_link_libraries(mirplatforminputx11objects mirplatform mircommon mircore + server_platform_common ) add_library( @@ -26,4 +27,5 @@ target_link_libraries(mirplatforminputx11objects-symbols PUBLIC mirplatform mircommon + server_platform_common ) diff --git a/tests/unit-tests/platforms/virtual/test_display.cpp b/tests/unit-tests/platforms/virtual/test_display.cpp index 70b44acb4b0..47fc524a5a6 100644 --- a/tests/unit-tests/platforms/virtual/test_display.cpp +++ b/tests/unit-tests/platforms/virtual/test_display.cpp @@ -17,10 +17,8 @@ #include #include -#include "mir/graphics/platform.h" #include "src/platforms/virtual/display.h" #include "src/platforms/virtual/platform.h" -#include "src/server/report/null/display_report.h" #include "mir/graphics/display_configuration.h" diff --git a/tests/unit-tests/platforms/virtual/test_platform.cpp b/tests/unit-tests/platforms/virtual/test_platform.cpp index 0a0fe8c8941..59c6228a95e 100644 --- a/tests/unit-tests/platforms/virtual/test_platform.cpp +++ b/tests/unit-tests/platforms/virtual/test_platform.cpp @@ -13,3 +13,75 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + +#include +#include + +#include "mir/graphics/platform.h" +#include "mir/options/program_option.h" +#include "src/platforms/virtual/platform.h" + +#include "mir/shared_library.h" +#include "mir_test_framework/executable_path.h" +#include "src/server/report/null/display_report.h" + +namespace mg = mir::graphics; +namespace mgv = mir::graphics::virt; +namespace geom = mir::geometry; +using namespace testing; + +namespace +{ + +class VirtualGraphicsPlatformTest : public ::testing::Test +{ +public: + std::shared_ptr create_platform() + { + mgv::VirtualOutputConfig config({{1280, 1024}}); + return std::make_shared( + std::make_shared(), + std::vector{config}); + } +}; + +TEST_F(VirtualGraphicsPlatformTest, has_one_config_when_provided_one_output_size) +{ + auto configs = mgv::Platform::parse_output_sizes({"1280x1024"}); + EXPECT_THAT(configs.size(), Eq(1)); +} + +TEST_F(VirtualGraphicsPlatformTest, lone_config_has_one_output_size_when_provided_one_output_size) +{ + auto configs = mgv::Platform::parse_output_sizes({"1280x1024"}); + EXPECT_THAT(configs[0].sizes.size(), Eq(1)); +} + +TEST_F(VirtualGraphicsPlatformTest, lone_output_size_has_size_provided_by_string) +{ + auto configs = mgv::Platform::parse_output_sizes({"1280x1024"}); + EXPECT_THAT(configs[0].sizes, ElementsAre(geom::Size{1280, 1024})); +} + +TEST_F(VirtualGraphicsPlatformTest, multiple_output_sizes_are_read_when_multiple_are_provided) +{ + auto configs = mgv::Platform::parse_output_sizes({"1280x1024:800x600"}); + EXPECT_THAT(configs[0].sizes.size(), Eq(2)); +} + +TEST_F(VirtualGraphicsPlatformTest, multiple_output_sizes_are_set_correctly_when_multiple_are_provided) +{ + auto configs = mgv::Platform::parse_output_sizes({"1280x1024:800x600"}); + EXPECT_THAT(configs[0].sizes, ElementsAre( + geom::Size{1280, 1024}, + geom::Size{800, 600})); +} + +TEST_F(VirtualGraphicsPlatformTest, multiple_configs_are_parset_when_multiple_strings_are_provided) +{ + auto configs = mgv::Platform::parse_output_sizes({"1280x1024", "800x600"}); + EXPECT_THAT(configs[0].sizes, ElementsAre(geom::Size{1280, 1024})); + EXPECT_THAT(configs[1].sizes, ElementsAre(geom::Size{800, 600})); +} + +} \ No newline at end of file From 4837e7a20855015544d7f954a97f0b7a62de53ee Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Fri, 29 Sep 2023 15:44:07 -0400 Subject: [PATCH 08/51] Removing MIR_BUILD_PLATFORM_VIRTUAL as virtual is always valid --- CMakeLists.txt | 2 -- src/platforms/CMakeLists.txt | 5 +---- tests/unit-tests/platforms/CMakeLists.txt | 4 +--- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 53f39bfb0cd..64df5031da0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -256,8 +256,6 @@ foreach(platform IN LISTS MIR_PLATFORM) endif() endforeach(platform) -set(MIR_BUILD_PLATFORM_VIRTUAL TRUE) - pkg_check_modules(GLM glm) if(NOT GLM_FOUND) find_package(glm REQUIRED) # There's no glm.pc on Fedora, but find_package(glm) fails on Ubuntu... diff --git a/src/platforms/CMakeLists.txt b/src/platforms/CMakeLists.txt index b5026304136..2097d9bec94 100644 --- a/src/platforms/CMakeLists.txt +++ b/src/platforms/CMakeLists.txt @@ -67,8 +67,5 @@ if (MIR_BUILD_PLATFORM_WAYLAND) add_subdirectory(wayland) endif() -if (MIR_BUILD_PLATFORM_VIRTUAL) - add_subdirectory(virtual) -endif() - +add_subdirectory(virtual) add_subdirectory(evdev/) diff --git a/tests/unit-tests/platforms/CMakeLists.txt b/tests/unit-tests/platforms/CMakeLists.txt index a8699ffed5e..582c886726a 100644 --- a/tests/unit-tests/platforms/CMakeLists.txt +++ b/tests/unit-tests/platforms/CMakeLists.txt @@ -10,9 +10,7 @@ if (MIR_BUILD_PLATFORM_X11) add_subdirectory(x11) endif() -if (MIR_BUILD_PLATFORM_VIRTUAL) - add_subdirectory(virtual) -endif () +add_subdirectory(virtual) set(UNIT_TEST_SOURCES ${UNIT_TEST_SOURCES} From 26481f2333b5193fdc88448b90b0d97608ce9a06 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Fri, 29 Sep 2023 15:52:40 -0400 Subject: [PATCH 09/51] Remove probe_rendering_platform --- src/platforms/virtual/platform_symbols.cpp | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/platforms/virtual/platform_symbols.cpp b/src/platforms/virtual/platform_symbols.cpp index 7618ca3facb..f5a1b91297e 100644 --- a/src/platforms/virtual/platform_symbols.cpp +++ b/src/platforms/virtual/platform_symbols.cpp @@ -80,23 +80,6 @@ auto probe_display_platform( return result; } -auto probe_rendering_platform( - std::span> const&, - mir::ConsoleServices&, - std::shared_ptr const&, - mir::options::ProgramOption const&) -> std::vector -{ - mir::assert_entry_point_signature(&probe_rendering_platform); - std::vector result; - result.emplace_back( - mg::SupportedDevice { - nullptr, - mg::PlatformPriority::supported, - nullptr - }); - return result; -} - mir::ModuleProperties const* describe_graphics_module() { mir::assert_entry_point_signature(&describe_graphics_module); From 69cb1e86796b082d5a5fa20b3059d663f59673c6 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Fri, 29 Sep 2023 15:53:17 -0400 Subject: [PATCH 10/51] Revert accidental change to X11 cmake file --- src/platforms/x11/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/x11/CMakeLists.txt b/src/platforms/x11/CMakeLists.txt index ec74f843b63..a7bc2fe09b0 100644 --- a/src/platforms/x11/CMakeLists.txt +++ b/src/platforms/x11/CMakeLists.txt @@ -28,7 +28,6 @@ target_link_libraries( mirplatformserverx11 PRIVATE mirplatform - server_platform_common PkgConfig::EGL PkgConfig::GLESv2 PkgConfig::XCB @@ -40,6 +39,7 @@ target_link_libraries( xkbcommon-x11 X11 X11-xcb + server_platform_common Boost::program_options ) From a69584d696722f0d0d5c691d7438c4dc57c497ac Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Fri, 29 Sep 2023 16:12:36 -0400 Subject: [PATCH 11/51] Removing unnecessary library linkages --- src/platforms/x11/graphics/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/platforms/x11/graphics/CMakeLists.txt b/src/platforms/x11/graphics/CMakeLists.txt index 69ff9ae07fc..25ae3708128 100644 --- a/src/platforms/x11/graphics/CMakeLists.txt +++ b/src/platforms/x11/graphics/CMakeLists.txt @@ -23,7 +23,6 @@ target_link_libraries(mirplatformgraphicsx11objects-symbols mirplatform mircommon mircore - server_platform_common ) target_link_libraries( @@ -31,5 +30,4 @@ target_link_libraries( PRIVATE mirplatform - server_platform_common ) From a74f6d6169652f69e13cc2ed413a7ae412477611 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Fri, 29 Sep 2023 16:13:20 -0400 Subject: [PATCH 12/51] Removing an unnecessary include --- src/platforms/x11/graphics/platform.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/platforms/x11/graphics/platform.cpp b/src/platforms/x11/graphics/platform.cpp index 26e94b24512..77f010471d2 100644 --- a/src/platforms/x11/graphics/platform.cpp +++ b/src/platforms/x11/graphics/platform.cpp @@ -22,7 +22,6 @@ #include "mir/graphics/platform.h" #include "mir/options/option.h" #include "options_parsing_helpers.h" -#include "shm_buffer.h" #include @@ -34,7 +33,6 @@ namespace { auto parse_scale(std::string const& str) -> float { - mg::common::MappableBackedShmBuffer x(nullptr, nullptr); try { size_t num_end = 0; From 49326140f26f93cfcc843aff5271be51d4e7ad92 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Fri, 29 Sep 2023 16:14:26 -0400 Subject: [PATCH 13/51] Removing unnecessary x11-input linking --- src/platforms/x11/input/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/platforms/x11/input/CMakeLists.txt b/src/platforms/x11/input/CMakeLists.txt index 5bb5c84cbd3..f2c092907c7 100644 --- a/src/platforms/x11/input/CMakeLists.txt +++ b/src/platforms/x11/input/CMakeLists.txt @@ -14,7 +14,6 @@ target_link_libraries(mirplatforminputx11objects mirplatform mircommon mircore - server_platform_common ) add_library( @@ -27,5 +26,4 @@ target_link_libraries(mirplatforminputx11objects-symbols PUBLIC mirplatform mircommon - server_platform_common ) From e7195d53437e939dd32ff2cc33f363617d355e84 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Mon, 2 Oct 2023 09:50:16 -0400 Subject: [PATCH 14/51] Narrowing down where the possible cmake error might be --- tests/unit-tests/platforms/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit-tests/platforms/CMakeLists.txt b/tests/unit-tests/platforms/CMakeLists.txt index 582c886726a..4b63ea68b17 100644 --- a/tests/unit-tests/platforms/CMakeLists.txt +++ b/tests/unit-tests/platforms/CMakeLists.txt @@ -10,7 +10,7 @@ if (MIR_BUILD_PLATFORM_X11) add_subdirectory(x11) endif() -add_subdirectory(virtual) +#add_subdirectory(virtual) set(UNIT_TEST_SOURCES ${UNIT_TEST_SOURCES} From e830a2818fb379b2dd6a0c2412bf7bbc5e8c92c4 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Mon, 2 Oct 2023 10:25:15 -0400 Subject: [PATCH 15/51] Revert "Narrowing down where the possible cmake error might be" This reverts commit 6d7b5e18d6f0ed76b23ad1c01eb83538587c0c65. --- tests/unit-tests/platforms/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit-tests/platforms/CMakeLists.txt b/tests/unit-tests/platforms/CMakeLists.txt index 4b63ea68b17..582c886726a 100644 --- a/tests/unit-tests/platforms/CMakeLists.txt +++ b/tests/unit-tests/platforms/CMakeLists.txt @@ -10,7 +10,7 @@ if (MIR_BUILD_PLATFORM_X11) add_subdirectory(x11) endif() -#add_subdirectory(virtual) +add_subdirectory(virtual) set(UNIT_TEST_SOURCES ${UNIT_TEST_SOURCES} From 92e560aa5e2e5d1675b1457035112094fd7823a4 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Mon, 2 Oct 2023 11:04:40 -0400 Subject: [PATCH 16/51] Stricly creating an egl_display once for StubGenericEGLDisplayProvider --- src/platforms/virtual/platform.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/platforms/virtual/platform.cpp b/src/platforms/virtual/platform.cpp index e636015aa82..1416e65a36c 100644 --- a/src/platforms/virtual/platform.cpp +++ b/src/platforms/virtual/platform.cpp @@ -40,11 +40,14 @@ class mgv::Platform::VirtualDisplayInterfaceProvider : public mg::DisplayInterfa public: auto get_egl_display() -> EGLDisplay override { - auto eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); - EGLint major, minor; - if (eglInitialize(eglDisplay, &major, &minor) == EGL_FALSE) - BOOST_THROW_EXCEPTION(std::runtime_error("Failed to initialize EGL display")); - return eglDisplay; + if (egl_display == nullptr) + { + egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); + EGLint major, minor; + if (eglInitialize(egl_display, &major, &minor) == EGL_FALSE) + BOOST_THROW_EXCEPTION(std::runtime_error("Failed to initialize EGL display")); + } + return egl_display; } class StubEGLFramebuffer : public EGLFramebuffer @@ -68,6 +71,9 @@ class mgv::Platform::VirtualDisplayInterfaceProvider : public mg::DisplayInterfa { return std::make_unique(); } + + private: + EGLDisplay egl_display = nullptr; }; if (dynamic_cast(&type_tag)) From 4ca6049aae9b3c237ffe8974e78cbf1116be978b Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Mon, 2 Oct 2023 15:46:42 -0400 Subject: [PATCH 17/51] Providing the Virtual platform with a VirtualInputPlatform so that it doesn't accidentally get evdev events --- src/platforms/virtual/CMakeLists.txt | 52 ++++++--------- src/platforms/virtual/graphics/CMakeLists.txt | 31 +++++++++ .../virtual/{ => graphics}/display.cpp | 4 +- .../virtual/{ => graphics}/display.h | 0 .../{ => graphics}/display_configuration.cpp | 0 .../{ => graphics}/display_configuration.h | 0 .../graphics.cpp} | 0 .../virtual/{ => graphics}/platform.cpp | 12 ++-- .../virtual/{ => graphics}/platform.h | 0 src/platforms/virtual/input/CMakeLists.txt | 28 ++++++++ src/platforms/virtual/input/input.cpp | 66 +++++++++++++++++++ .../virtual/input/input_platform.cpp | 46 +++++++++++++ src/platforms/virtual/input/input_platform.h | 48 ++++++++++++++ src/platforms/virtual/symbols.map.in | 10 ++- .../input/event_filter_chain_dispatcher.cpp | 2 + .../platforms/virtual/CMakeLists.txt | 2 +- 16 files changed, 258 insertions(+), 43 deletions(-) create mode 100644 src/platforms/virtual/graphics/CMakeLists.txt rename src/platforms/virtual/{ => graphics}/display.cpp (97%) rename src/platforms/virtual/{ => graphics}/display.h (100%) rename src/platforms/virtual/{ => graphics}/display_configuration.cpp (100%) rename src/platforms/virtual/{ => graphics}/display_configuration.h (100%) rename src/platforms/virtual/{platform_symbols.cpp => graphics/graphics.cpp} (100%) rename src/platforms/virtual/{ => graphics}/platform.cpp (89%) rename src/platforms/virtual/{ => graphics}/platform.h (100%) create mode 100644 src/platforms/virtual/input/CMakeLists.txt create mode 100644 src/platforms/virtual/input/input.cpp create mode 100644 src/platforms/virtual/input/input_platform.cpp create mode 100644 src/platforms/virtual/input/input_platform.h diff --git a/src/platforms/virtual/CMakeLists.txt b/src/platforms/virtual/CMakeLists.txt index 43877264b61..104be53493a 100644 --- a/src/platforms/virtual/CMakeLists.txt +++ b/src/platforms/virtual/CMakeLists.txt @@ -1,43 +1,33 @@ -add_library(mirplatformvirtual-graphics STATIC - platform.cpp platform.h - display.cpp display.h - display_configuration.cpp display_configuration.h -) - -target_include_directories(mirplatformvirtual-graphics - PUBLIC - ${server_common_include_dirs} -) +add_subdirectory(graphics/) +add_subdirectory(input/) -target_link_libraries(mirplatformvirtual-graphics - PUBLIC - mirplatform - server_platform_common -) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/symbols.map.in + ${CMAKE_CURRENT_BINARY_DIR}/symbols.map) +set(symbol_map ${CMAKE_CURRENT_BINARY_DIR}/symbols.map) add_library(mirplatformvirtual MODULE - platform_symbols.cpp + $ + $ + $ + $ ) -target_link_libraries(mirplatformvirtual - PRIVATE - mirplatformvirtual-graphics -) -configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/symbols.map.in - ${CMAKE_CURRENT_BINARY_DIR}/symbols.map +target_link_libraries( + mirplatformvirtual + PRIVATE + mirplatform + server_platform_common ) -set(symbol_map ${CMAKE_CURRENT_BINARY_DIR}/symbols.map) set_target_properties( - mirplatformvirtual PROPERTIES - OUTPUT_NAME graphics-virtual - LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/server-modules - PREFIX "" - SUFFIX ".so.${MIR_SERVER_GRAPHICS_PLATFORM_ABI}" - LINK_FLAGS "-Wl,--exclude-libs=ALL -Wl,--version-script,${symbol_map}" - LINK_DEPENDS ${symbol_map} + mirplatformvirtual PROPERTIES + OUTPUT_NAME server-virtual + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/server-modules + PREFIX "" + SUFFIX ".so.${MIR_SERVER_GRAPHICS_PLATFORM_ABI}" + LINK_FLAGS "-Wl,--exclude-libs=ALL -Wl,--version-script,${symbol_map}" + LINK_DEPENDS ${symbol_map} ) install(TARGETS mirplatformvirtual LIBRARY DESTINATION ${MIR_SERVER_PLATFORM_PATH}) diff --git a/src/platforms/virtual/graphics/CMakeLists.txt b/src/platforms/virtual/graphics/CMakeLists.txt new file mode 100644 index 00000000000..16ae38dce8d --- /dev/null +++ b/src/platforms/virtual/graphics/CMakeLists.txt @@ -0,0 +1,31 @@ +include_directories( + ${server_common_include_dirs} +) + +add_library( + mirplatformgraphicsvirtualobjects OBJECT + + platform.cpp + display.cpp + display_configuration.cpp +) + +add_library( + mirplatformgraphicsvirtualobjects-symbols OBJECT + + graphics.cpp +) + +target_link_libraries(mirplatformgraphicsvirtualobjects-symbols + PUBLIC + mirplatform + mircommon + mircore +) + +target_link_libraries( + mirplatformgraphicsvirtualobjects + + PRIVATE + mirplatform +) diff --git a/src/platforms/virtual/display.cpp b/src/platforms/virtual/graphics/display.cpp similarity index 97% rename from src/platforms/virtual/display.cpp rename to src/platforms/virtual/graphics/display.cpp index 05637d1a607..d10d909f2a4 100644 --- a/src/platforms/virtual/display.cpp +++ b/src/platforms/virtual/graphics/display.cpp @@ -44,7 +44,7 @@ std::unique_ptr mgv::Display::configuration() const bool mgv::Display::apply_if_configuration_preserves_display_buffers( const mir::graphics::DisplayConfiguration &) { - return false; + return true; } void mgv::Display::configure(mir::graphics::DisplayConfiguration const&) @@ -67,5 +67,5 @@ void mgv::Display::resume() std::shared_ptr mgv::Display::create_hardware_cursor() { - return std::shared_ptr(); + return nullptr; } diff --git a/src/platforms/virtual/display.h b/src/platforms/virtual/graphics/display.h similarity index 100% rename from src/platforms/virtual/display.h rename to src/platforms/virtual/graphics/display.h diff --git a/src/platforms/virtual/display_configuration.cpp b/src/platforms/virtual/graphics/display_configuration.cpp similarity index 100% rename from src/platforms/virtual/display_configuration.cpp rename to src/platforms/virtual/graphics/display_configuration.cpp diff --git a/src/platforms/virtual/display_configuration.h b/src/platforms/virtual/graphics/display_configuration.h similarity index 100% rename from src/platforms/virtual/display_configuration.h rename to src/platforms/virtual/graphics/display_configuration.h diff --git a/src/platforms/virtual/platform_symbols.cpp b/src/platforms/virtual/graphics/graphics.cpp similarity index 100% rename from src/platforms/virtual/platform_symbols.cpp rename to src/platforms/virtual/graphics/graphics.cpp diff --git a/src/platforms/virtual/platform.cpp b/src/platforms/virtual/graphics/platform.cpp similarity index 89% rename from src/platforms/virtual/platform.cpp rename to src/platforms/virtual/graphics/platform.cpp index 1416e65a36c..99488672872 100644 --- a/src/platforms/virtual/platform.cpp +++ b/src/platforms/virtual/graphics/platform.cpp @@ -40,13 +40,10 @@ class mgv::Platform::VirtualDisplayInterfaceProvider : public mg::DisplayInterfa public: auto get_egl_display() -> EGLDisplay override { - if (egl_display == nullptr) - { - egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); - EGLint major, minor; - if (eglInitialize(egl_display, &major, &minor) == EGL_FALSE) - BOOST_THROW_EXCEPTION(std::runtime_error("Failed to initialize EGL display")); - } + auto egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); + EGLint major, minor; + if (eglInitialize(egl_display, &major, &minor) == EGL_FALSE) + BOOST_THROW_EXCEPTION(std::runtime_error("Failed to initialize EGL display")); return egl_display; } @@ -73,7 +70,6 @@ class mgv::Platform::VirtualDisplayInterfaceProvider : public mg::DisplayInterfa } private: - EGLDisplay egl_display = nullptr; }; if (dynamic_cast(&type_tag)) diff --git a/src/platforms/virtual/platform.h b/src/platforms/virtual/graphics/platform.h similarity index 100% rename from src/platforms/virtual/platform.h rename to src/platforms/virtual/graphics/platform.h diff --git a/src/platforms/virtual/input/CMakeLists.txt b/src/platforms/virtual/input/CMakeLists.txt new file mode 100644 index 00000000000..2f12f011c73 --- /dev/null +++ b/src/platforms/virtual/input/CMakeLists.txt @@ -0,0 +1,28 @@ +include_directories( + ${server_common_include_dirs} +) + +add_library( + mirplatforminputvirtualobjects OBJECT + + input_platform.cpp +) + +target_link_libraries(mirplatforminputvirtualobjects + PUBLIC + mirplatform + mircommon + mircore +) + +add_library( + mirplatforminputvirtualobjects-symbols OBJECT + + input.cpp +) + +target_link_libraries(mirplatforminputvirtualobjects-symbols + PUBLIC + mirplatform + mircommon +) diff --git a/src/platforms/virtual/input/input.cpp b/src/platforms/virtual/input/input.cpp new file mode 100644 index 00000000000..95bd2337ebd --- /dev/null +++ b/src/platforms/virtual/input/input.cpp @@ -0,0 +1,66 @@ +/* + * Copyright © Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 or 3, + * as published by the Free Software Foundation. + * + * 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 "input_platform.h" +#include "mir/module_properties.h" +#include "mir/assert_module_entry_point.h" +#include "mir/libname.h" + +namespace mo = mir::options; +namespace mi = mir::input; +namespace miv = mir::input::virt; + +mir::UniqueModulePtr create_input_platform( + mo::Option const& /*options*/, + std::shared_ptr const& /*emergency_cleanup_registry*/, + std::shared_ptr const& /*input_device_registry*/, + std::shared_ptr const& /*console*/, + std::shared_ptr const& /*report*/) +{ + mir::assert_entry_point_signature(&create_input_platform); + return mir::make_module_ptr(); +} + +void add_input_platform_options( + boost::program_options::options_description& /*config*/) +{ + mir::assert_entry_point_signature(&add_input_platform_options); +} + +mi::PlatformPriority probe_input_platform( + mo::Option const& /*options*/, + mir::ConsoleServices&) +{ + mir::assert_entry_point_signature(&probe_input_platform); + return mi::PlatformPriority::supported; +} + +namespace +{ +mir::ModuleProperties const description = { + "mir:virt-input", + MIR_VERSION_MAJOR, + MIR_VERSION_MINOR, + MIR_VERSION_MICRO, + mir::libname() +}; +} + +mir::ModuleProperties const* describe_input_module() +{ + mir::assert_entry_point_signature(&describe_input_module); + return &description; +} diff --git a/src/platforms/virtual/input/input_platform.cpp b/src/platforms/virtual/input/input_platform.cpp new file mode 100644 index 00000000000..3f3f8745dd9 --- /dev/null +++ b/src/platforms/virtual/input/input_platform.cpp @@ -0,0 +1,46 @@ +/* + * Copyright © Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 2 or 3, + * as published by the Free Software Foundation. + * + * 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include "input_platform.h" +#include + +namespace mi = mir::input; +namespace miv = mir::input::virt; + +miv::VirtualInputPlatform::VirtualInputPlatform() +{ +} + +std::shared_ptr miv::VirtualInputPlatform::dispatchable() +{ + return std::make_shared(); +} + +void miv::VirtualInputPlatform::start() +{ +} + +void miv::VirtualInputPlatform::stop() +{ +} + +void miv::VirtualInputPlatform::pause_for_config() +{ +} + +void miv::VirtualInputPlatform::continue_after_config() +{ +} \ No newline at end of file diff --git a/src/platforms/virtual/input/input_platform.h b/src/platforms/virtual/input/input_platform.h new file mode 100644 index 00000000000..e9f33ee6fac --- /dev/null +++ b/src/platforms/virtual/input/input_platform.h @@ -0,0 +1,48 @@ +/* + * Copyright © Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 2 or 3, + * as published by the Free Software Foundation. + * + * 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + + +#ifndef MIR_GRAPHICS_VIRTUAL_INPUT_PLATFORM_H_ +#define MIR_GRAPHICS_VIRTUAL_INPUT_PLATFORM_H_ + +#include "mir/input/platform.h" + +namespace mir +{ +namespace input +{ +namespace virt +{ + +/// Serves as a pass-through platform so that the virtual input platform +/// does not default to evdev (which would lead to funny things, like +/// two inputs being registered when using a VNC on localhost) +class VirtualInputPlatform : public input::Platform +{ +public: + VirtualInputPlatform(); + std::shared_ptr dispatchable() override; + void start() override; + void stop() override; + void pause_for_config() override; + void continue_after_config() override; +}; + +} +} +} + +#endif //MIR_GRAPHICS_VIRTUAL_INPUT_PLATFORM_H_ diff --git a/src/platforms/virtual/symbols.map.in b/src/platforms/virtual/symbols.map.in index b27888b99be..674d7edc237 100644 --- a/src/platforms/virtual/symbols.map.in +++ b/src/platforms/virtual/symbols.map.in @@ -6,4 +6,12 @@ describe_graphics_module; local: *; -}; \ No newline at end of file +}; + +@MIR_SERVER_INPUT_PLATFORM_VERSION@ { + global: + add_input_platform_options; + create_input_platform; + probe_input_platform; + describe_input_module; +}; diff --git a/src/server/input/event_filter_chain_dispatcher.cpp b/src/server/input/event_filter_chain_dispatcher.cpp index 73b90e1b393..724afac60e0 100644 --- a/src/server/input/event_filter_chain_dispatcher.cpp +++ b/src/server/input/event_filter_chain_dispatcher.cpp @@ -32,6 +32,7 @@ bool mi::EventFilterChainDispatcher::handle(MirEvent const& event) std::lock_guard lg(filter_guard); auto it = filters.begin(); + int idx = 0; while (it != filters.end()) { auto filter = (*it).lock(); @@ -42,6 +43,7 @@ bool mi::EventFilterChainDispatcher::handle(MirEvent const& event) } if (filter->handle(event)) return true; ++it; + idx++; } return false; } diff --git a/tests/unit-tests/platforms/virtual/CMakeLists.txt b/tests/unit-tests/platforms/virtual/CMakeLists.txt index 339a70c07f7..d85f073bd26 100644 --- a/tests/unit-tests/platforms/virtual/CMakeLists.txt +++ b/tests/unit-tests/platforms/virtual/CMakeLists.txt @@ -1,7 +1,7 @@ mir_add_wrapped_executable(mir_unit_tests_virtual NOINSTALL ${CMAKE_CURRENT_SOURCE_DIR}/test_platform.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_display.cpp - $ + $ $ # Sub-optimal. We really want to link a lib ) From 5ad522b08a471918bd0d9535419098de9af32ae2 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Mon, 2 Oct 2023 18:03:12 -0400 Subject: [PATCH 18/51] Improved coe-sharing between X11 and virtual platforms --- .../common/server/options_parsing_helpers.cpp | 47 ++++++++++++++++++- .../common/server/options_parsing_helpers.h | 3 +- src/platforms/virtual/graphics/platform.cpp | 2 +- src/platforms/virtual/graphics/platform.h | 4 ++ src/platforms/x11/graphics/platform.cpp | 40 +--------------- .../platforms/virtual/CMakeLists.txt | 3 +- .../platforms/virtual/test_display.cpp | 4 +- .../platforms/virtual/test_platform.cpp | 44 +++++++---------- 8 files changed, 76 insertions(+), 71 deletions(-) diff --git a/src/platforms/common/server/options_parsing_helpers.cpp b/src/platforms/common/server/options_parsing_helpers.cpp index 5db5da682eb..a42f7594832 100644 --- a/src/platforms/common/server/options_parsing_helpers.cpp +++ b/src/platforms/common/server/options_parsing_helpers.cpp @@ -21,7 +21,31 @@ namespace mgc = mir::graphics::common; namespace geom = mir::geometry; -auto mgc::parse_size_dimension(std::string const& str) -> int +namespace +{ +auto parse_scale(std::string const& str) -> float +{ + try + { + size_t num_end = 0; + float const value = std::stof(str, &num_end); + if (num_end != str.size()) + BOOST_THROW_EXCEPTION(std::runtime_error("Scale \"" + str + "\" is not a valid float")); + if (value <= 0.000001) + BOOST_THROW_EXCEPTION(std::runtime_error("Scale must be greater than zero")); + return value; + } + catch (std::invalid_argument const &) + { + BOOST_THROW_EXCEPTION(std::runtime_error("Scale \"" + str + "\" is not a valid float")); + } + catch (std::out_of_range const &) + { + BOOST_THROW_EXCEPTION(std::runtime_error("Scale \"" + str + "\" is out of range")); + } +} + +auto parse_size_dimension(std::string const& str) -> int { try { @@ -42,6 +66,8 @@ auto mgc::parse_size_dimension(std::string const& str) -> int BOOST_THROW_EXCEPTION(std::runtime_error("Output dimension \"" + str + "\" is out of range")); } } +} + auto mgc::parse_size(std::string const& str) -> geom::Size { @@ -51,4 +77,23 @@ auto mgc::parse_size(std::string const& str) -> geom::Size return geom::Size{ parse_size_dimension(str.substr(0, x)), parse_size_dimension(str.substr(x + 1))}; +} + +auto mgc::parse_size_with_scale(std::string const& str) -> std::tuple +{ + auto const x = str.find('x'); // "x" between width and height + if (x == std::string::npos || x <= 0 || x >= str.size() - 1) + BOOST_THROW_EXCEPTION(std::runtime_error("Output size \"" + str + "\" does not have two dimensions")); + auto const scale_start = str.find('^'); // start of output scale + float scale = 1.0f; + if (scale_start != std::string::npos) + { + if (scale_start >= str.size() - 1) + BOOST_THROW_EXCEPTION(std::runtime_error("In \"" + str + "\", '^' is not followed by a scale")); + scale = parse_scale(str.substr(scale_start + 1, std::string::npos)); + } + return {geom::Size{ + parse_size_dimension(str.substr(0, x)), + parse_size_dimension(str.substr(x + 1, scale_start - x - 1))}, + scale}; } \ No newline at end of file diff --git a/src/platforms/common/server/options_parsing_helpers.h b/src/platforms/common/server/options_parsing_helpers.h index 75332df01c2..2841d69b4ed 100644 --- a/src/platforms/common/server/options_parsing_helpers.h +++ b/src/platforms/common/server/options_parsing_helpers.h @@ -18,6 +18,7 @@ #define MIR_PLATFORM_OPTIONS_PARSING_HELPERS_H #include +#include #include namespace mir @@ -28,7 +29,7 @@ namespace common { auto parse_size(std::string const& str) -> mir::geometry::Size; -auto parse_size_dimension(std::string const& str) -> int; +auto parse_size_with_scale(std::string const& str) -> std::tuple; } } diff --git a/src/platforms/virtual/graphics/platform.cpp b/src/platforms/virtual/graphics/platform.cpp index 99488672872..0f0e0ac4982 100644 --- a/src/platforms/virtual/graphics/platform.cpp +++ b/src/platforms/virtual/graphics/platform.cpp @@ -33,7 +33,7 @@ class mgv::Platform::VirtualDisplayInterfaceProvider : public mg::DisplayInterfa protected: auto maybe_create_interface(mg::DisplayInterfaceBase::Tag const& type_tag) - -> std::shared_ptr + -> std::shared_ptr { class StubGenericEGLDisplayProvider : public GenericEGLDisplayProvider { diff --git a/src/platforms/virtual/graphics/platform.h b/src/platforms/virtual/graphics/platform.h index a8114129513..a393c9ce7f6 100644 --- a/src/platforms/virtual/graphics/platform.h +++ b/src/platforms/virtual/graphics/platform.h @@ -36,6 +36,10 @@ struct VirtualOutputConfig { } + bool operator==(VirtualOutputConfig const& output) const + { + return sizes == output.sizes; + } std::vector sizes; }; diff --git a/src/platforms/x11/graphics/platform.cpp b/src/platforms/x11/graphics/platform.cpp index 77f010471d2..9174628b53e 100644 --- a/src/platforms/x11/graphics/platform.cpp +++ b/src/platforms/x11/graphics/platform.cpp @@ -31,46 +31,10 @@ namespace geom = mir::geometry; namespace { -auto parse_scale(std::string const& str) -> float -{ - try - { - size_t num_end = 0; - float const value = std::stof(str, &num_end); - if (num_end != str.size()) - BOOST_THROW_EXCEPTION(std::runtime_error("Scale \"" + str + "\" is not a valid float")); - if (value <= 0.000001) - BOOST_THROW_EXCEPTION(std::runtime_error("Scale must be greater than zero")); - return value; - } - catch (std::invalid_argument const &) - { - BOOST_THROW_EXCEPTION(std::runtime_error("Scale \"" + str + "\" is not a valid float")); - } - catch (std::out_of_range const &) - { - BOOST_THROW_EXCEPTION(std::runtime_error("Scale \"" + str + "\" is out of range")); - } -} - auto parse_size(std::string const& str) -> mgx::X11OutputConfig { - auto const x = str.find('x'); // "x" between width and height - if (x == std::string::npos || x <= 0 || x >= str.size() - 1) - BOOST_THROW_EXCEPTION(std::runtime_error("Output size \"" + str + "\" does not have two dimensions")); - auto const scale_start = str.find('^'); // start of output scale - float scale = 1.0f; - if (scale_start != std::string::npos) - { - if (scale_start >= str.size() - 1) - BOOST_THROW_EXCEPTION(std::runtime_error("In \"" + str + "\", '^' is not followed by a scale")); - scale = parse_scale(str.substr(scale_start + 1, std::string::npos)); - } - return mgx::X11OutputConfig{ - geom::Size{ - mir::graphics::common::parse_size_dimension(str.substr(0, x)), - mir::graphics::common::parse_size_dimension(str.substr(x + 1, scale_start - x - 1))}, - scale}; + auto parsed = mir::graphics::common::parse_size_with_scale(str); + return mgx::X11OutputConfig{std::get<0>(parsed), std::get<1>(parsed)}; } } diff --git a/tests/unit-tests/platforms/virtual/CMakeLists.txt b/tests/unit-tests/platforms/virtual/CMakeLists.txt index d85f073bd26..e2479f0ea24 100644 --- a/tests/unit-tests/platforms/virtual/CMakeLists.txt +++ b/tests/unit-tests/platforms/virtual/CMakeLists.txt @@ -1,7 +1,8 @@ mir_add_wrapped_executable(mir_unit_tests_virtual NOINSTALL ${CMAKE_CURRENT_SOURCE_DIR}/test_platform.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_display.cpp - $ + $ + $ $ # Sub-optimal. We really want to link a lib ) diff --git a/tests/unit-tests/platforms/virtual/test_display.cpp b/tests/unit-tests/platforms/virtual/test_display.cpp index 47fc524a5a6..a514ba76cb2 100644 --- a/tests/unit-tests/platforms/virtual/test_display.cpp +++ b/tests/unit-tests/platforms/virtual/test_display.cpp @@ -17,8 +17,8 @@ #include #include -#include "src/platforms/virtual/display.h" -#include "src/platforms/virtual/platform.h" +#include "src/platforms/virtual/graphics/display.h" +#include "src/platforms/virtual/graphics/platform.h" #include "mir/graphics/display_configuration.h" diff --git a/tests/unit-tests/platforms/virtual/test_platform.cpp b/tests/unit-tests/platforms/virtual/test_platform.cpp index 59c6228a95e..e323913b82e 100644 --- a/tests/unit-tests/platforms/virtual/test_platform.cpp +++ b/tests/unit-tests/platforms/virtual/test_platform.cpp @@ -18,11 +18,9 @@ #include #include "mir/graphics/platform.h" -#include "mir/options/program_option.h" -#include "src/platforms/virtual/platform.h" +#include "src/platforms/virtual/graphics/platform.h" #include "mir/shared_library.h" -#include "mir_test_framework/executable_path.h" #include "src/server/report/null/display_report.h" namespace mg = mir::graphics; @@ -45,43 +43,35 @@ class VirtualGraphicsPlatformTest : public ::testing::Test } }; -TEST_F(VirtualGraphicsPlatformTest, has_one_config_when_provided_one_output_size) -{ - auto configs = mgv::Platform::parse_output_sizes({"1280x1024"}); - EXPECT_THAT(configs.size(), Eq(1)); -} - TEST_F(VirtualGraphicsPlatformTest, lone_config_has_one_output_size_when_provided_one_output_size) { auto configs = mgv::Platform::parse_output_sizes({"1280x1024"}); - EXPECT_THAT(configs[0].sizes.size(), Eq(1)); + EXPECT_THAT(configs, ElementsAre( + mgv::VirtualOutputConfig(std::vector{{1280, 1024}}))); } -TEST_F(VirtualGraphicsPlatformTest, lone_output_size_has_size_provided_by_string) -{ - auto configs = mgv::Platform::parse_output_sizes({"1280x1024"}); - EXPECT_THAT(configs[0].sizes, ElementsAre(geom::Size{1280, 1024})); -} - -TEST_F(VirtualGraphicsPlatformTest, multiple_output_sizes_are_read_when_multiple_are_provided) +TEST_F(VirtualGraphicsPlatformTest, multiple_output_sizes_are_set_correctly_when_multiple_are_provided) { auto configs = mgv::Platform::parse_output_sizes({"1280x1024:800x600"}); - EXPECT_THAT(configs[0].sizes.size(), Eq(2)); + EXPECT_THAT(configs, ElementsAre( + mgv::VirtualOutputConfig(std::vector{geom::Size{1280, 1024}}), + mgv::VirtualOutputConfig(std::vector{geom::Size{800, 600}}))); } -TEST_F(VirtualGraphicsPlatformTest, multiple_output_sizes_are_set_correctly_when_multiple_are_provided) +TEST_F(VirtualGraphicsPlatformTest, can_acquire_interface_for_generic_egl_display_provider) { - auto configs = mgv::Platform::parse_output_sizes({"1280x1024:800x600"}); - EXPECT_THAT(configs[0].sizes, ElementsAre( - geom::Size{1280, 1024}, - geom::Size{800, 600})); + auto platform = create_platform(); + auto interface = mg::DisplayPlatform::interface_for(platform); + EXPECT_TRUE(interface->acquire_interface() != nullptr); } -TEST_F(VirtualGraphicsPlatformTest, multiple_configs_are_parset_when_multiple_strings_are_provided) +TEST_F(VirtualGraphicsPlatformTest, output_size_parsing_throws_on_bad_input) { - auto configs = mgv::Platform::parse_output_sizes({"1280x1024", "800x600"}); - EXPECT_THAT(configs[0].sizes, ElementsAre(geom::Size{1280, 1024})); - EXPECT_THAT(configs[1].sizes, ElementsAre(geom::Size{800, 600})); + // X11's tests check the remaining cases here. These are the only cases that do not overlap with X11's. + using namespace ::testing; + EXPECT_THROW(mgv::Platform::parse_output_sizes({"1280"}), std::runtime_error) << "No height or 'x'"; + EXPECT_THROW(mgv::Platform::parse_output_sizes({"1280x"}), std::runtime_error) << "No height"; + EXPECT_THROW(mgv::Platform::parse_output_sizes({"x1280"}), std::runtime_error) << "No width"; } } \ No newline at end of file From 7c7282ffca3574c7de72e2f53845913c4051d15f Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Tue, 3 Oct 2023 09:17:06 -0400 Subject: [PATCH 19/51] Minor initial pull request feedback --- src/platforms/virtual/graphics/display.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/platforms/virtual/graphics/display.h b/src/platforms/virtual/graphics/display.h index d95ba28a275..a26a7e3a029 100644 --- a/src/platforms/virtual/graphics/display.h +++ b/src/platforms/virtual/graphics/display.h @@ -14,8 +14,8 @@ * along with this program. If not, see . */ -#ifndef MIR_PLATFORMS_VIRTUAL_DISPLAY_H_ -#define MIR_PLATFORMS_VIRTUAL_DISPLAY_H_ +#ifndef MIR_GRAPHICS_VIRT_DISPLAY_H_ +#define MIR_GRAPHICS_VIRT_DISPLAY_H_ #include "platform.h" #include @@ -30,7 +30,7 @@ namespace virt class Display : public mir::graphics::Display { public: - Display(std::vector output_sizes); + explicit Display(std::vector output_sizes); void for_each_display_sync_group(const std::function &f) override; std::unique_ptr configuration() const override; bool apply_if_configuration_preserves_display_buffers(const mir::graphics::DisplayConfiguration &conf) override; @@ -50,4 +50,4 @@ class Display : public mir::graphics::Display } -#endif //MIR_PLATFORMS_VIRTUAL_DISPLAY_H_ +#endif //MIR_GRAPHICS_VIRT_DISPLAY_H_ From e6194da490a49dedcfbe80c722d435e63c53dde3 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Wed, 4 Oct 2023 15:48:50 -0400 Subject: [PATCH 20/51] Missing space in graphics --- src/platforms/virtual/graphics/graphics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/virtual/graphics/graphics.cpp b/src/platforms/virtual/graphics/graphics.cpp index f5a1b91297e..174c2f91e63 100644 --- a/src/platforms/virtual/graphics/graphics.cpp +++ b/src/platforms/virtual/graphics/graphics.cpp @@ -62,7 +62,7 @@ void add_graphics_platform_options(boost::program_options::options_description& ->default_value(std::vector{"1280x1024"}, "1280x1024") ->multitoken(), "[mir-on-virtual specific] Colon separated list of WIDTHxHEIGHT sizes for the \"output\" size." - "Multiple outputs may be specified by providing the argument multiple times."); + " Multiple outputs may be specified by providing the argument multiple times."); } auto probe_display_platform( From b3e4da9a10513452c85dea6033d84fe6861e60bd Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Wed, 4 Oct 2023 15:50:06 -0400 Subject: [PATCH 21/51] Resetting an accidentally changed file --- src/server/input/event_filter_chain_dispatcher.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/server/input/event_filter_chain_dispatcher.cpp b/src/server/input/event_filter_chain_dispatcher.cpp index 724afac60e0..73b90e1b393 100644 --- a/src/server/input/event_filter_chain_dispatcher.cpp +++ b/src/server/input/event_filter_chain_dispatcher.cpp @@ -32,7 +32,6 @@ bool mi::EventFilterChainDispatcher::handle(MirEvent const& event) std::lock_guard lg(filter_guard); auto it = filters.begin(); - int idx = 0; while (it != filters.end()) { auto filter = (*it).lock(); @@ -43,7 +42,6 @@ bool mi::EventFilterChainDispatcher::handle(MirEvent const& event) } if (filter->handle(event)) return true; ++it; - idx++; } return false; } From 2e3b08a19efbb8254b5c009226a4df8203663d6d Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Tue, 10 Oct 2023 15:56:25 -0400 Subject: [PATCH 22/51] Bandaid fix for unit tests --- tests/unit-tests/input/CMakeLists.txt | 2 ++ .../input/test_input_platform_probing.cpp | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/unit-tests/input/CMakeLists.txt b/tests/unit-tests/input/CMakeLists.txt index 756e47d77a2..d22f106eafc 100644 --- a/tests/unit-tests/input/CMakeLists.txt +++ b/tests/unit-tests/input/CMakeLists.txt @@ -25,7 +25,9 @@ list(APPEND UMOCK_UNIT_TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/test_input_platform_probing.cpp $ $ + $ ) + if (MIR_BUILD_PLATFORM_X11) list(APPEND UMOCK_UNIT_TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/test_x11_platform.cpp diff --git a/tests/unit-tests/input/test_input_platform_probing.cpp b/tests/unit-tests/input/test_input_platform_probing.cpp index a350003e6f0..c28c9ff49cb 100644 --- a/tests/unit-tests/input/test_input_platform_probing.cpp +++ b/tests/unit-tests/input/test_input_platform_probing.cpp @@ -32,6 +32,7 @@ #include "mir/test/doubles/mock_input_device_registry.h" #include "src/platforms/evdev/platform.h" #include "src/platforms/x11/input/input_platform.h" +#include "src/platforms/virtual/input/input_platform.h" #include "mir/test/fake_shared.h" namespace mt = mir::test; @@ -51,6 +52,7 @@ struct StubEmergencyCleanupRegistry : mir::EmergencyCleanupRegistry }; char const platform_input_lib[] = "platform-input-lib"; char const platform_path[] = "platform-path"; +char const platform_display_libs[] = "platform-display-libs"; struct InputPlatformProbe : ::testing::Test { @@ -58,6 +60,7 @@ struct InputPlatformProbe : ::testing::Test { ON_CALL(mock_options, is_set(StrEq(platform_input_lib))).WillByDefault(Return(false)); ON_CALL(mock_options, is_set(StrEq(platform_path))).WillByDefault(Return(true)); + ON_CALL(mock_options, is_set(StrEq(platform_display_libs))).WillByDefault(Return(true)); ON_CALL(mock_options, get(StrEq(platform_path),Matcher(_))) .WillByDefault(Return(platform_path_value)); ON_CALL(mock_options, get(StrEq(platform_path))) @@ -72,6 +75,12 @@ struct InputPlatformProbe : ::testing::Test { return platform_input_lib_value_as_any; })); + ON_CALL(mock_options, get(StrEq(platform_display_libs_value))) + .WillByDefault(Invoke( + [this](char const*) -> boost::any const& + { + return platform_display_libs_value_as_any; + })); #ifdef MIR_BUILD_PLATFORM_X11 ON_CALL(mock_x11, XGetXCBConnection(_)) .WillByDefault(Return(reinterpret_cast(1))); @@ -101,6 +110,8 @@ struct InputPlatformProbe : ::testing::Test boost::any platform_path_value_as_any{platform_path_value}; std::string platform_input_lib_value; boost::any platform_input_lib_value_as_any; + std::string platform_display_libs_value; + boost::any platform_display_libs_value_as_any; std::vector> const empty_loaded_module_list{}; }; @@ -143,7 +154,7 @@ TEST_F(InputPlatformProbe, stub_platform_not_picked_up_by_default) empty_loaded_module_list, *stub_prober_report); - EXPECT_THAT(platform, OfPtrType()); + EXPECT_THAT(platform, OfPtrType()); } #ifdef MIR_BUILD_PLATFORM_X11 @@ -162,7 +173,7 @@ TEST_F(InputPlatformProbe, x11_input_platform_not_used_when_vt_specified) empty_loaded_module_list, *stub_prober_report); - EXPECT_THAT(platform, OfPtrType()); + EXPECT_THAT(platform, OfPtrType()); } #endif From f386759af4e9ae8ec5872f34fcf49f687877bdfa Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Tue, 10 Oct 2023 16:21:06 -0400 Subject: [PATCH 23/51] Selecting the virtual platform only if a virtual display is up and running, otherwise it is a dummy option --- src/platforms/virtual/graphics/graphics.cpp | 2 +- src/platforms/virtual/graphics/platform.cpp | 16 ++++++++++++++++ src/platforms/virtual/graphics/platform.h | 4 +++- src/platforms/virtual/input/input.cpp | 11 +++++++++-- .../input/test_input_platform_probing.cpp | 4 ++-- 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/platforms/virtual/graphics/graphics.cpp b/src/platforms/virtual/graphics/graphics.cpp index 174c2f91e63..7fdeb872a1d 100644 --- a/src/platforms/virtual/graphics/graphics.cpp +++ b/src/platforms/virtual/graphics/graphics.cpp @@ -74,7 +74,7 @@ auto probe_display_platform( std::vector result; result.push_back({ nullptr, - mg::PlatformPriority::hosted, + mg::PlatformPriority::supported, nullptr }); return result; diff --git a/src/platforms/virtual/graphics/platform.cpp b/src/platforms/virtual/graphics/platform.cpp index 0f0e0ac4982..6823ae34a4a 100644 --- a/src/platforms/virtual/graphics/platform.cpp +++ b/src/platforms/virtual/graphics/platform.cpp @@ -24,6 +24,11 @@ namespace mgv = mir::graphics::virt; namespace geom = mir::geometry; using namespace std::literals; +namespace +{ +mgv::Platform* virtual_platform = nullptr; +} + class mgv::Platform::VirtualDisplayInterfaceProvider : public mg::DisplayInterfaceProvider { public: @@ -87,6 +92,12 @@ mgv::Platform::Platform( provider{std::make_shared()}, outputs{outputs} { + virtual_platform = this; +} + +mgv::Platform::~Platform() +{ + virtual_platform = nullptr; } mir::UniqueModulePtr mgv::Platform::create_display( @@ -118,4 +129,9 @@ auto mgv::Platform::parse_output_sizes(std::vector virtual_outputs) configs.push_back(VirtualOutputConfig(std::move(sizes))); } return configs; +} + +bool mgv::Platform::has_instance() +{ + return virtual_platform != nullptr; } \ No newline at end of file diff --git a/src/platforms/virtual/graphics/platform.h b/src/platforms/virtual/graphics/platform.h index a393c9ce7f6..3685a40e9a3 100644 --- a/src/platforms/virtual/graphics/platform.h +++ b/src/platforms/virtual/graphics/platform.h @@ -50,12 +50,14 @@ class Platform : public graphics::DisplayPlatform Platform( std::shared_ptr const& report, std::vector outputs); - ~Platform() = default; + ~Platform(); UniqueModulePtr create_display( std::shared_ptr const& initial_conf_policy, std::shared_ptr const& gl_config) override; + static bool has_instance(); + protected: auto interface_for() -> std::shared_ptr override; private: diff --git a/src/platforms/virtual/input/input.cpp b/src/platforms/virtual/input/input.cpp index 95bd2337ebd..fa0dccc1b29 100644 --- a/src/platforms/virtual/input/input.cpp +++ b/src/platforms/virtual/input/input.cpp @@ -18,6 +18,8 @@ #include "mir/module_properties.h" #include "mir/assert_module_entry_point.h" #include "mir/libname.h" +#include "mir/options/configuration.h" +#include "../graphics/platform.h" namespace mo = mir::options; namespace mi = mir::input; @@ -41,11 +43,16 @@ void add_input_platform_options( } mi::PlatformPriority probe_input_platform( - mo::Option const& /*options*/, + mo::Option const&, mir::ConsoleServices&) { mir::assert_entry_point_signature(&probe_input_platform); - return mi::PlatformPriority::supported; + if (mir::graphics::virt::Platform::has_instance()) + { + return mi::PlatformPriority::best; + } + + return mi::PlatformPriority::dummy; } namespace diff --git a/tests/unit-tests/input/test_input_platform_probing.cpp b/tests/unit-tests/input/test_input_platform_probing.cpp index c28c9ff49cb..0649f4f8ec8 100644 --- a/tests/unit-tests/input/test_input_platform_probing.cpp +++ b/tests/unit-tests/input/test_input_platform_probing.cpp @@ -154,7 +154,7 @@ TEST_F(InputPlatformProbe, stub_platform_not_picked_up_by_default) empty_loaded_module_list, *stub_prober_report); - EXPECT_THAT(platform, OfPtrType()); + EXPECT_THAT(platform, OfPtrType()); } #ifdef MIR_BUILD_PLATFORM_X11 @@ -173,7 +173,7 @@ TEST_F(InputPlatformProbe, x11_input_platform_not_used_when_vt_specified) empty_loaded_module_list, *stub_prober_report); - EXPECT_THAT(platform, OfPtrType()); + EXPECT_THAT(platform, OfPtrType()); } #endif From 202ad0d885df178271e09eb43754edc9cec0f5ba Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Tue, 10 Oct 2023 16:44:12 -0400 Subject: [PATCH 24/51] Fixing issue with new test --- tests/unit-tests/platforms/virtual/test_platform.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/unit-tests/platforms/virtual/test_platform.cpp b/tests/unit-tests/platforms/virtual/test_platform.cpp index e323913b82e..2645c2e914b 100644 --- a/tests/unit-tests/platforms/virtual/test_platform.cpp +++ b/tests/unit-tests/platforms/virtual/test_platform.cpp @@ -52,10 +52,9 @@ TEST_F(VirtualGraphicsPlatformTest, lone_config_has_one_output_size_when_provide TEST_F(VirtualGraphicsPlatformTest, multiple_output_sizes_are_set_correctly_when_multiple_are_provided) { - auto configs = mgv::Platform::parse_output_sizes({"1280x1024:800x600"}); - EXPECT_THAT(configs, ElementsAre( - mgv::VirtualOutputConfig(std::vector{geom::Size{1280, 1024}}), - mgv::VirtualOutputConfig(std::vector{geom::Size{800, 600}}))); + auto config = mgv::Platform::parse_output_sizes({"1280x1024:800x600"}); + EXPECT_THAT(config, ElementsAre( + mgv::VirtualOutputConfig(std::vector{geom::Size{1280, 1024}, geom::Size{800, 600}}))); } TEST_F(VirtualGraphicsPlatformTest, can_acquire_interface_for_generic_egl_display_provider) From 9a5c81c8cad661ac20784fc7fa1f2d2fdb2dbc6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sawicz=20=28Saviq=29?= Date: Wed, 11 Oct 2023 11:14:29 +0200 Subject: [PATCH 25/51] debian: add virtual platform packaging --- debian/control | 30 +++++++++++++++++++ .../mir-platform-graphics-virtual20.install | 2 ++ 2 files changed, 32 insertions(+) create mode 100644 debian/mir-platform-graphics-virtual20.install diff --git a/debian/control b/debian/control index f0117044346..49f10ed682d 100644 --- a/debian/control +++ b/debian/control @@ -317,6 +317,20 @@ Description: Display server for Ubuntu - generic EGL rendering platform Contains the shared libraries required for the Mir server to provide accelerated client rendering via standard EGL interfaces. +Package: mir-platform-graphics-virtual20 +Section: libs +Architecture: linux-any +Multi-Arch: same +Pre-Depends: ${misc:Pre-Depends} +Depends: ${misc:Depends}, + ${shlibs:Depends}, +Description: Display server for Ubuntu - virtual display platform + Mir is a display server running on linux systems, with a focus on efficiency, + robust operation and a well-defined driver model. + . + Contains the shared libraries required for the Mir server to provide virtual + output support. + Package: mir-graphics-drivers-nvidia Section: libs Architecture: linux-any @@ -325,6 +339,8 @@ Pre-Depends: ${misc:Pre-Depends} Depends: ${misc:Depends}, mir-platform-graphics-eglstream-kms, mir-platform-graphics-x, +Recommends: + mir-platform-graphics-virtual, Description: Display server for Ubuntu - Nvidia driver metapackage Mir is a display server running on linux systems, with a focus on efficiency, robust operation and a well-defined driver model. @@ -354,6 +370,8 @@ Depends: ${misc:Depends}, mir-platform-graphics-gbm-kms, mir-platform-graphics-x, mir-platform-graphics-wayland, +Recommends: + mir-platform-graphics-virtual, Description: Display server for Ubuntu - desktop driver metapackage Mir is a display server running on linux systems, with a focus on efficiency, robust operation and a well-defined driver model. @@ -420,6 +438,18 @@ Description: Display server for Ubuntu - EGL rendering provider metapackage This package depends on the current provider of accelerated client rendering support via standard EGL interfaces. +Package: mir-platform-graphics-virtual +Section: libs +Architecture: linux-any +Multi-Arch: same +Pre-Depends: ${misc:Pre-Depends} +Depends: mir-platform-graphics-virtual20 +Description: Display server for Ubuntu - virtual display provider metapackage + Mir is a display server running on linux systems, with a focus on efficiency, + robust operation and a well-defined driver model. + . + This package depends on the current provider of virtual outputs. + Package: mir-platform-graphics-x Section: libs Architecture: linux-any diff --git a/debian/mir-platform-graphics-virtual20.install b/debian/mir-platform-graphics-virtual20.install new file mode 100644 index 00000000000..9e091404a06 --- /dev/null +++ b/debian/mir-platform-graphics-virtual20.install @@ -0,0 +1,2 @@ +usr/lib/*/mir/server-platform/server-virtual.so.20 + From 381c44b395cb8da6d6385662657acd191d7c5ea6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sawicz=20=28Saviq=29?= Date: Wed, 11 Oct 2023 12:38:17 +0200 Subject: [PATCH 26/51] tools: add new package support --- tools/update_package_abis.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/update_package_abis.sh b/tools/update_package_abis.sh index 98b3a8214c7..22a04b5fd73 100755 --- a/tools/update_package_abis.sh +++ b/tools/update_package_abis.sh @@ -23,7 +23,8 @@ packages="\ mir-platform-input-evdev:MIR_SERVER_INPUT_PLATFORM_ABI\ libmirwayland:MIRWAYLAND_ABI\ mir-platform-graphics-wayland:MIR_SERVER_GRAPHICS_PLATFORM_ABI\ - mir-platform-rendering-egl-generic:MIR_SERVER_GRAPHICS_PLATFORM_ABI" + mir-platform-rendering-egl-generic:MIR_SERVER_GRAPHICS_PLATFORM_ABI\ + mir-platform-graphics-virtual:MIR_SERVER_GRAPHICS_PLATFORM_ABI" package_name() { From 26873dcc0a83b6f29aa75bd946d77f66a74f63c9 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Wed, 11 Oct 2023 09:12:22 -0400 Subject: [PATCH 27/51] Changing the platform name to virtual instead of virt --- src/platforms/virtual/graphics/graphics.cpp | 2 +- src/platforms/virtual/input/input.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platforms/virtual/graphics/graphics.cpp b/src/platforms/virtual/graphics/graphics.cpp index 7fdeb872a1d..5e5d09176d2 100644 --- a/src/platforms/virtual/graphics/graphics.cpp +++ b/src/platforms/virtual/graphics/graphics.cpp @@ -30,7 +30,7 @@ namespace mgv = mir::graphics::virt; namespace { mir::ModuleProperties const description = { - "mir:virt", + "mir:virtual", MIR_VERSION_MAJOR, MIR_VERSION_MINOR, MIR_VERSION_MICRO, diff --git a/src/platforms/virtual/input/input.cpp b/src/platforms/virtual/input/input.cpp index fa0dccc1b29..5c23ca68f17 100644 --- a/src/platforms/virtual/input/input.cpp +++ b/src/platforms/virtual/input/input.cpp @@ -58,7 +58,7 @@ mi::PlatformPriority probe_input_platform( namespace { mir::ModuleProperties const description = { - "mir:virt-input", + "mir:virtual-input", MIR_VERSION_MAJOR, MIR_VERSION_MINOR, MIR_VERSION_MICRO, From dcd1dd8155a49af14f9d241e3f23cf375ef777de Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Wed, 11 Oct 2023 11:04:56 -0400 Subject: [PATCH 28/51] Removing the null input platform that was created without purpose --- src/platforms/virtual/CMakeLists.txt | 3 - src/platforms/virtual/input/CMakeLists.txt | 28 ------- src/platforms/virtual/input/input.cpp | 73 ------------------- .../virtual/input/input_platform.cpp | 46 ------------ src/platforms/virtual/input/input_platform.h | 48 ------------ tests/unit-tests/input/CMakeLists.txt | 2 - .../input/test_input_platform_probing.cpp | 11 --- .../platforms/virtual/CMakeLists.txt | 1 - 8 files changed, 212 deletions(-) delete mode 100644 src/platforms/virtual/input/CMakeLists.txt delete mode 100644 src/platforms/virtual/input/input.cpp delete mode 100644 src/platforms/virtual/input/input_platform.cpp delete mode 100644 src/platforms/virtual/input/input_platform.h diff --git a/src/platforms/virtual/CMakeLists.txt b/src/platforms/virtual/CMakeLists.txt index 104be53493a..56d07467fe9 100644 --- a/src/platforms/virtual/CMakeLists.txt +++ b/src/platforms/virtual/CMakeLists.txt @@ -1,5 +1,4 @@ add_subdirectory(graphics/) -add_subdirectory(input/) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/symbols.map.in ${CMAKE_CURRENT_BINARY_DIR}/symbols.map) @@ -8,8 +7,6 @@ set(symbol_map ${CMAKE_CURRENT_BINARY_DIR}/symbols.map) add_library(mirplatformvirtual MODULE $ $ - $ - $ ) diff --git a/src/platforms/virtual/input/CMakeLists.txt b/src/platforms/virtual/input/CMakeLists.txt deleted file mode 100644 index 2f12f011c73..00000000000 --- a/src/platforms/virtual/input/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -include_directories( - ${server_common_include_dirs} -) - -add_library( - mirplatforminputvirtualobjects OBJECT - - input_platform.cpp -) - -target_link_libraries(mirplatforminputvirtualobjects - PUBLIC - mirplatform - mircommon - mircore -) - -add_library( - mirplatforminputvirtualobjects-symbols OBJECT - - input.cpp -) - -target_link_libraries(mirplatforminputvirtualobjects-symbols - PUBLIC - mirplatform - mircommon -) diff --git a/src/platforms/virtual/input/input.cpp b/src/platforms/virtual/input/input.cpp deleted file mode 100644 index 5c23ca68f17..00000000000 --- a/src/platforms/virtual/input/input.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright © Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 or 3, - * as published by the Free Software Foundation. - * - * 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 "input_platform.h" -#include "mir/module_properties.h" -#include "mir/assert_module_entry_point.h" -#include "mir/libname.h" -#include "mir/options/configuration.h" -#include "../graphics/platform.h" - -namespace mo = mir::options; -namespace mi = mir::input; -namespace miv = mir::input::virt; - -mir::UniqueModulePtr create_input_platform( - mo::Option const& /*options*/, - std::shared_ptr const& /*emergency_cleanup_registry*/, - std::shared_ptr const& /*input_device_registry*/, - std::shared_ptr const& /*console*/, - std::shared_ptr const& /*report*/) -{ - mir::assert_entry_point_signature(&create_input_platform); - return mir::make_module_ptr(); -} - -void add_input_platform_options( - boost::program_options::options_description& /*config*/) -{ - mir::assert_entry_point_signature(&add_input_platform_options); -} - -mi::PlatformPriority probe_input_platform( - mo::Option const&, - mir::ConsoleServices&) -{ - mir::assert_entry_point_signature(&probe_input_platform); - if (mir::graphics::virt::Platform::has_instance()) - { - return mi::PlatformPriority::best; - } - - return mi::PlatformPriority::dummy; -} - -namespace -{ -mir::ModuleProperties const description = { - "mir:virtual-input", - MIR_VERSION_MAJOR, - MIR_VERSION_MINOR, - MIR_VERSION_MICRO, - mir::libname() -}; -} - -mir::ModuleProperties const* describe_input_module() -{ - mir::assert_entry_point_signature(&describe_input_module); - return &description; -} diff --git a/src/platforms/virtual/input/input_platform.cpp b/src/platforms/virtual/input/input_platform.cpp deleted file mode 100644 index 3f3f8745dd9..00000000000 --- a/src/platforms/virtual/input/input_platform.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright © Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License version 2 or 3, - * as published by the Free Software Foundation. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -#include "input_platform.h" -#include - -namespace mi = mir::input; -namespace miv = mir::input::virt; - -miv::VirtualInputPlatform::VirtualInputPlatform() -{ -} - -std::shared_ptr miv::VirtualInputPlatform::dispatchable() -{ - return std::make_shared(); -} - -void miv::VirtualInputPlatform::start() -{ -} - -void miv::VirtualInputPlatform::stop() -{ -} - -void miv::VirtualInputPlatform::pause_for_config() -{ -} - -void miv::VirtualInputPlatform::continue_after_config() -{ -} \ No newline at end of file diff --git a/src/platforms/virtual/input/input_platform.h b/src/platforms/virtual/input/input_platform.h deleted file mode 100644 index e9f33ee6fac..00000000000 --- a/src/platforms/virtual/input/input_platform.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright © Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License version 2 or 3, - * as published by the Free Software Foundation. - * - * 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - - -#ifndef MIR_GRAPHICS_VIRTUAL_INPUT_PLATFORM_H_ -#define MIR_GRAPHICS_VIRTUAL_INPUT_PLATFORM_H_ - -#include "mir/input/platform.h" - -namespace mir -{ -namespace input -{ -namespace virt -{ - -/// Serves as a pass-through platform so that the virtual input platform -/// does not default to evdev (which would lead to funny things, like -/// two inputs being registered when using a VNC on localhost) -class VirtualInputPlatform : public input::Platform -{ -public: - VirtualInputPlatform(); - std::shared_ptr dispatchable() override; - void start() override; - void stop() override; - void pause_for_config() override; - void continue_after_config() override; -}; - -} -} -} - -#endif //MIR_GRAPHICS_VIRTUAL_INPUT_PLATFORM_H_ diff --git a/tests/unit-tests/input/CMakeLists.txt b/tests/unit-tests/input/CMakeLists.txt index d22f106eafc..756e47d77a2 100644 --- a/tests/unit-tests/input/CMakeLists.txt +++ b/tests/unit-tests/input/CMakeLists.txt @@ -25,9 +25,7 @@ list(APPEND UMOCK_UNIT_TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/test_input_platform_probing.cpp $ $ - $ ) - if (MIR_BUILD_PLATFORM_X11) list(APPEND UMOCK_UNIT_TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/test_x11_platform.cpp diff --git a/tests/unit-tests/input/test_input_platform_probing.cpp b/tests/unit-tests/input/test_input_platform_probing.cpp index 0649f4f8ec8..a350003e6f0 100644 --- a/tests/unit-tests/input/test_input_platform_probing.cpp +++ b/tests/unit-tests/input/test_input_platform_probing.cpp @@ -32,7 +32,6 @@ #include "mir/test/doubles/mock_input_device_registry.h" #include "src/platforms/evdev/platform.h" #include "src/platforms/x11/input/input_platform.h" -#include "src/platforms/virtual/input/input_platform.h" #include "mir/test/fake_shared.h" namespace mt = mir::test; @@ -52,7 +51,6 @@ struct StubEmergencyCleanupRegistry : mir::EmergencyCleanupRegistry }; char const platform_input_lib[] = "platform-input-lib"; char const platform_path[] = "platform-path"; -char const platform_display_libs[] = "platform-display-libs"; struct InputPlatformProbe : ::testing::Test { @@ -60,7 +58,6 @@ struct InputPlatformProbe : ::testing::Test { ON_CALL(mock_options, is_set(StrEq(platform_input_lib))).WillByDefault(Return(false)); ON_CALL(mock_options, is_set(StrEq(platform_path))).WillByDefault(Return(true)); - ON_CALL(mock_options, is_set(StrEq(platform_display_libs))).WillByDefault(Return(true)); ON_CALL(mock_options, get(StrEq(platform_path),Matcher(_))) .WillByDefault(Return(platform_path_value)); ON_CALL(mock_options, get(StrEq(platform_path))) @@ -75,12 +72,6 @@ struct InputPlatformProbe : ::testing::Test { return platform_input_lib_value_as_any; })); - ON_CALL(mock_options, get(StrEq(platform_display_libs_value))) - .WillByDefault(Invoke( - [this](char const*) -> boost::any const& - { - return platform_display_libs_value_as_any; - })); #ifdef MIR_BUILD_PLATFORM_X11 ON_CALL(mock_x11, XGetXCBConnection(_)) .WillByDefault(Return(reinterpret_cast(1))); @@ -110,8 +101,6 @@ struct InputPlatformProbe : ::testing::Test boost::any platform_path_value_as_any{platform_path_value}; std::string platform_input_lib_value; boost::any platform_input_lib_value_as_any; - std::string platform_display_libs_value; - boost::any platform_display_libs_value_as_any; std::vector> const empty_loaded_module_list{}; }; diff --git a/tests/unit-tests/platforms/virtual/CMakeLists.txt b/tests/unit-tests/platforms/virtual/CMakeLists.txt index e2479f0ea24..df55f07284a 100644 --- a/tests/unit-tests/platforms/virtual/CMakeLists.txt +++ b/tests/unit-tests/platforms/virtual/CMakeLists.txt @@ -2,7 +2,6 @@ mir_add_wrapped_executable(mir_unit_tests_virtual NOINSTALL ${CMAKE_CURRENT_SOURCE_DIR}/test_platform.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_display.cpp $ - $ $ # Sub-optimal. We really want to link a lib ) From 5a07d615e606643adf9ca4db8c6b130786c837e2 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Wed, 11 Oct 2023 11:52:08 -0400 Subject: [PATCH 29/51] Remove unused function from platform --- src/platforms/virtual/graphics/platform.cpp | 11 ----------- src/platforms/virtual/graphics/platform.h | 2 -- 2 files changed, 13 deletions(-) diff --git a/src/platforms/virtual/graphics/platform.cpp b/src/platforms/virtual/graphics/platform.cpp index 6823ae34a4a..97a2180c8ea 100644 --- a/src/platforms/virtual/graphics/platform.cpp +++ b/src/platforms/virtual/graphics/platform.cpp @@ -24,10 +24,6 @@ namespace mgv = mir::graphics::virt; namespace geom = mir::geometry; using namespace std::literals; -namespace -{ -mgv::Platform* virtual_platform = nullptr; -} class mgv::Platform::VirtualDisplayInterfaceProvider : public mg::DisplayInterfaceProvider { @@ -92,12 +88,10 @@ mgv::Platform::Platform( provider{std::make_shared()}, outputs{outputs} { - virtual_platform = this; } mgv::Platform::~Platform() { - virtual_platform = nullptr; } mir::UniqueModulePtr mgv::Platform::create_display( @@ -129,9 +123,4 @@ auto mgv::Platform::parse_output_sizes(std::vector virtual_outputs) configs.push_back(VirtualOutputConfig(std::move(sizes))); } return configs; -} - -bool mgv::Platform::has_instance() -{ - return virtual_platform != nullptr; } \ No newline at end of file diff --git a/src/platforms/virtual/graphics/platform.h b/src/platforms/virtual/graphics/platform.h index 3685a40e9a3..14cc4859843 100644 --- a/src/platforms/virtual/graphics/platform.h +++ b/src/platforms/virtual/graphics/platform.h @@ -56,8 +56,6 @@ class Platform : public graphics::DisplayPlatform std::shared_ptr const& initial_conf_policy, std::shared_ptr const& gl_config) override; - static bool has_instance(); - protected: auto interface_for() -> std::shared_ptr override; private: From baa0fdc1131c60efaf2412e8501ada4ea58a7974 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Wed, 11 Oct 2023 13:42:37 -0400 Subject: [PATCH 30/51] Virtual platform is now a 'dummy' platform --- src/platforms/virtual/graphics/graphics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/virtual/graphics/graphics.cpp b/src/platforms/virtual/graphics/graphics.cpp index 5e5d09176d2..537ec04520c 100644 --- a/src/platforms/virtual/graphics/graphics.cpp +++ b/src/platforms/virtual/graphics/graphics.cpp @@ -74,7 +74,7 @@ auto probe_display_platform( std::vector result; result.push_back({ nullptr, - mg::PlatformPriority::supported, + mg::PlatformPriority::dummy, nullptr }); return result; From 473fbdf6590deba8592ae9365c9ae5d60fc37969 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Wed, 11 Oct 2023 13:48:34 -0400 Subject: [PATCH 31/51] display_configuration.cpp now uses virtual instead of unknown --- src/platforms/virtual/graphics/display_configuration.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/virtual/graphics/display_configuration.cpp b/src/platforms/virtual/graphics/display_configuration.cpp index c81df99df62..7a1f15d8fe3 100644 --- a/src/platforms/virtual/graphics/display_configuration.cpp +++ b/src/platforms/virtual/graphics/display_configuration.cpp @@ -35,7 +35,7 @@ mg::DisplayConfigurationOutput mgv::DisplayConfiguration::build_output(mgv::Virt mg::DisplayConfigurationOutputId{last_output_id}, mg::DisplayConfigurationCardId{0}, mg::DisplayConfigurationLogicalGroupId{0}, - mg::DisplayConfigurationOutputType::unknown, + mg::DisplayConfigurationOutputType::virt, {MirPixelFormat ::mir_pixel_format_argb_8888}, std::move(configuration_modes), 0, From 2729cdd9f1737d90a9b1b50cd405b9d5c431302d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sawicz=20=28Saviq=29?= Date: Thu, 12 Oct 2023 09:08:48 +0200 Subject: [PATCH 32/51] Revert "Virtual platform is now a 'dummy' platform" This reverts commit 211680796dc58924a1b81bb15850f0a8d5d3eff8. --- src/platforms/virtual/graphics/graphics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/virtual/graphics/graphics.cpp b/src/platforms/virtual/graphics/graphics.cpp index 537ec04520c..5e5d09176d2 100644 --- a/src/platforms/virtual/graphics/graphics.cpp +++ b/src/platforms/virtual/graphics/graphics.cpp @@ -74,7 +74,7 @@ auto probe_display_platform( std::vector result; result.push_back({ nullptr, - mg::PlatformPriority::dummy, + mg::PlatformPriority::supported, nullptr }); return result; From ad2ae604e6f9b67cfd13d982d9116f53d201474d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sawicz=20=28Saviq=29?= Date: Thu, 12 Oct 2023 11:04:48 +0200 Subject: [PATCH 33/51] tests: add eglinfo dependency --- tests/performance-tests/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/performance-tests/CMakeLists.txt b/tests/performance-tests/CMakeLists.txt index 61645e32cc6..e39ef538c4e 100644 --- a/tests/performance-tests/CMakeLists.txt +++ b/tests/performance-tests/CMakeLists.txt @@ -18,12 +18,13 @@ install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/mir-smoke-test-runner DESTINATION ${CMAKE_INSTALL_BINDIR} ) +find_program(EGLINFO_EXECUTABLE eglinfo) find_program(XVFB_RUN_EXECUTABLE xvfb-run) find_program(GLMARK2_EXECUTABLE glmark2-es2-wayland) CMAKE_DEPENDENT_OPTION( MIR_RUN_SMOKE_TESTS "Run mir-smoke-test-runner as part of testsuite" ON - "XVFB_RUN_EXECUTABLE" OFF + "EGLINFO_EXECUTABLE;XVFB_RUN_EXECUTABLE" OFF ) CMAKE_DEPENDENT_OPTION( From f8ec4298a2d798abe6b81bb132d85965a3d82a03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sawicz=20=28Saviq=29?= Date: Thu, 12 Oct 2023 11:06:01 +0200 Subject: [PATCH 34/51] tests: drop xvfb, use the virtual platform instead --- tests/performance-tests/CMakeLists.txt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/performance-tests/CMakeLists.txt b/tests/performance-tests/CMakeLists.txt index e39ef538c4e..e85d9924dd1 100644 --- a/tests/performance-tests/CMakeLists.txt +++ b/tests/performance-tests/CMakeLists.txt @@ -19,27 +19,26 @@ install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/mir-smoke-test-runner ) find_program(EGLINFO_EXECUTABLE eglinfo) -find_program(XVFB_RUN_EXECUTABLE xvfb-run) find_program(GLMARK2_EXECUTABLE glmark2-es2-wayland) CMAKE_DEPENDENT_OPTION( MIR_RUN_SMOKE_TESTS "Run mir-smoke-test-runner as part of testsuite" ON - "EGLINFO_EXECUTABLE;XVFB_RUN_EXECUTABLE" OFF + "EGLINFO_EXECUTABLE" OFF ) CMAKE_DEPENDENT_OPTION( MIR_RUN_PERFORMANCE_TESTS "Run mir_performance_tests as part of testsuite" OFF - "XVFB_RUN_EXECUTABLE;GLMARK2_EXECUTABLE" OFF + "GLMARK2_EXECUTABLE" OFF ) if(MIR_RUN_SMOKE_TESTS) mir_add_test(NAME mir-smoke-test-runner - COMMAND "xvfb-run" "--auto-servernum" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/mir-smoke-test-runner" + COMMAND "env" "MIR_SERVER_VIRTUAL_OUTPUT=1280x1024" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/mir-smoke-test-runner" ) endif() if(MIR_RUN_PERFORMANCE_TESTS) mir_add_test(NAME mir_performance_tests - COMMAND "xvfb-run" "--auto-servernum" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/mir_performance_tests" + COMMAND "env" "MIR_SERVER_VIRTUAL_OUTPUT=1280x1024" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/mir_performance_tests" ) endif() From 60aeb209763329dfbffcf2d387c3d1c1b1f022bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sawicz=20=28Saviq=29?= Date: Thu, 12 Oct 2023 12:00:35 +0200 Subject: [PATCH 35/51] coverage: add missing dependencies --- .github/workflows/coverage.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index ea3e67c7775..803511be2c0 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -55,7 +55,9 @@ jobs: sudo apt-add-repository --yes ppa:mir-team/dev sudo apt-get install --no-install-recommends \ dmz-cursor-theme \ + glmark2-es2-wayland \ lcov \ + mesa-utils \ ninja-build # deal with incompataibles preinstalled From b09b8cadc34e9d413298d125789a0a40bcd4b7c0 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Thu, 12 Oct 2023 09:22:16 -0400 Subject: [PATCH 36/51] Proper const styles for virtual display.cpp --- src/platforms/virtual/graphics/display.cpp | 7 +++---- src/platforms/virtual/graphics/display.h | 8 ++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/platforms/virtual/graphics/display.cpp b/src/platforms/virtual/graphics/display.cpp index d10d909f2a4..91a8ee87de1 100644 --- a/src/platforms/virtual/graphics/display.cpp +++ b/src/platforms/virtual/graphics/display.cpp @@ -27,7 +27,7 @@ mgv::Display::Display(std::vector output_sizes) { } -void mgv::Display::for_each_display_sync_group(const std::function &) +void mgv::Display::for_each_display_sync_group(std::function const&) { } @@ -41,8 +41,7 @@ std::unique_ptr mgv::Display::configuration() const return std::make_unique(output_configurations); } -bool mgv::Display::apply_if_configuration_preserves_display_buffers( - const mir::graphics::DisplayConfiguration &) +bool mgv::Display::apply_if_configuration_preserves_display_buffers(mir::graphics::DisplayConfiguration const&) { return true; } @@ -53,7 +52,7 @@ void mgv::Display::configure(mir::graphics::DisplayConfiguration const&) void mgv::Display::register_configuration_change_handler( mir::graphics::EventHandlerRegister &, - const mir::graphics::DisplayConfigurationChangeHandler &) + mir::graphics::DisplayConfigurationChangeHandler const&) { } diff --git a/src/platforms/virtual/graphics/display.h b/src/platforms/virtual/graphics/display.h index a26a7e3a029..46ea44c1627 100644 --- a/src/platforms/virtual/graphics/display.h +++ b/src/platforms/virtual/graphics/display.h @@ -31,13 +31,13 @@ class Display : public mir::graphics::Display { public: explicit Display(std::vector output_sizes); - void for_each_display_sync_group(const std::function &f) override; + void for_each_display_sync_group(std::function const& f) override; std::unique_ptr configuration() const override; - bool apply_if_configuration_preserves_display_buffers(const mir::graphics::DisplayConfiguration &conf) override; - void configure(const mir::graphics::DisplayConfiguration &conf) override; + bool apply_if_configuration_preserves_display_buffers(mir::graphics::DisplayConfiguration const& conf) override; + void configure(mir::graphics::DisplayConfiguration const& conf) override; void register_configuration_change_handler( EventHandlerRegister &handlers, - const DisplayConfigurationChangeHandler &conf_change_handler) override; + DisplayConfigurationChangeHandler const& conf_change_handler) override; void pause() override; void resume() override; std::shared_ptr create_hardware_cursor() override; From cd591ab5d03c63ce26ec5fd39ca57b88c894951b Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Thu, 12 Oct 2023 09:50:37 -0400 Subject: [PATCH 37/51] Removing unnecessary graphics folder from virtual platform --- src/platforms/virtual/CMakeLists.txt | 54 +++++++++++++------ .../virtual/{graphics => }/display.cpp | 0 .../virtual/{graphics => }/display.h | 0 .../{graphics => }/display_configuration.cpp | 0 .../{graphics => }/display_configuration.h | 0 .../virtual/{graphics => }/graphics.cpp | 0 .../virtual/{graphics => }/platform.cpp | 0 .../virtual/{graphics => }/platform.h | 0 .../platforms/virtual/test_display.cpp | 4 +- .../platforms/virtual/test_platform.cpp | 2 +- 10 files changed, 40 insertions(+), 20 deletions(-) rename src/platforms/virtual/{graphics => }/display.cpp (100%) rename src/platforms/virtual/{graphics => }/display.h (100%) rename src/platforms/virtual/{graphics => }/display_configuration.cpp (100%) rename src/platforms/virtual/{graphics => }/display_configuration.h (100%) rename src/platforms/virtual/{graphics => }/graphics.cpp (100%) rename src/platforms/virtual/{graphics => }/platform.cpp (100%) rename src/platforms/virtual/{graphics => }/platform.h (100%) diff --git a/src/platforms/virtual/CMakeLists.txt b/src/platforms/virtual/CMakeLists.txt index 56d07467fe9..257d9425e80 100644 --- a/src/platforms/virtual/CMakeLists.txt +++ b/src/platforms/virtual/CMakeLists.txt @@ -1,30 +1,50 @@ -add_subdirectory(graphics/) +include_directories( + ${server_common_include_dirs} +) -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/symbols.map.in - ${CMAKE_CURRENT_BINARY_DIR}/symbols.map) +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/symbols.map.in + ${CMAKE_CURRENT_BINARY_DIR}/symbols.map +) set(symbol_map ${CMAKE_CURRENT_BINARY_DIR}/symbols.map) -add_library(mirplatformvirtual MODULE - $ - $ +add_library(mirplatformgraphicsvirtualobjects OBJECT + graphics.cpp + platform.cpp + platform.h + display.h + display.cpp + display_configuration.h + display_configuration.cpp +) + +target_link_libraries(mirplatformgraphicsvirtualobjects + PUBLIC + mirplatform + mircommon + mircore ) +add_library(mirplatformvirtual MODULE + $ +) target_link_libraries( - mirplatformvirtual - PRIVATE - mirplatform - server_platform_common + mirplatformvirtual + + PRIVATE + mirplatform + server_platform_common ) set_target_properties( - mirplatformvirtual PROPERTIES - OUTPUT_NAME server-virtual - LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/server-modules - PREFIX "" - SUFFIX ".so.${MIR_SERVER_GRAPHICS_PLATFORM_ABI}" - LINK_FLAGS "-Wl,--exclude-libs=ALL -Wl,--version-script,${symbol_map}" - LINK_DEPENDS ${symbol_map} + mirplatformvirtual PROPERTIES + OUTPUT_NAME server-virtual + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/server-modules + PREFIX "" + SUFFIX ".so.${MIR_SERVER_GRAPHICS_PLATFORM_ABI}" + LINK_FLAGS "-Wl,--exclude-libs=ALL -Wl,--version-script,${symbol_map}" + LINK_DEPENDS ${symbol_map} ) install(TARGETS mirplatformvirtual LIBRARY DESTINATION ${MIR_SERVER_PLATFORM_PATH}) diff --git a/src/platforms/virtual/graphics/display.cpp b/src/platforms/virtual/display.cpp similarity index 100% rename from src/platforms/virtual/graphics/display.cpp rename to src/platforms/virtual/display.cpp diff --git a/src/platforms/virtual/graphics/display.h b/src/platforms/virtual/display.h similarity index 100% rename from src/platforms/virtual/graphics/display.h rename to src/platforms/virtual/display.h diff --git a/src/platforms/virtual/graphics/display_configuration.cpp b/src/platforms/virtual/display_configuration.cpp similarity index 100% rename from src/platforms/virtual/graphics/display_configuration.cpp rename to src/platforms/virtual/display_configuration.cpp diff --git a/src/platforms/virtual/graphics/display_configuration.h b/src/platforms/virtual/display_configuration.h similarity index 100% rename from src/platforms/virtual/graphics/display_configuration.h rename to src/platforms/virtual/display_configuration.h diff --git a/src/platforms/virtual/graphics/graphics.cpp b/src/platforms/virtual/graphics.cpp similarity index 100% rename from src/platforms/virtual/graphics/graphics.cpp rename to src/platforms/virtual/graphics.cpp diff --git a/src/platforms/virtual/graphics/platform.cpp b/src/platforms/virtual/platform.cpp similarity index 100% rename from src/platforms/virtual/graphics/platform.cpp rename to src/platforms/virtual/platform.cpp diff --git a/src/platforms/virtual/graphics/platform.h b/src/platforms/virtual/platform.h similarity index 100% rename from src/platforms/virtual/graphics/platform.h rename to src/platforms/virtual/platform.h diff --git a/tests/unit-tests/platforms/virtual/test_display.cpp b/tests/unit-tests/platforms/virtual/test_display.cpp index a514ba76cb2..47fc524a5a6 100644 --- a/tests/unit-tests/platforms/virtual/test_display.cpp +++ b/tests/unit-tests/platforms/virtual/test_display.cpp @@ -17,8 +17,8 @@ #include #include -#include "src/platforms/virtual/graphics/display.h" -#include "src/platforms/virtual/graphics/platform.h" +#include "src/platforms/virtual/display.h" +#include "src/platforms/virtual/platform.h" #include "mir/graphics/display_configuration.h" diff --git a/tests/unit-tests/platforms/virtual/test_platform.cpp b/tests/unit-tests/platforms/virtual/test_platform.cpp index 2645c2e914b..92626a3ae7d 100644 --- a/tests/unit-tests/platforms/virtual/test_platform.cpp +++ b/tests/unit-tests/platforms/virtual/test_platform.cpp @@ -18,7 +18,7 @@ #include #include "mir/graphics/platform.h" -#include "src/platforms/virtual/graphics/platform.h" +#include "src/platforms/virtual/platform.h" #include "mir/shared_library.h" #include "src/server/report/null/display_report.h" From b978c5847731c224f58e83d1fdf35d032096e506 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Thu, 12 Oct 2023 10:39:34 -0400 Subject: [PATCH 38/51] User must specify at least one virtual output for the platform to be supported --- src/platforms/virtual/graphics.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/platforms/virtual/graphics.cpp b/src/platforms/virtual/graphics.cpp index 5e5d09176d2..4a5fd51cef6 100644 --- a/src/platforms/virtual/graphics.cpp +++ b/src/platforms/virtual/graphics.cpp @@ -59,7 +59,6 @@ void add_graphics_platform_options(boost::program_options::options_description& config.add_options() (virtual_displays_option_name, boost::program_options::value>() - ->default_value(std::vector{"1280x1024"}, "1280x1024") ->multitoken(), "[mir-on-virtual specific] Colon separated list of WIDTHxHEIGHT sizes for the \"output\" size." " Multiple outputs may be specified by providing the argument multiple times."); @@ -68,15 +67,18 @@ void add_graphics_platform_options(boost::program_options::options_description& auto probe_display_platform( std::shared_ptr const&, std::shared_ptr const&, - mo::ProgramOption const&) -> std::vector + mo::ProgramOption const& options) -> std::vector { mir::assert_entry_point_signature(&probe_display_platform); std::vector result; - result.push_back({ - nullptr, - mg::PlatformPriority::supported, - nullptr - }); + if (options.is_set(virtual_displays_option_name)) + { + result.push_back({ + nullptr, + mg::PlatformPriority::supported, + nullptr + }); + } return result; } From 9636f4cb412247a736c1c42f8907de2210a5ba2d Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Thu, 12 Oct 2023 10:59:26 -0400 Subject: [PATCH 39/51] Revert "tests: drop xvfb, use the virtual platform instead" This reverts commit 30fbf12886a925958bded408d2c51df5cf4a36a4. --- tests/performance-tests/CMakeLists.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/performance-tests/CMakeLists.txt b/tests/performance-tests/CMakeLists.txt index e85d9924dd1..e39ef538c4e 100644 --- a/tests/performance-tests/CMakeLists.txt +++ b/tests/performance-tests/CMakeLists.txt @@ -19,26 +19,27 @@ install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/mir-smoke-test-runner ) find_program(EGLINFO_EXECUTABLE eglinfo) +find_program(XVFB_RUN_EXECUTABLE xvfb-run) find_program(GLMARK2_EXECUTABLE glmark2-es2-wayland) CMAKE_DEPENDENT_OPTION( MIR_RUN_SMOKE_TESTS "Run mir-smoke-test-runner as part of testsuite" ON - "EGLINFO_EXECUTABLE" OFF + "EGLINFO_EXECUTABLE;XVFB_RUN_EXECUTABLE" OFF ) CMAKE_DEPENDENT_OPTION( MIR_RUN_PERFORMANCE_TESTS "Run mir_performance_tests as part of testsuite" OFF - "GLMARK2_EXECUTABLE" OFF + "XVFB_RUN_EXECUTABLE;GLMARK2_EXECUTABLE" OFF ) if(MIR_RUN_SMOKE_TESTS) mir_add_test(NAME mir-smoke-test-runner - COMMAND "env" "MIR_SERVER_VIRTUAL_OUTPUT=1280x1024" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/mir-smoke-test-runner" + COMMAND "xvfb-run" "--auto-servernum" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/mir-smoke-test-runner" ) endif() if(MIR_RUN_PERFORMANCE_TESTS) mir_add_test(NAME mir_performance_tests - COMMAND "env" "MIR_SERVER_VIRTUAL_OUTPUT=1280x1024" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/mir_performance_tests" + COMMAND "xvfb-run" "--auto-servernum" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/mir_performance_tests" ) endif() From e6d228abfc8204e0ef5649861cba9ebb063d8658 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Fri, 13 Oct 2023 09:19:42 -0400 Subject: [PATCH 40/51] Removing rogue virtual/graphics folder --- src/platforms/virtual/graphics/CMakeLists.txt | 31 ------------------- 1 file changed, 31 deletions(-) delete mode 100644 src/platforms/virtual/graphics/CMakeLists.txt diff --git a/src/platforms/virtual/graphics/CMakeLists.txt b/src/platforms/virtual/graphics/CMakeLists.txt deleted file mode 100644 index 16ae38dce8d..00000000000 --- a/src/platforms/virtual/graphics/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -include_directories( - ${server_common_include_dirs} -) - -add_library( - mirplatformgraphicsvirtualobjects OBJECT - - platform.cpp - display.cpp - display_configuration.cpp -) - -add_library( - mirplatformgraphicsvirtualobjects-symbols OBJECT - - graphics.cpp -) - -target_link_libraries(mirplatformgraphicsvirtualobjects-symbols - PUBLIC - mirplatform - mircommon - mircore -) - -target_link_libraries( - mirplatformgraphicsvirtualobjects - - PRIVATE - mirplatform -) From f8915be25d3040c6092e5d6587eb80a8d121588a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sawicz=20=28Saviq=29?= Date: Fri, 13 Oct 2023 07:47:43 +0200 Subject: [PATCH 41/51] Revert "coverage: add missing dependencies" This reverts commit 71902f0c1729a40a4a2e2b712d1439f3d146f9da. --- .github/workflows/coverage.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 803511be2c0..ea3e67c7775 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -55,9 +55,7 @@ jobs: sudo apt-add-repository --yes ppa:mir-team/dev sudo apt-get install --no-install-recommends \ dmz-cursor-theme \ - glmark2-es2-wayland \ lcov \ - mesa-utils \ ninja-build # deal with incompataibles preinstalled From a1de2788676959699d1ed962ead7c6b40a76ddae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sawicz=20=28Saviq=29?= Date: Fri, 13 Oct 2023 07:48:06 +0200 Subject: [PATCH 42/51] Revert "tests: add eglinfo dependency" This reverts commit b9a4c9eaba7f2d3054aa885d5534aac3c24f6308. --- tests/performance-tests/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/performance-tests/CMakeLists.txt b/tests/performance-tests/CMakeLists.txt index e39ef538c4e..61645e32cc6 100644 --- a/tests/performance-tests/CMakeLists.txt +++ b/tests/performance-tests/CMakeLists.txt @@ -18,13 +18,12 @@ install(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/mir-smoke-test-runner DESTINATION ${CMAKE_INSTALL_BINDIR} ) -find_program(EGLINFO_EXECUTABLE eglinfo) find_program(XVFB_RUN_EXECUTABLE xvfb-run) find_program(GLMARK2_EXECUTABLE glmark2-es2-wayland) CMAKE_DEPENDENT_OPTION( MIR_RUN_SMOKE_TESTS "Run mir-smoke-test-runner as part of testsuite" ON - "EGLINFO_EXECUTABLE;XVFB_RUN_EXECUTABLE" OFF + "XVFB_RUN_EXECUTABLE" OFF ) CMAKE_DEPENDENT_OPTION( From 525bf195cb6f82e52eb38ac601de967b04d7d0de Mon Sep 17 00:00:00 2001 From: Alan Griffiths Date: Tue, 17 Oct 2023 17:59:12 +0100 Subject: [PATCH 43/51] Apply refactorings that happened on target branch --- src/platforms/virtual/graphics.cpp | 2 +- src/platforms/virtual/platform.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/platforms/virtual/graphics.cpp b/src/platforms/virtual/graphics.cpp index 4a5fd51cef6..63641d5fd0e 100644 --- a/src/platforms/virtual/graphics.cpp +++ b/src/platforms/virtual/graphics.cpp @@ -75,7 +75,7 @@ auto probe_display_platform( { result.push_back({ nullptr, - mg::PlatformPriority::supported, + mg::probe::supported, nullptr }); } diff --git a/src/platforms/virtual/platform.cpp b/src/platforms/virtual/platform.cpp index 97a2180c8ea..a81d41daf9d 100644 --- a/src/platforms/virtual/platform.cpp +++ b/src/platforms/virtual/platform.cpp @@ -33,8 +33,8 @@ class mgv::Platform::VirtualDisplayInterfaceProvider : public mg::DisplayInterfa } protected: - auto maybe_create_interface(mg::DisplayInterfaceBase::Tag const& type_tag) - -> std::shared_ptr + auto maybe_create_interface(mg::DisplayProvider::Tag const& type_tag) + -> std::shared_ptr { class StubGenericEGLDisplayProvider : public GenericEGLDisplayProvider { From 23aad29ede2ab24f7dc0d59e26d241691db5c592 Mon Sep 17 00:00:00 2001 From: Alan Griffiths Date: Mon, 23 Oct 2023 10:35:26 +0100 Subject: [PATCH 44/51] Improve diagnostics for `get_egl_display()` failures --- src/platforms/virtual/platform.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/platforms/virtual/platform.cpp b/src/platforms/virtual/platform.cpp index a81d41daf9d..63a0e9ab1fd 100644 --- a/src/platforms/virtual/platform.cpp +++ b/src/platforms/virtual/platform.cpp @@ -17,6 +17,7 @@ #include "platform.h" #include "display.h" #include "mir/graphics/platform.h" +#include "mir/graphics/egl_error.h" #include "options_parsing_helpers.h" namespace mg = mir::graphics; @@ -41,10 +42,16 @@ class mgv::Platform::VirtualDisplayInterfaceProvider : public mg::DisplayInterfa public: auto get_egl_display() -> EGLDisplay override { - auto egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); + auto const egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); + if (egl_display == EGL_NO_DISPLAY) + { + BOOST_THROW_EXCEPTION((std::runtime_error{"Failed to create EGL display"})); + } EGLint major, minor; if (eglInitialize(egl_display, &major, &minor) == EGL_FALSE) - BOOST_THROW_EXCEPTION(std::runtime_error("Failed to initialize EGL display")); + { + BOOST_THROW_EXCEPTION(egl_error("Failed to initialize EGL display")); + } return egl_display; } From 2c54d7962123d15cd3fd3487dac24e28d675b4ae Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Mon, 23 Oct 2023 09:24:28 -0400 Subject: [PATCH 45/51] Providing a mostly implemented CPUAdressable --- src/platforms/virtual/platform.cpp | 58 ++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/src/platforms/virtual/platform.cpp b/src/platforms/virtual/platform.cpp index 63a0e9ab1fd..6214406fd0b 100644 --- a/src/platforms/virtual/platform.cpp +++ b/src/platforms/virtual/platform.cpp @@ -19,6 +19,7 @@ #include "mir/graphics/platform.h" #include "mir/graphics/egl_error.h" #include "options_parsing_helpers.h" +#include namespace mg = mir::graphics; namespace mgv = mir::graphics::virt; @@ -37,7 +38,7 @@ class mgv::Platform::VirtualDisplayInterfaceProvider : public mg::DisplayInterfa auto maybe_create_interface(mg::DisplayProvider::Tag const& type_tag) -> std::shared_ptr { - class StubGenericEGLDisplayProvider : public GenericEGLDisplayProvider + class VirtualEGLDisplayProvider : public GenericEGLDisplayProvider { public: auto get_egl_display() -> EGLDisplay override @@ -80,10 +81,63 @@ class mgv::Platform::VirtualDisplayInterfaceProvider : public mg::DisplayInterfa private: }; + class VirtualCPUAddressibleDisplayProvider: public CPUAddressableDisplayProvider + { + public: + class VirtualMappableFb: public MappableFB + { + public: + VirtualMappableFb(geom::Size const& size, DRMFormat format) + : size_{size}, format_{format} + { + } + + auto format() const -> MirPixelFormat override + { + return format_.as_mir_format().value_or(mir_pixel_format_invalid); + } + + auto stride() const -> geom::Stride override + { + return geom::Stride{}; + } + + auto size() const -> geom::Size override + { + return size_; + } + + auto map_writeable() -> std::unique_ptr> override + { + return nullptr; + } + + private: + geom::Size size_; + DRMFormat format_; + }; + + auto supported_formats() const -> std::vector override + { + return {mg::DRMFormat{DRM_FORMAT_XRGB8888}, mg::DRMFormat{DRM_FORMAT_ARGB8888}}; + } + + auto alloc_fb(geometry::Size pixel_size, DRMFormat format) -> std::unique_ptr override + { + return std::make_unique(pixel_size, format); + } + }; + if (dynamic_cast(&type_tag)) { - return std::make_shared(); + return std::make_shared(); } + + if (dynamic_cast(&type_tag)) + { + return std::make_shared(); + } + return nullptr; } }; From 45db8291e723c5ff950e6a6d83fea0bf3b01c120 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Mon, 23 Oct 2023 09:55:42 -0400 Subject: [PATCH 46/51] Testing if GenericEGLDisplayProvider can be used --- src/platforms/virtual/platform.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/platforms/virtual/platform.cpp b/src/platforms/virtual/platform.cpp index 6214406fd0b..d4cf949d6a5 100644 --- a/src/platforms/virtual/platform.cpp +++ b/src/platforms/virtual/platform.cpp @@ -109,7 +109,7 @@ class mgv::Platform::VirtualDisplayInterfaceProvider : public mg::DisplayInterfa auto map_writeable() -> std::unique_ptr> override { - return nullptr; + BOOST_THROW_EXCEPTION(std::logic_error("map_writeable is not implemented")); } private: @@ -130,7 +130,18 @@ class mgv::Platform::VirtualDisplayInterfaceProvider : public mg::DisplayInterfa if (dynamic_cast(&type_tag)) { - return std::make_shared(); + auto egl_display_provider = std::make_shared(); + try + { + // If we cannot get the egl display, we can ignore it in the hopes + // that we can use the CPUAddressableDisplayProvider later on instead. + egl_display_provider->get_egl_display(); + return egl_display_provider; + } + catch (std::runtime_error const&) + { + return nullptr; + } } if (dynamic_cast(&type_tag)) From e0b6875bcb279104d37c6fafb1261d391a3f42b2 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Mon, 23 Oct 2023 15:10:36 -0400 Subject: [PATCH 47/51] Fixed tests and a typo with the platform interface --- src/platforms/virtual/platform.cpp | 4 +- .../platforms/virtual/test_platform.cpp | 51 +++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/platforms/virtual/platform.cpp b/src/platforms/virtual/platform.cpp index d4cf949d6a5..c0eb6c25b7d 100644 --- a/src/platforms/virtual/platform.cpp +++ b/src/platforms/virtual/platform.cpp @@ -81,7 +81,7 @@ class mgv::Platform::VirtualDisplayInterfaceProvider : public mg::DisplayInterfa private: }; - class VirtualCPUAddressibleDisplayProvider: public CPUAddressableDisplayProvider + class VirtualCPUAddressableDisplayProvider: public CPUAddressableDisplayProvider { public: class VirtualMappableFb: public MappableFB @@ -146,7 +146,7 @@ class mgv::Platform::VirtualDisplayInterfaceProvider : public mg::DisplayInterfa if (dynamic_cast(&type_tag)) { - return std::make_shared(); + return std::make_shared(); } return nullptr; diff --git a/tests/unit-tests/platforms/virtual/test_platform.cpp b/tests/unit-tests/platforms/virtual/test_platform.cpp index 92626a3ae7d..6737bc6c96d 100644 --- a/tests/unit-tests/platforms/virtual/test_platform.cpp +++ b/tests/unit-tests/platforms/virtual/test_platform.cpp @@ -19,11 +19,13 @@ #include "mir/graphics/platform.h" #include "src/platforms/virtual/platform.h" +#include "mir/test/doubles/mock_egl.h" #include "mir/shared_library.h" #include "src/server/report/null/display_report.h" namespace mg = mir::graphics; +namespace mtd = mir::test::doubles; namespace mgv = mir::graphics::virt; namespace geom = mir::geometry; using namespace testing; @@ -41,6 +43,15 @@ class VirtualGraphicsPlatformTest : public ::testing::Test std::make_shared(), std::vector{config}); } + +protected: + virtual void SetUp() + { + mock_egl.provide_egl_extensions(); + } + + testing::NiceMock mock_egl; + EGLDisplay fake_display{reinterpret_cast(0xabcd)}; }; TEST_F(VirtualGraphicsPlatformTest, lone_config_has_one_output_size_when_provided_one_output_size) @@ -57,13 +68,53 @@ TEST_F(VirtualGraphicsPlatformTest, multiple_output_sizes_are_set_correctly_when mgv::VirtualOutputConfig(std::vector{geom::Size{1280, 1024}, geom::Size{800, 600}}))); } +TEST_F(VirtualGraphicsPlatformTest, can_acquire_interface_for_cpu_addressable_display_provider) +{ + auto platform = create_platform(); + auto interface = mg::DisplayPlatform::interface_for(platform); + EXPECT_TRUE(interface->acquire_interface() != nullptr); +} + TEST_F(VirtualGraphicsPlatformTest, can_acquire_interface_for_generic_egl_display_provider) { + ON_CALL(mock_egl, eglGetDisplay(_)) + .WillByDefault(Return(fake_display)); + ON_CALL(mock_egl, eglInitialize(_,_,_)) + .WillByDefault(DoAll( + SetArgPointee<1>(1), + SetArgPointee<2>(4), + Return(EGL_TRUE))); auto platform = create_platform(); auto interface = mg::DisplayPlatform::interface_for(platform); EXPECT_TRUE(interface->acquire_interface() != nullptr); } +TEST_F(VirtualGraphicsPlatformTest, cannot_acquire_interface_for_generic_egl_display_provider_when_egl_display_is_none) +{ + ON_CALL(mock_egl, eglGetDisplay(_)) + .WillByDefault(Return(EGL_NO_DISPLAY)); + ON_CALL(mock_egl, eglInitialize(_,_,_)) + .WillByDefault(DoAll( + SetArgPointee<1>(1), + SetArgPointee<2>(4), + Return(EGL_TRUE))); + auto platform = create_platform(); + auto interface = mg::DisplayPlatform::interface_for(platform); + EXPECT_THAT(interface->acquire_interface(), nullptr); +} + +TEST_F(VirtualGraphicsPlatformTest, cannot_acquire_interface_for_generic_egl_display_provider_when_egl_initialize_returns_false) +{ + ON_CALL(mock_egl, eglGetDisplay(_)) + .WillByDefault(Return(fake_display)); + ON_CALL(mock_egl, eglInitialize(_,_,_)) + .WillByDefault(DoAll( + Return(EGL_FALSE))); + auto platform = create_platform(); + auto interface = mg::DisplayPlatform::interface_for(platform); + EXPECT_THAT(interface->acquire_interface(), nullptr); +} + TEST_F(VirtualGraphicsPlatformTest, output_size_parsing_throws_on_bad_input) { // X11's tests check the remaining cases here. These are the only cases that do not overlap with X11's. From b509679cb33e156f9656d09af60921672fec8d85 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Mon, 23 Oct 2023 17:16:05 -0400 Subject: [PATCH 48/51] Explicitly syncing the frame to make the EGL client not block for the virtual display --- examples/miral-shell/spinner/miregl.cpp | 58 +++++++++++++++++++++++-- examples/miral-shell/spinner/miregl.h | 3 ++ 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/examples/miral-shell/spinner/miregl.cpp b/examples/miral-shell/spinner/miregl.cpp index d94ea80ff07..aceb70c026f 100644 --- a/examples/miral-shell/spinner/miregl.cpp +++ b/examples/miral-shell/spinner/miregl.cpp @@ -24,6 +24,7 @@ #include #include #include +#include class MirEglApp : public WaylandApp { @@ -35,7 +36,7 @@ class MirEglApp : public WaylandApp EGLSurface create_eglsurface(wl_surface* surface, int width, int height); void make_current(EGLSurface eglsurface) const; - void swap_buffers(EGLSurface eglsurface) const; + void swap_buffers(EGLSurface eglsurface, wl_surface* wayland_surface) const; void destroy_surface(EGLSurface eglsurface) const; void get_surface_size(EGLSurface eglsurface, int* width, int* height) const; @@ -99,7 +100,7 @@ void MirEglSurface::egl_make_current() void MirEglSurface::swap_buffers() { - mir_egl_app->swap_buffers(eglsurface); + mir_egl_app->swap_buffers(eglsurface, surface()); } MirEglApp::MirEglApp(wl_display* display) : @@ -192,9 +193,60 @@ void MirEglApp::make_current(EGLSurface eglsurface) const throw std::runtime_error("Can't eglMakeCurrent"); } -void MirEglApp::swap_buffers(EGLSurface eglsurface) const +void MirEglApp::swap_buffers(EGLSurface eglsurface, wl_surface* wayland_surface) const { + // Taken primarily from src/platforms/wayland/displayclient.cpp + struct FrameSync + { + explicit FrameSync(wl_surface* surface): + surface{surface} + { + } + + void init() + { + callback = wl_surface_frame(surface); + static struct wl_callback_listener const frame_listener = + { + [](void* data, auto... args) + { static_cast(data)->frame_done(args...); }, + }; + wl_callback_add_listener(callback, &frame_listener, this); + } + + ~FrameSync() + { + wl_callback_destroy(callback); + } + + void frame_done(wl_callback*, uint32_t) + { + { + std::lock_guard lock{mutex}; + posted = true; + } + cv.notify_one(); + } + + void wait_for_done() + { + std::unique_lock lock{mutex}; + cv.wait_for(lock, std::chrono::milliseconds{100}, [this]{ return posted; }); + } + + wl_surface* const surface; + + wl_callback* callback; + std::mutex mutex; + bool posted = false; + std::condition_variable cv; + }; + + auto const frame_sync = std::make_shared(wayland_surface); + frame_sync->init(); + eglSwapInterval(egldisplay, 0); eglSwapBuffers(egldisplay, eglsurface); + frame_sync->wait_for_done(); } void MirEglApp::destroy_surface(EGLSurface eglsurface) const diff --git a/examples/miral-shell/spinner/miregl.h b/examples/miral-shell/spinner/miregl.h index 1c1d01aa145..ee85f7da905 100644 --- a/examples/miral-shell/spinner/miregl.h +++ b/examples/miral-shell/spinner/miregl.h @@ -23,6 +23,7 @@ #include #include +#include class MirEglApp; class MirEglSurface; @@ -42,7 +43,9 @@ class MirEglSurface : WaylandSurface { egl_make_current(); functor(width_, height_); + std::cout << "HERE" << std::endl; swap_buffers(); + std::cout << "THERE" << std::endl; } private: From 1822b5552643b4288883b593991a436e8aba328e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sawicz?= Date: Tue, 24 Oct 2023 07:28:58 +0200 Subject: [PATCH 49/51] spinner: drop debug prints --- examples/miral-shell/spinner/miregl.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/miral-shell/spinner/miregl.h b/examples/miral-shell/spinner/miregl.h index ee85f7da905..0f25d767d18 100644 --- a/examples/miral-shell/spinner/miregl.h +++ b/examples/miral-shell/spinner/miregl.h @@ -43,9 +43,7 @@ class MirEglSurface : WaylandSurface { egl_make_current(); functor(width_, height_); - std::cout << "HERE" << std::endl; swap_buffers(); - std::cout << "THERE" << std::endl; } private: From b3e221d8de600e7726c41262d4e435aabcb3cb6a Mon Sep 17 00:00:00 2001 From: Alan Griffiths Date: Tue, 24 Oct 2023 09:53:14 +0100 Subject: [PATCH 50/51] Don't use exceptions for expected control flow --- src/platforms/virtual/CMakeLists.txt | 2 ++ src/platforms/virtual/platform.cpp | 32 ++++++++----------- .../platforms/virtual/test_platform.cpp | 10 ++---- 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/platforms/virtual/CMakeLists.txt b/src/platforms/virtual/CMakeLists.txt index 257d9425e80..32cc34fe355 100644 --- a/src/platforms/virtual/CMakeLists.txt +++ b/src/platforms/virtual/CMakeLists.txt @@ -8,6 +8,8 @@ configure_file( ) set(symbol_map ${CMAKE_CURRENT_BINARY_DIR}/symbols.map) +add_compile_definitions(MIR_LOG_COMPONENT="mir::virtual") + add_library(mirplatformgraphicsvirtualobjects OBJECT graphics.cpp platform.cpp diff --git a/src/platforms/virtual/platform.cpp b/src/platforms/virtual/platform.cpp index c0eb6c25b7d..9e19b8d93f6 100644 --- a/src/platforms/virtual/platform.cpp +++ b/src/platforms/virtual/platform.cpp @@ -18,6 +18,7 @@ #include "display.h" #include "mir/graphics/platform.h" #include "mir/graphics/egl_error.h" +#include "mir/log.h" #include "options_parsing_helpers.h" #include @@ -41,18 +42,11 @@ class mgv::Platform::VirtualDisplayInterfaceProvider : public mg::DisplayInterfa class VirtualEGLDisplayProvider : public GenericEGLDisplayProvider { public: + + explicit VirtualEGLDisplayProvider(EGLDisplay const egl_display) : egl_display{egl_display} {} + auto get_egl_display() -> EGLDisplay override { - auto const egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); - if (egl_display == EGL_NO_DISPLAY) - { - BOOST_THROW_EXCEPTION((std::runtime_error{"Failed to create EGL display"})); - } - EGLint major, minor; - if (eglInitialize(egl_display, &major, &minor) == EGL_FALSE) - { - BOOST_THROW_EXCEPTION(egl_error("Failed to initialize EGL display")); - } return egl_display; } @@ -79,6 +73,7 @@ class mgv::Platform::VirtualDisplayInterfaceProvider : public mg::DisplayInterfa } private: + EGLDisplay const egl_display; }; class VirtualCPUAddressableDisplayProvider: public CPUAddressableDisplayProvider @@ -130,17 +125,18 @@ class mgv::Platform::VirtualDisplayInterfaceProvider : public mg::DisplayInterfa if (dynamic_cast(&type_tag)) { - auto egl_display_provider = std::make_shared(); - try + auto const egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); + if (egl_display == EGL_NO_DISPLAY) + { + log_info("Failed to create EGL display"); + } + else if (eglInitialize(egl_display, nullptr, nullptr) == EGL_FALSE) { - // If we cannot get the egl display, we can ignore it in the hopes - // that we can use the CPUAddressableDisplayProvider later on instead. - egl_display_provider->get_egl_display(); - return egl_display_provider; + log_debug("Failed to initialise EGL: %s", mg::egl_category().message(eglGetError()).c_str()); } - catch (std::runtime_error const&) + else { - return nullptr; + return std::make_shared(egl_display); } } diff --git a/tests/unit-tests/platforms/virtual/test_platform.cpp b/tests/unit-tests/platforms/virtual/test_platform.cpp index 6737bc6c96d..8ed77ec29c8 100644 --- a/tests/unit-tests/platforms/virtual/test_platform.cpp +++ b/tests/unit-tests/platforms/virtual/test_platform.cpp @@ -80,10 +80,7 @@ TEST_F(VirtualGraphicsPlatformTest, can_acquire_interface_for_generic_egl_displa ON_CALL(mock_egl, eglGetDisplay(_)) .WillByDefault(Return(fake_display)); ON_CALL(mock_egl, eglInitialize(_,_,_)) - .WillByDefault(DoAll( - SetArgPointee<1>(1), - SetArgPointee<2>(4), - Return(EGL_TRUE))); + .WillByDefault(Return(EGL_TRUE)); auto platform = create_platform(); auto interface = mg::DisplayPlatform::interface_for(platform); EXPECT_TRUE(interface->acquire_interface() != nullptr); @@ -94,10 +91,7 @@ TEST_F(VirtualGraphicsPlatformTest, cannot_acquire_interface_for_generic_egl_dis ON_CALL(mock_egl, eglGetDisplay(_)) .WillByDefault(Return(EGL_NO_DISPLAY)); ON_CALL(mock_egl, eglInitialize(_,_,_)) - .WillByDefault(DoAll( - SetArgPointee<1>(1), - SetArgPointee<2>(4), - Return(EGL_TRUE))); + .WillByDefault(Return(EGL_TRUE)); auto platform = create_platform(); auto interface = mg::DisplayPlatform::interface_for(platform); EXPECT_THAT(interface->acquire_interface(), nullptr); From 634c940208a3c07fa591c77b822c7fe4e6afe638 Mon Sep 17 00:00:00 2001 From: Alan Griffiths Date: Tue, 24 Oct 2023 11:59:22 +0100 Subject: [PATCH 51/51] Fix nitpicking --- examples/miral-shell/spinner/miregl.cpp | 19 +++++-------------- examples/miral-shell/spinner/miregl.h | 1 - src/platforms/virtual/CMakeLists.txt | 2 +- src/platforms/virtual/graphics.cpp | 2 +- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/examples/miral-shell/spinner/miregl.cpp b/examples/miral-shell/spinner/miregl.cpp index aceb70c026f..c93dd545286 100644 --- a/examples/miral-shell/spinner/miregl.cpp +++ b/examples/miral-shell/spinner/miregl.cpp @@ -200,22 +200,21 @@ void MirEglApp::swap_buffers(EGLSurface eglsurface, wl_surface* wayland_surface) { explicit FrameSync(wl_surface* surface): surface{surface} - { - } - - void init() { callback = wl_surface_frame(surface); static struct wl_callback_listener const frame_listener = { [](void* data, auto... args) - { static_cast(data)->frame_done(args...); }, + { static_cast(data)->frame_done(args...); }, }; wl_callback_add_listener(callback, &frame_listener, this); } + ~FrameSync() { + std::unique_lock lock{mutex}; + cv.wait_for(lock, std::chrono::milliseconds{100}, [this]{ return posted; }); wl_callback_destroy(callback); } @@ -228,12 +227,6 @@ void MirEglApp::swap_buffers(EGLSurface eglsurface, wl_surface* wayland_surface) cv.notify_one(); } - void wait_for_done() - { - std::unique_lock lock{mutex}; - cv.wait_for(lock, std::chrono::milliseconds{100}, [this]{ return posted; }); - } - wl_surface* const surface; wl_callback* callback; @@ -242,11 +235,9 @@ void MirEglApp::swap_buffers(EGLSurface eglsurface, wl_surface* wayland_surface) std::condition_variable cv; }; - auto const frame_sync = std::make_shared(wayland_surface); - frame_sync->init(); + FrameSync frame_sync{wayland_surface}; eglSwapInterval(egldisplay, 0); eglSwapBuffers(egldisplay, eglsurface); - frame_sync->wait_for_done(); } void MirEglApp::destroy_surface(EGLSurface eglsurface) const diff --git a/examples/miral-shell/spinner/miregl.h b/examples/miral-shell/spinner/miregl.h index 0f25d767d18..1c1d01aa145 100644 --- a/examples/miral-shell/spinner/miregl.h +++ b/examples/miral-shell/spinner/miregl.h @@ -23,7 +23,6 @@ #include #include -#include class MirEglApp; class MirEglSurface; diff --git a/src/platforms/virtual/CMakeLists.txt b/src/platforms/virtual/CMakeLists.txt index 32cc34fe355..75ce2b0cbb5 100644 --- a/src/platforms/virtual/CMakeLists.txt +++ b/src/platforms/virtual/CMakeLists.txt @@ -8,7 +8,7 @@ configure_file( ) set(symbol_map ${CMAKE_CURRENT_BINARY_DIR}/symbols.map) -add_compile_definitions(MIR_LOG_COMPONENT="mir::virtual") +add_compile_definitions(MIR_LOG_COMPONENT="mir:virtual") add_library(mirplatformgraphicsvirtualobjects OBJECT graphics.cpp diff --git a/src/platforms/virtual/graphics.cpp b/src/platforms/virtual/graphics.cpp index 63641d5fd0e..b2a5afcf306 100644 --- a/src/platforms/virtual/graphics.cpp +++ b/src/platforms/virtual/graphics.cpp @@ -36,7 +36,7 @@ mir::ModuleProperties const description = { MIR_VERSION_MICRO, mir::libname() }; -char const* virtual_displays_option_name{"virtual-output"}; +char const* const virtual_displays_option_name{"virtual-output"}; } mir::UniqueModulePtr create_display_platform(