Skip to content

Commit

Permalink
Cleaing the initial renders after 5 seconds, woohoo!
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkae committed Sep 1, 2023
1 parent 651b1a2 commit a93b6c9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/include/server/mir/default_server_configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ class DefaultServerConfiguration : public virtual ServerConfiguration
display_configuration_observer_multiplexer;
CachedPtr<ObserverMultiplexer<input::SeatObserver>>
seat_observer_multiplexer;
CachedPtr<graphics::InitialRenderManager> initial_render_manager;
std::shared_ptr<graphics::InitialRenderManager> initial_render_manager;

// The following caches and factory functions are internal to the
// default implementations of corresponding the Mir components
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ class DefaultInitialRenderManager : public InitialRenderManager
void add_initial_render(std::shared_ptr<InitialRender> const&) override;

private:
void remove_renderables();
std::shared_ptr<time::Clock> const& clock;
time::AlarmFactory& alarm_factory;
std::shared_ptr<input::Scene>& scene;
std::vector<std::shared_ptr<InitialRender>> renderable_list;
std::unique_ptr<time::Alarm> const alarm;
};

}
Expand Down
16 changes: 6 additions & 10 deletions src/server/graphics/default_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,14 +504,10 @@ mir::DefaultServerConfiguration::the_display_configuration_observer()
std::shared_ptr<mg::InitialRenderManager>
mir::DefaultServerConfiguration::the_initial_render_manager(mg::Display& in_display)
{
return initial_render_manager(
[display = &in_display, this]
{
auto in_input_scene = the_input_scene();
auto in_main_loop = the_main_loop();
auto in_clock = the_clock();
auto render_manager = std::make_shared<mg::DefaultInitialRenderManager>(in_clock, *in_main_loop, in_input_scene);
render_manager->add_initial_render(display->create_initial_render());
return render_manager;
});
auto in_input_scene = the_input_scene();
auto in_main_loop = the_main_loop();
auto in_clock = the_clock();
initial_render_manager = std::make_shared<mg::DefaultInitialRenderManager>(in_clock, *in_main_loop, in_input_scene);
initial_render_manager->add_initial_render(in_display.create_initial_render());
return initial_render_manager;
}
26 changes: 22 additions & 4 deletions src/server/graphics/default_initial_render_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

#include "mir/graphics/default_initial_render_manager.h"
#include "mir/input/scene.h"
#include "mir/time/alarm_factory.h"
#include "mir/time/clock.h"
#include <chrono>

namespace mg = mir::graphics;

Expand All @@ -24,15 +27,18 @@ mg::DefaultInitialRenderManager::DefaultInitialRenderManager(
time::AlarmFactory &alarm_factory,
std::shared_ptr<input::Scene>& scene)
: clock{clock},
alarm_factory{alarm_factory},
scene{scene}
scene{scene},
alarm{alarm_factory.create_alarm([&]{
remove_renderables();
alarm->cancel();
})}
{

time::Timestamp scheduled_time = clock->now() + std::chrono::seconds {5};
alarm->reschedule_for(scheduled_time);
}

mg::DefaultInitialRenderManager::~DefaultInitialRenderManager()
{

}

void mg::DefaultInitialRenderManager::add_initial_render(std::shared_ptr<InitialRender> const& initial_render)
Expand All @@ -45,4 +51,16 @@ void mg::DefaultInitialRenderManager::add_initial_render(std::shared_ptr<Initial
scene->add_input_visualization(renderable);
}
renderable_list.push_back(initial_render);
}

void mg::DefaultInitialRenderManager::remove_renderables()
{
for (auto inital_render : renderable_list)
{
for (auto const& renderable : inital_render->get_renderables())
{
scene->remove_input_visualization(renderable);
}
}
renderable_list.clear();
}

0 comments on commit a93b6c9

Please sign in to comment.