Skip to content

Commit

Permalink
Building implementation of the CRTC-only smooth boot support
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkae committed Sep 6, 2023
1 parent d32e781 commit 06f516c
Show file tree
Hide file tree
Showing 28 changed files with 189 additions and 43 deletions.
46 changes: 46 additions & 0 deletions include/miral/miral/smooth_boot_support.h
Original file line number Diff line number Diff line change
@@ -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 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 <http://www.gnu.org/licenses/>.
*/

#ifndef MIRAL_SMOOTH_BOOT_SUPPORT_H
#define MIRAL_SMOOTH_BOOT_SUPPORT_H

#include <memory>

namespace mir { class Server; }

namespace miral
{

/// Provides a smooth boot transition from the prior screen (such as the plymouth
/// splash or any other DRM-based display) to the compositor.
class SmoothBootSupport
{
public:
void operator()(mir::Server& server) const;

explicit SmoothBootSupport();
~SmoothBootSupport();
SmoothBootSupport(SmoothBootSupport const&);
auto operator=(SmoothBootSupport const&) -> SmoothBootSupport&;

private:
struct Self;
std::shared_ptr<Self> self;
};

}

#endif
3 changes: 2 additions & 1 deletion include/platform/mir/graphics/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,8 @@ class DisplayPlatform : public std::enable_shared_from_this<DisplayPlatform>
*/
virtual UniqueModulePtr<Display> create_display(
std::shared_ptr<DisplayConfigurationPolicy> const& initial_conf_policy,
std::shared_ptr<GLConfig> const& gl_config) = 0;
std::shared_ptr<GLConfig> const& gl_config,
std::shared_ptr<mir::options::Option> const& options) = 0;

static auto interface_for(std::shared_ptr<DisplayPlatform> platform)
-> std::shared_ptr<DisplayInterfaceProvider>
Expand Down
1 change: 1 addition & 0 deletions include/platform/mir/options/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ extern char const* const null_console;
extern char const* const auto_console;

extern char const* const vt_option_name;
extern char const* const smooth_boot_opt;

class Configuration
{
Expand Down
1 change: 1 addition & 0 deletions src/miral/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ add_library(miral SHARED
window_specification.cpp ${miral_include}/miral/window_specification.h
internal_client.cpp ${miral_include}/miral/internal_client.h
prepend_event_filter.cpp ${miral_include}/miral/prepend_event_filter.h
smooth_boot_support.cpp ${miral_include}/miral/smooth_boot_support.h
set_command_line_handler.cpp ${miral_include}/miral/set_command_line_handler.h
set_terminator.cpp ${miral_include}/miral/set_terminator.h
set_window_management_policy.cpp ${miral_include}/miral/set_window_management_policy.h
Expand Down
46 changes: 46 additions & 0 deletions src/miral/smooth_boot_support.cpp
Original file line number Diff line number Diff line change
@@ -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 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 <http://www.gnu.org/licenses/>.
*/

#include "miral/smooth_boot_support.h"
#include <mir/server.h>
#include <mir/options/configuration.h>
#include <stdexcept>

namespace mg = mir::graphics;
namespace mo = mir::options;

struct miral::SmoothBootSupport::Self
{
};

miral::SmoothBootSupport::SmoothBootSupport()
: self{std::make_shared<Self>()}
{
}

miral::SmoothBootSupport::~SmoothBootSupport() = default;
miral::SmoothBootSupport::SmoothBootSupport(SmoothBootSupport const& other) = default;
auto miral::SmoothBootSupport::operator=(miral::SmoothBootSupport const& other) -> SmoothBootSupport& = default;

void miral::SmoothBootSupport::operator()(mir::Server &server) const
{
server.add_configuration_option(
mo::smooth_boot_opt,
"When set, provides a transition from the previous screen to the compositor",
true
);
}
5 changes: 5 additions & 0 deletions src/miral/symbols.map
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ global:
extern "C++" {
miral::WaylandExtensions::zwp_input_method_v1*;
miral::WaylandExtensions::zwp_input_panel_v1*;
miral::SmoothBootSupport::?SmoothBootSupport*;
miral::SmoothBootSupport::SmoothBootSupport*;
miral::SmoothBootSupport::operator*;
typeinfo?for?miral::SmoothBootSupport;
vtable?for?miral::SmoothBootSupport;
};

} MIRAL_4.0;
Expand Down
1 change: 1 addition & 0 deletions src/platform/options/default_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ char const* const mo::null_console = "none";
char const* const mo::auto_console = "auto";

char const* const mo::vt_option_name = "vt";
char const* const mo::smooth_boot_opt = "smooth-boot";


namespace
Expand Down
1 change: 1 addition & 0 deletions src/platform/symbols.map
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,6 @@ MIR_PLATFORM_2.13 {
global:
extern "C++" {
mir::graphics::DRMFormat::from_mir_format*;
mir::options::smooth_boot_opt*;
};
} MIR_PLATFORM_2.11;
9 changes: 6 additions & 3 deletions src/platforms/gbm-kms/server/kms/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ mgg::Display::Display(
mir::Fd drm_fd,
mgg::BypassOption bypass_option,
std::shared_ptr<DisplayConfigurationPolicy> const& initial_conf_policy,
std::shared_ptr<DisplayReport> const& listener)
std::shared_ptr<DisplayReport> const& listener,
bool smooth_transition)
: owner{std::move(parent)},
drm_fd{std::move(drm_fd)},
listener(listener),
Expand All @@ -159,7 +160,8 @@ mgg::Display::Display(
std::make_shared<KMSPageFlipper>(this->drm_fd, listener))},
current_display_configuration{output_container},
dirty_configuration{false},
bypass_option(bypass_option)
bypass_option(bypass_option),
smooth_transition{smooth_transition}
{
monitor.filter_by_subsystem_and_type("drm", "drm_minor");
monitor.enable();
Expand Down Expand Up @@ -428,7 +430,8 @@ void mgg::Display::configure_locked(
listener,
kms_outputs,
bounding_rect,
transformation);
transformation,
smooth_transition);

