Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: renderer now gathers its data from an intermediary list instead of reaching out to the container and its surrounding objects #349

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ add_library(miracle-wm-implementation
src/miracle_gl_config.cpp
src/ipc_command.cpp
src/ipc_command_executor.cpp
src/surface_tracker.cpp
src/render_data_manager.cpp
src/window_tools_accessor.cpp
src/animator.cpp
src/animation_definition.cpp
Expand Down
10 changes: 10 additions & 0 deletions src/compositor_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

using namespace miracle;

CompositorState::CompositorState() :
render_data_manager_(std::make_unique<RenderDataManager>())
{
}

std::shared_ptr<Container> CompositorState::focused_container() const
{
if (!focused.expired())
Expand Down Expand Up @@ -116,3 +121,8 @@ void CompositorState::mode(WindowManagerMode next)
{
mode_ = next;
}

RenderDataManager* CompositorState::render_data_manager() const
{
return render_data_manager_.get();
}
4 changes: 4 additions & 0 deletions src/compositor_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define MIRACLE_WM_COMPOSITOR_STATE_H

#include "container.h"
#include "render_data_manager.h"

#include <algorithm>
#include <memory>
Expand Down Expand Up @@ -48,6 +49,7 @@ enum class WindowManagerMode
class CompositorState
{
public:
CompositorState();
mir::geometry::Point cursor_position;
uint32_t modifiers = 0;
bool has_clicked_floating_window = false;
Expand All @@ -68,12 +70,14 @@ class CompositorState
[[nodiscard]] std::vector<std::weak_ptr<Container>> const& containers() const { return focus_order; }
WindowManagerMode mode() const;
void mode(WindowManagerMode);
RenderDataManager* render_data_manager() const;

private:
std::weak_ptr<Container> focused;
std::vector<std::weak_ptr<Container>> focus_order;
std::weak_ptr<Output> output;
WindowManagerMode mode_ = WindowManagerMode::normal;
std::unique_ptr<RenderDataManager> render_data_manager_;
};
}

Expand Down
13 changes: 12 additions & 1 deletion src/floating_window_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

#include "mir_toolkit/common.h"
#define MIR_LOG_COMPONENT "floating_container"
#define GLM_ENABLE_EXPERIMENTAL

#include "compositor_state.h"
#include "config.h"
#include "floating_window_container.h"
#include "leaf_container.h"
#include "output.h"
#include "render_data_manager.h"
#include "workspace.h"

#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/transform.hpp>
#include <mir/log.h>
#include <mir/scene/session.h>
Expand Down Expand Up @@ -65,6 +66,12 @@ FloatingWindowContainer::FloatingWindowContainer(
state { state },
config { config }
{
state.render_data_manager()->add(*this);
}

FloatingWindowContainer::~FloatingWindowContainer()
{
state.render_data_manager()->remove(*this);
}

void FloatingWindowContainer::commit_changes()
Expand Down Expand Up @@ -148,11 +155,13 @@ void FloatingWindowContainer::on_focus_gained()
return;

wm->advise_focus_gained(window_controller.info_for(window_));
state.render_data_manager()->focus_change(*this);
}

void FloatingWindowContainer::on_focus_lost()
{
wm->advise_focus_lost(window_controller.info_for(window_));
state.render_data_manager()->focus_change(*this);
}

void FloatingWindowContainer::on_move_to(geom::Point const& top_left)
Expand Down Expand Up @@ -254,6 +263,7 @@ Workspace* FloatingWindowContainer::get_workspace() const
void FloatingWindowContainer::set_workspace(Workspace* workspace)
{
workspace_ = workspace;
state.render_data_manager()->workspace_transform_change(*this);
}

Output* FloatingWindowContainer::get_output() const
Expand All @@ -275,6 +285,7 @@ void FloatingWindowContainer::set_transform(glm::mat4 transform_)
{
surface->set_transformation(transform_);
transform = transform_;
state.render_data_manager()->transform_change(*this);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/floating_window_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace miracle
{
class WindowController;
class CompositorState;
class RenderDataManager;

enum class ScratchpadState
{
Expand All @@ -45,6 +46,7 @@ class FloatingWindowContainer : public Container
Workspace* workspace,
CompositorState const& state,
std::shared_ptr<Config> const&);
~FloatingWindowContainer();
[[nodiscard]] mir::geometry::Rectangle get_logical_area() const override;
void set_logical_area(mir::geometry::Rectangle const&) override;
void commit_changes() override;
Expand Down
15 changes: 14 additions & 1 deletion src/leaf_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "container_group_container.h"
#include "output.h"
#include "parent_container.h"
#include "render_data_manager.h"
#include "tiling_window_tree.h"
#include "window_helpers.h"
#include "workspace.h"
Expand Down Expand Up @@ -51,9 +52,15 @@ LeafContainer::LeafContainer(
{
}

LeafContainer::~LeafContainer()
{
state.render_data_manager()->remove(*this);
}

void LeafContainer::associate_to_window(miral::Window const& in_window)
{
window_ = in_window;
state.render_data_manager()->add(*this);
}

geom::Rectangle LeafContainer::get_logical_area() const
Expand Down Expand Up @@ -228,10 +235,12 @@ void LeafContainer::on_open()
void LeafContainer::on_focus_gained()
{
tree_->advise_focus_gained(*this);
state.render_data_manager()->focus_change(*this);
}

void LeafContainer::on_focus_lost()
{
state.render_data_manager()->focus_change(*this);
}

void LeafContainer::on_move_to(geom::Point const&)
Expand Down Expand Up @@ -299,6 +308,7 @@ TilingWindowTree* LeafContainer::tree() const
void LeafContainer::tree(TilingWindowTree* in)
{
tree_ = in;
state.render_data_manager()->workspace_transform_change(*this);
}

Workspace* LeafContainer::get_workspace() const
Expand All @@ -308,7 +318,9 @@ Workspace* LeafContainer::get_workspace() const

Output* LeafContainer::get_output() const
{
return get_workspace()->get_output();
if (auto workspace = get_workspace())
return workspace->get_output();
return nullptr;
}

glm::mat4 LeafContainer::get_transform() const
Expand All @@ -322,6 +334,7 @@ void LeafContainer::set_transform(glm::mat4 transform_)
{
surface->set_transformation(transform_);
transform = transform_;
state.render_data_manager()->transform_change(*this);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/leaf_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace miracle
class Config;
class TilingWindowTree;
class CompositorState;
class RenderDataManager;

/// A [LeafContainer] always contains a single window.
class LeafContainer : public Container
Expand All @@ -45,6 +46,7 @@ class LeafContainer : public Container
TilingWindowTree* tree,
std::shared_ptr<ParentContainer> const& parent,
CompositorState const& state);
~LeafContainer();

void associate_to_window(miral::Window const&);
[[nodiscard]] geom::Rectangle get_logical_area() const override;
Expand Down
7 changes: 3 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "config.h"
#include "miracle_gl_config.h"
#include "policy.h"
#include "render_data_manager.h"
#include "renderer.h"
#include "surface_tracker.h"
#include "version.h"
#include "window_tools_accessor.h"

Expand Down Expand Up @@ -71,7 +71,6 @@ int main(int argc, char const* argv[])

ExternalClientLauncher external_client_launcher;
miracle::AutoRestartingLauncher auto_restarting_launcher(runner, external_client_launcher);
miracle::SurfaceTracker surface_tracker;
auto config = std::make_shared<miracle::FilesystemConfiguration>(runner);
auto animator = std::make_shared<miracle::Animator>();
for (auto const& env : config->get_env_variables())
Expand All @@ -87,7 +86,7 @@ int main(int argc, char const* argv[])
config->load(server);
options = new WindowManagerOptions {
add_window_manager_policy<miracle::Policy>(
"tiling", auto_restarting_launcher, runner, config, animator, surface_tracker, server, compositor_state, accessor)
"tiling", auto_restarting_launcher, runner, config, animator, server, compositor_state, accessor)
};
(*options)(server);
});
Expand Down Expand Up @@ -121,7 +120,7 @@ int main(int argc, char const* argv[])
}),
CustomRenderer([&](std::unique_ptr<mir::graphics::gl::OutputSurface> x, std::shared_ptr<mir::graphics::GLRenderingProvider> y)
{
return std::make_unique<miracle::Renderer>(std::move(y), std::move(x), config, surface_tracker, compositor_state, accessor, animator);
return std::make_unique<miracle::Renderer>(std::move(y), std::move(x), config, compositor_state, accessor, animator);
}),
miroil::OpenGLContext(new miracle::GLConfig()) });
}
6 changes: 3 additions & 3 deletions src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ bool MiralWrapperOutput::advise_workspace_active(uint32_t id)
set_position(glm::vec2(
-to_rectangle.top_left.x.as_int(),
-to_rectangle.top_left.y.as_int()));
to->trigger_rerender();
to->workspace_transform_change_hack();
return true;
}

Expand Down Expand Up @@ -303,7 +303,7 @@ void MiralWrapperOutput::on_workspace_animation(
workspace->hide();
}

to->trigger_rerender();
to->workspace_transform_change_hack();
return;
}

Expand All @@ -313,7 +313,7 @@ void MiralWrapperOutput::on_workspace_animation(
set_transform(asr.transform.value());

for (auto const& workspace : workspaces)
workspace->trigger_rerender();
workspace->workspace_transform_change_hack();
}

void MiralWrapperOutput::advise_application_zone_create(miral::Zone const& application_zone)
Expand Down
6 changes: 0 additions & 6 deletions src/policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,12 @@ Policy::Policy(
miral::MirRunner& runner,
std::shared_ptr<Config> const& config,
std::shared_ptr<Animator> const& animator,
SurfaceTracker& surface_tracker,
mir::Server const& server,
CompositorState& compositor_state,
std::shared_ptr<WindowToolsAccessor> const& window_tools_accessor) :
external_client_launcher { external_client_launcher },
config { config },
animator { animator },
surface_tracker { surface_tracker },
state { compositor_state },
floating_window_manager(std::make_unique<MinimalWindowManager>(tools, config)),
animator_loop(std::make_unique<ThreadedAnimatorLoop>(animator)),
Expand Down Expand Up @@ -393,7 +391,6 @@ void Policy::advise_new_window(miral::WindowInfo const& window_info)
// windows are considered to be in the "other" category until
// we have more data on them.
orphaned_window_list.push_back(window);
surface_tracker.add(window);
}