display_buffers_new.push_back(std::move(db));
}
Expand Down
4 changes: 3 additions & 1 deletion src/platforms/gbm-kms/server/kms/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class Display : public graphics::Display
mir::Fd drm_fd,
BypassOption bypass_option,
std::shared_ptr<DisplayConfigurationPolicy> const& initial_conf_policy,
std::shared_ptr<DisplayReport> const& listener);
std::shared_ptr<DisplayReport> const& listener,
bool smooth_boot);
~Display();

geometry::Rectangle view_area() const;
Expand Down Expand Up @@ -102,6 +103,7 @@ class Display : public graphics::Display

BypassOption bypass_option;
std::weak_ptr<Cursor> cursor;
bool smooth_transition;
};

class CPUAddressableDisplayProvider : public graphics::CPUAddressableDisplayProvider
Expand Down
33 changes: 18 additions & 15 deletions src/platforms/gbm-kms/server/kms/display_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ mgg::DisplayBuffer::DisplayBuffer(
std::shared_ptr<DisplayReport> const& listener,
std::vector<std::shared_ptr<KMSOutput>> const& outputs,
geom::Rectangle const& area,
glm::mat2 const& transformation)
glm::mat2 const& transformation,
bool smooth_transition)
: provider{std::move(provider)},
listener(listener),
outputs(outputs),
Expand All @@ -63,22 +64,24 @@ mgg::DisplayBuffer::DisplayBuffer(
{
listener->report_successful_setup_of_native_resources();

// TODO: Pull a supported format out of KMS rather than assuming XRGB8888
auto initial_fb = std::make_shared<mgg::CPUAddressableFB>(
std::move(drm_fd),
false,
DRMFormat{DRM_FORMAT_XRGB8888},
area.size);

auto mapping = initial_fb->map_writeable();
::memset(mapping->data(), 24, mapping->len());

visible_fb = std::move(initial_fb);
for (auto& output : outputs)
if (!smooth_transition)
{
output->set_crtc(*visible_fb);
// TODO: Pull a supported format out of KMS rather than assuming XRGB8888
auto initial_fb = std::make_shared<mgg::CPUAddressableFB>(
std::move(drm_fd),
false,
DRMFormat{DRM_FORMAT_XRGB8888},
area.size);

auto mapping = initial_fb->map_writeable();
::memset(mapping->data(), 24, mapping->len());

visible_fb = std::move(initial_fb);
for (auto &output: outputs) {
output->set_crtc(*visible_fb);
}
listener->report_successful_drm_mode_set_crtc_on_construction();
}
listener->report_successful_drm_mode_set_crtc_on_construction();
listener->report_successful_display_construction();
}

Expand Down
3 changes: 2 additions & 1 deletion src/platforms/gbm-kms/server/kms/display_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class DisplayBuffer : public graphics::DisplayBuffer,
std::shared_ptr<DisplayReport> const& listener,
std::vector<std::shared_ptr<KMSOutput>> const& outputs,
geometry::Rectangle const& area,
glm::mat2 const& transformation);
glm::mat2 const& transformation,
bool smooth_transition);
~DisplayBuffer();

geometry::Rectangle view_area() const override;
Expand Down
10 changes: 8 additions & 2 deletions src/platforms/gbm-kms/server/kms/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "mir/graphics/egl_error.h"
#include "mir/graphics/egl_extensions.h"
#include "one_shot_device_observer.h"
#include "mir/options/configuration.h"
#include "mir/options/option.h"
#include <gbm.h>

#define MIR_LOG_COMPONENT "platform-graphics-gbm-kms"
Expand Down Expand Up @@ -296,14 +298,18 @@ class mgg::Platform::KMSDisplayInterfaceProvider : public mg::DisplayInterfacePr
};

mir::UniqueModulePtr<mg::Display> mgg::Platform::create_display(
std::shared_ptr<DisplayConfigurationPolicy> const& initial_conf_policy, std::shared_ptr<GLConfig> const&)
std::shared_ptr<DisplayConfigurationPolicy> const& initial_conf_policy,
std::shared_ptr<GLConfig> const&,
std::shared_ptr<mir::options::Option> const& options)
{
auto smooth_boot = options->is_set(options::smooth_boot_opt);
return make_module_ptr<mgg::Display>(
provider,
drm_fd,
bypass_option_,
initial_conf_policy,
listener);
listener,
smooth_boot);
}

auto mgg::Platform::interface_for() -> std::shared_ptr<DisplayInterfaceProvider>
Expand Down
3 changes: 2 additions & 1 deletion src/platforms/gbm-kms/server/kms/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class Platform : public graphics::DisplayPlatform
/* From Platform */
UniqueModulePtr<graphics::Display> create_display(
std::shared_ptr<DisplayConfigurationPolicy> const& initial_conf_policy,
std::shared_ptr<GLConfig> const& gl_config) override;
std::shared_ptr<GLConfig> const& gl_config,
std::shared_ptr<mir::options::Option> const& options) override;

std::shared_ptr<mir::udev::Context> udev;

Expand Down
3 changes: 2 additions & 1 deletion src/platforms/wayland/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ mgw::Platform::Platform(struct wl_display* const wl_display, std::shared_ptr<mg:

mir::UniqueModulePtr<mg::Display> mgw::Platform::create_display(
std::shared_ptr<DisplayConfigurationPolicy> const&,
std::shared_ptr<GLConfig> const& gl_config)
std::shared_ptr<GLConfig> const& gl_config,
std::shared_ptr<mir::options::Option> const&)
{
return mir::make_module_ptr<mgw::Display>(wl_display, gl_config, report);
}
Expand Down
3 changes: 2 additions & 1 deletion src/platforms/wayland/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class Platform : public graphics::DisplayPlatform

UniqueModulePtr<Display> create_display(
std::shared_ptr<DisplayConfigurationPolicy> const& initial_conf_policy,
std::shared_ptr<GLConfig> const& gl_config) override;
std::shared_ptr<GLConfig> const& gl_config,
std::shared_ptr<mir::options::Option> const& options) override;