return;
Expand All @@ -405,7 +402,6 @@ void Policy::advise_new_window(miral::WindowInfo const& window_info)
state.add(container);

pending_allocation.container_type = ContainerType::none;
surface_tracker.add(window_info.window());
}

void Policy::handle_window_ready(miral::WindowInfo& window_info)
Expand Down Expand Up @@ -501,7 +497,6 @@ void Policy::advise_delete_window(const miral::WindowInfo& window_info)
if (*it == window_info.window())
{
orphaned_window_list.erase(it);
surface_tracker.remove(window_info.window());
return;
}
}
Expand All @@ -519,7 +514,6 @@ void Policy::advise_delete_window(const miral::WindowInfo& window_info)
scratchpad_.remove(container);

animator->remove_by_animation_handle(container->animation_handle());
surface_tracker.remove(window_info.window());
if (container == state.focused_container())
state.unfocus_container(container);

Expand Down
3 changes: 0 additions & 3 deletions src/policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "mode_observer.h"
#include "output.h"
#include "scratchpad.h"
#include "surface_tracker.h"
#include "window_manager_tools_window_controller.h"
#include "workspace_manager.h"

Expand Down Expand Up @@ -61,7 +60,6 @@ class Policy : public miral::WindowManagementPolicy
miral::MirRunner&,
std::shared_ptr<Config> const&,
std::shared_ptr<Animator> const&,
SurfaceTracker&,
mir::Server const&,
CompositorState&,
std::shared_ptr<WindowToolsAccessor> const&);
Expand Down Expand Up @@ -107,7 +105,6 @@ class Policy : public miral::WindowManagementPolicy
AutoRestartingLauncher& external_client_launcher;
std::shared_ptr<Config> config;
std::shared_ptr<Animator> animator;
SurfaceTracker& surface_tracker;
CompositorState& state;

bool is_starting_ = true;
Expand Down
Loading
Loading