protected:
auto interface_for() -> std::shared_ptr<DisplayInterfaceProvider> override;
Expand Down
3 changes: 2 additions & 1 deletion src/platforms/x11/graphics/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ mgx::Platform::Platform(std::shared_ptr<mir::X::X11Resources> const& x11_resourc

mir::UniqueModulePtr<mg::Display> mgx::Platform::create_display(
std::shared_ptr<DisplayConfigurationPolicy> const& initial_conf_policy,
std::shared_ptr<GLConfig> const& /*gl_config*/)
std::shared_ptr<GLConfig> const& /*gl_config*/,
std::shared_ptr<mir::options::Option> const& /*options*/)
{
return make_module_ptr<mgx::Display>(
std::dynamic_pointer_cast<Platform>(shared_from_this()),
Expand Down
3 changes: 2 additions & 1 deletion src/platforms/x11/graphics/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class Platform : public graphics::DisplayPlatform
/* From Platform */
auto create_display(
std::shared_ptr<DisplayConfigurationPolicy> const& initial_conf_policy,
std::shared_ptr<GLConfig> const& gl_config) -> UniqueModulePtr<graphics::Display> override;
std::shared_ptr<GLConfig> const& gl_config,
std::shared_ptr<mir::options::Option> const& options) -> UniqueModulePtr<graphics::Display> override;

auto provider_for_window(xcb_window_t x_win) -> std::shared_ptr<DisplayInterfaceProvider>;
protected:
Expand Down
3 changes: 2 additions & 1 deletion src/server/graphics/default_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ mir::DefaultServerConfiguration::the_display()
displays.push_back(
platform->create_display(
the_display_configuration_policy(),
the_gl_config()));
the_gl_config(),
the_options()));
}
return std::make_shared<mg::MultiplexingDisplay>(
std::move(displays),
Expand Down
3 changes: 2 additions & 1 deletion tests/include/mir/test/doubles/null_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class NullDisplayPlatform : public graphics::DisplayPlatform
public:
auto create_display(
std::shared_ptr<graphics::DisplayConfigurationPolicy> const&,
std::shared_ptr<graphics::GLConfig> const&) -> mir::UniqueModulePtr<graphics::Display> override
std::shared_ptr<graphics::GLConfig> const&,
std::shared_ptr<mir::options::Option> const&) -> mir::UniqueModulePtr<graphics::Display> override
{
return mir::make_module_ptr<NullDisplay>();
}
Expand Down
5 changes: 3 additions & 2 deletions tests/mir_test_framework/platform_graphics_throw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@ class ExceptionThrowingPlatform : public mg::DisplayPlatform, public mg::Renderi

mir::UniqueModulePtr<mg::Display> create_display(
std::shared_ptr<mg::DisplayConfigurationPolicy> const& ptr,
std::shared_ptr<mg::GLConfig> const& shared_ptr) override
std::shared_ptr<mg::GLConfig> const& gl_config,
std::shared_ptr<mir::options::Option> const& options) override
{
if (should_throw.at(ExceptionLocation::at_create_display))
BOOST_THROW_EXCEPTION(std::runtime_error("Exception during create_display"));

return stub_display_platform->create_display(ptr, shared_ptr);
return stub_display_platform->create_display(ptr, gl_config, options);
}

private:
Expand Down
3 changes: 2 additions & 1 deletion tests/mir_test_framework/stubbed_graphics_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ std::unique_ptr<mg::Display> display_preset;

mir::UniqueModulePtr<mg::Display> mtf::StubGraphicPlatform::create_display(
std::shared_ptr<mg::DisplayConfigurationPolicy> const&,
std::shared_ptr<mg::GLConfig> const&)
std::shared_ptr<mg::GLConfig> const&,
std::shared_ptr<mir::options::Option> const&)
{
if (display_preset)
{
Expand Down
3 changes: 2 additions & 1 deletion tests/mir_test_framework/stubbed_graphics_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class StubGraphicPlatform :

mir::UniqueModulePtr<mir::graphics::Display> create_display(
std::shared_ptr<mir::graphics::DisplayConfigurationPolicy> const&,
std::shared_ptr<mir::graphics::GLConfig> const&) override;
std::shared_ptr<mir::graphics::GLConfig> const&,
std::shared_ptr<mir::options::Option> const&) override;

protected:
auto maybe_create_interface(
Expand Down
Loading

0 comments on commit 06f516c

Please sign in to comment.