Skip to content

Commit

Permalink
WindowServer: Add initial support for rendering on multiple screens
Browse files Browse the repository at this point in the history
This allows WindowServer to use multiple framebuffer devices and
compose the desktop with any arbitrary layout. Currently, it is assumed
that it is configured contiguous and non-overlapping, but this should
eventually be enforced.

To make rendering efficient, each window now also tracks on which
screens it needs to be rendered. This way we don't have to iterate all
the windows for each screen but instead use the same rendering loop and
then only render to the screen (or screens) that the window actually
uses.
  • Loading branch information
tomuta authored and awesomekling committed Jun 20, 2021
1 parent 499c33a commit 4392da9
Show file tree
Hide file tree
Showing 42 changed files with 1,123 additions and 559 deletions.
8 changes: 7 additions & 1 deletion Base/etc/WindowServer.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
[Screen]
[Screens]
MainScreen=0

[Screen0]
Device=/dev/fb0
Left=0
Top=0
Width=1024
Height=768
ScaleFactor=1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ void MonitorSettingsWidget::apply_settings()
}

if (current_resolution != m_monitor_widget->desktop_resolution() || current_scale_factor != m_monitor_widget->desktop_scale_factor()) {
auto result = GUI::WindowServerConnection::the().set_resolution(m_monitor_widget->desktop_resolution(), m_monitor_widget->desktop_scale_factor());
u32 display_index = 0; // TODO: implement multiple display support
auto result = GUI::WindowServerConnection::the().set_resolution(display_index, m_monitor_widget->desktop_resolution(), m_monitor_widget->desktop_scale_factor());
if (!result.success()) {
GUI::MessageBox::show(nullptr, String::formatted("Reverting to resolution {}x{} @ {}x", result.resolution().width(), result.resolution().height(), result.scale_factor()),
"Unable to set resolution", GUI::MessageBox::Type::Error);
Expand All @@ -134,7 +135,7 @@ void MonitorSettingsWidget::apply_settings()

// If the user selects "No", closes the window or the window gets closed by the 10 seconds timer, revert the changes.
if (box->exec() != GUI::MessageBox::ExecYes) {
result = GUI::WindowServerConnection::the().set_resolution(current_resolution, current_scale_factor);
result = GUI::WindowServerConnection::the().set_resolution(display_index, current_resolution, current_scale_factor);
if (!result.success()) {
GUI::MessageBox::show(nullptr, String::formatted("Reverting to resolution {}x{} @ {}x", result.resolution().width(), result.resolution().height(), result.scale_factor()),
"Unable to set resolution", GUI::MessageBox::Type::Error);
Expand Down
14 changes: 10 additions & 4 deletions Userland/Libraries/LibGUI/Desktop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ Desktop::Desktop()
{
}

void Desktop::did_receive_screen_rect(Badge<WindowServerConnection>, const Gfx::IntRect& rect)
void Desktop::did_receive_screen_rects(Badge<WindowServerConnection>, const Vector<Gfx::IntRect, 4>& rects, size_t main_screen_index)
{
if (m_rect == rect)
return;
m_rect = rect;
m_main_screen_index = main_screen_index;
m_rects = rects;
if (!m_rects.is_empty()) {
m_bounding_rect = m_rects[0];
for (size_t i = 1; i < m_rects.size(); i++)
m_bounding_rect = m_bounding_rect.united(m_rects[i]);
} else {
m_bounding_rect = {};
}
}

void Desktop::set_background_color(const StringView& background_color)
Expand Down
10 changes: 7 additions & 3 deletions Userland/Libraries/LibGUI/Desktop.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@ class Desktop {
String wallpaper() const;
bool set_wallpaper(const StringView& path, bool save_config = true);

Gfx::IntRect rect() const { return m_rect; }
Gfx::IntRect rect() const { return m_bounding_rect; }
const Vector<Gfx::IntRect, 4>& rects() const { return m_rects; }
size_t main_screen_index() const { return m_main_screen_index; }

int taskbar_height() const { return TaskbarWindow::taskbar_height(); }

void did_receive_screen_rect(Badge<WindowServerConnection>, const Gfx::IntRect&);
void did_receive_screen_rects(Badge<WindowServerConnection>, const Vector<Gfx::IntRect, 4>&, size_t);

private:
Gfx::IntRect m_rect;
Vector<Gfx::IntRect, 4> m_rects;
size_t m_main_screen_index { 0 };
Gfx::IntRect m_bounding_rect;
};

}
17 changes: 10 additions & 7 deletions Userland/Libraries/LibGUI/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Event : public Core::Event {
DragMove,
Drop,
ThemeChange,
ScreenRectChange,
ScreenRectsChange,
ActionEnter,
ActionLeave,

Expand Down Expand Up @@ -392,18 +392,21 @@ class ThemeChangeEvent final : public Event {
}
};

class ScreenRectChangeEvent final : public Event {
class ScreenRectsChangeEvent final : public Event {
public:
explicit ScreenRectChangeEvent(const Gfx::IntRect& rect)
: Event(Type::ScreenRectChange)
, m_rect(rect)
explicit ScreenRectsChangeEvent(const Vector<Gfx::IntRect, 4>& rects, size_t main_screen_index)
: Event(Type::ScreenRectsChange)
, m_rects(rects)
, m_main_screen_index(main_screen_index)
{
}

const Gfx::IntRect& rect() const { return m_rect; }
const Vector<Gfx::IntRect, 4>& rects() const { return m_rects; }
size_t main_screen_index() const { return m_main_screen_index; }

private:
Gfx::IntRect m_rect;
Vector<Gfx::IntRect, 4> m_rects;
size_t m_main_screen_index;
};

class FocusEvent final : public Event {
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibGUI/Forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Painter;
class RadioButton;
class ResizeCorner;
class ResizeEvent;
class ScreenRectChangeEvent;
class ScreenRectsChangeEvent;
class Scrollbar;
class AbstractScrollableWidget;
class Slider;
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibGUI/Widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ void Widget::theme_change_event(ThemeChangeEvent&)
{
}

void Widget::screen_rect_change_event(ScreenRectChangeEvent&)
void Widget::screen_rects_change_event(ScreenRectsChangeEvent&)
{
}

Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibGUI/Widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ class Widget : public Core::Object {
virtual void drag_leave_event(Event&);
virtual void drop_event(DropEvent&);
virtual void theme_change_event(ThemeChangeEvent&);
virtual void screen_rect_change_event(ScreenRectChangeEvent&);
virtual void screen_rects_change_event(ScreenRectsChangeEvent&);

virtual void did_begin_inspection() override;
virtual void did_end_inspection() override;
Expand Down
14 changes: 7 additions & 7 deletions Userland/Libraries/LibGUI/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,20 +495,20 @@ void Window::handle_theme_change_event(ThemeChangeEvent& event)
dispatch_theme_change(*m_main_widget.ptr(), dispatch_theme_change);
}

void Window::handle_screen_rect_change_event(ScreenRectChangeEvent& event)
void Window::handle_screen_rects_change_event(ScreenRectsChangeEvent& event)
{
if (!m_main_widget)
return;
auto dispatch_screen_rect_change = [&](auto& widget, auto recursive) {
auto dispatch_screen_rects_change = [&](auto& widget, auto recursive) {
widget.dispatch_event(event, this);
widget.for_each_child_widget([&](auto& widget) -> IterationDecision {
widget.dispatch_event(event, this);
recursive(widget, recursive);
return IterationDecision::Continue;
});
};
dispatch_screen_rect_change(*m_main_widget.ptr(), dispatch_screen_rect_change);
screen_rect_change_event(event);
dispatch_screen_rects_change(*m_main_widget.ptr(), dispatch_screen_rects_change);
screen_rects_change_event(event);
}

void Window::handle_drag_move_event(DragEvent& event)
Expand Down Expand Up @@ -578,8 +578,8 @@ void Window::event(Core::Event& event)
if (event.type() == Event::ThemeChange)
return handle_theme_change_event(static_cast<ThemeChangeEvent&>(event));

if (event.type() == Event::ScreenRectChange)
return handle_screen_rect_change_event(static_cast<ScreenRectChangeEvent&>(event));
if (event.type() == Event::ScreenRectsChange)
return handle_screen_rects_change_event(static_cast<ScreenRectsChangeEvent&>(event));

Core::Object::event(event);
}
Expand Down Expand Up @@ -811,7 +811,7 @@ void Window::wm_event(WMEvent&)
{
}

void Window::screen_rect_change_event(ScreenRectChangeEvent&)
void Window::screen_rects_change_event(ScreenRectsChangeEvent&)
{
}

Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibGUI/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class Window : public Core::Object {
protected:
Window(Core::Object* parent = nullptr);
virtual void wm_event(WMEvent&);
virtual void screen_rect_change_event(ScreenRectChangeEvent&);
virtual void screen_rects_change_event(ScreenRectsChangeEvent&);

private:
void update_cursor();
Expand All @@ -218,7 +218,7 @@ class Window : public Core::Object {
void handle_became_active_or_inactive_event(Core::Event&);
void handle_close_request();
void handle_theme_change_event(ThemeChangeEvent&);
void handle_screen_rect_change_event(ScreenRectChangeEvent&);
void handle_screen_rects_change_event(ScreenRectsChangeEvent&);
void handle_drag_move_event(DragEvent&);
void handle_left_event();

Expand Down
12 changes: 6 additions & 6 deletions Userland/Libraries/LibGUI/WindowServerConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ WindowServerConnection::WindowServerConnection()
// All we have to do is wait for it to arrive. This avoids a round-trip during application startup.
auto message = wait_for_specific_message<Messages::WindowClient::FastGreet>();
set_system_theme_from_anonymous_buffer(message->theme_buffer());
Desktop::the().did_receive_screen_rect({}, message->screen_rect());
Desktop::the().did_receive_screen_rects({}, message->screen_rects(), message->main_screen_index());
Gfx::FontDatabase::set_default_font_query(message->default_font_query());
Gfx::FontDatabase::set_fixed_width_font_query(message->fixed_width_font_query());
}

void WindowServerConnection::fast_greet(Gfx::IntRect const&, Core::AnonymousBuffer const&, String const&, String const&)
void WindowServerConnection::fast_greet(Vector<Gfx::IntRect> const&, u32, Core::AnonymousBuffer const&, String const&, String const&)
{
// NOTE: This message is handled in the constructor.
}
Expand Down Expand Up @@ -311,11 +311,11 @@ void WindowServerConnection::menu_item_left(i32 menu_id, u32 identifier)
Core::EventLoop::current().post_event(*app, make<ActionEvent>(GUI::Event::ActionLeave, *action));
}

void WindowServerConnection::screen_rect_changed(Gfx::IntRect const& rect)
void WindowServerConnection::screen_rects_changed(Vector<Gfx::IntRect> const& rects, u32 main_screen_index)
{
Desktop::the().did_receive_screen_rect({}, rect);
Window::for_each_window({}, [rect](auto& window) {
Core::EventLoop::current().post_event(window, make<ScreenRectChangeEvent>(rect));
Desktop::the().did_receive_screen_rects({}, rects, main_screen_index);
Window::for_each_window({}, [&](auto& window) {
Core::EventLoop::current().post_event(window, make<ScreenRectsChangeEvent>(rects, main_screen_index));
});
}

Expand Down
4 changes: 2 additions & 2 deletions Userland/Libraries/LibGUI/WindowServerConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class WindowServerConnection final
private:
WindowServerConnection();

virtual void fast_greet(Gfx::IntRect const&, Core::AnonymousBuffer const&, String const&, String const&) override;
virtual void fast_greet(Vector<Gfx::IntRect> const&, u32, Core::AnonymousBuffer const&, String const&, String const&) override;
virtual void paint(i32, Gfx::IntSize const&, Vector<Gfx::IntRect> const&) override;
virtual void mouse_move(i32, Gfx::IntPoint const&, u32, u32, u32, i32, bool, Vector<String> const&) override;
virtual void mouse_down(i32, Gfx::IntPoint const&, u32, u32, u32, i32) override;
Expand All @@ -43,7 +43,7 @@ class WindowServerConnection final
virtual void menu_item_entered(i32, u32) override;
virtual void menu_item_left(i32, u32) override;
virtual void menu_visibility_did_change(i32, bool) override;
virtual void screen_rect_changed(Gfx::IntRect const&) override;
virtual void screen_rects_changed(Vector<Gfx::IntRect> const&, u32) override;
virtual void set_wallpaper_finished(bool) override;
virtual void drag_dropped(i32, Gfx::IntPoint const&, String const&, HashMap<String, ByteBuffer> const&) override;
virtual void drag_accepted() override;
Expand Down
6 changes: 3 additions & 3 deletions Userland/Libraries/LibWeb/OutOfProcessWebView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void OutOfProcessWebView::create_client()

client().async_update_system_theme(Gfx::current_system_theme_buffer());
client().async_update_system_fonts(Gfx::FontDatabase::default_font_query(), Gfx::FontDatabase::fixed_width_font_query());
client().async_update_screen_rect(GUI::Desktop::the().rect());
client().async_update_screen_rects(GUI::Desktop::the().rects(), GUI::Desktop::the().main_screen_index());
}

void OutOfProcessWebView::load(const URL& url)
Expand Down Expand Up @@ -192,9 +192,9 @@ void OutOfProcessWebView::theme_change_event(GUI::ThemeChangeEvent& event)
request_repaint();
}

void OutOfProcessWebView::screen_rect_change_event(GUI::ScreenRectChangeEvent& event)
void OutOfProcessWebView::screen_rects_change_event(GUI::ScreenRectsChangeEvent& event)
{
client().async_update_screen_rect(event.rect());
client().async_update_screen_rects(event.rects(), event.main_screen_index());
}

void OutOfProcessWebView::notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id)
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/OutOfProcessWebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class OutOfProcessWebView final
virtual void mousewheel_event(GUI::MouseEvent&) override;
virtual void keydown_event(GUI::KeyEvent&) override;
virtual void theme_change_event(GUI::ThemeChangeEvent&) override;
virtual void screen_rect_change_event(GUI::ScreenRectChangeEvent&) override;
virtual void screen_rects_change_event(GUI::ScreenRectsChangeEvent&) override;

// ^AbstractScrollableWidget
virtual void did_scroll() override;
Expand Down
4 changes: 2 additions & 2 deletions Userland/Services/NotificationServer/NotificationWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ void NotificationWindow::set_image(const Gfx::ShareableBitmap& image)
}
}

void NotificationWindow::screen_rect_change_event(GUI::ScreenRectChangeEvent& event)
void NotificationWindow::screen_rects_change_event(GUI::ScreenRectsChangeEvent& event)
{
update_notification_window_locations(event.rect());
update_notification_window_locations(event.rects()[event.main_screen_index()]);
}

}
2 changes: 1 addition & 1 deletion Userland/Services/NotificationServer/NotificationWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class NotificationWindow final : public GUI::Window {
private:
NotificationWindow(i32 client_id, const String& text, const String& title, const Gfx::ShareableBitmap&);

virtual void screen_rect_change_event(GUI::ScreenRectChangeEvent&) override;
virtual void screen_rects_change_event(GUI::ScreenRectsChangeEvent&) override;

Gfx::IntRect m_original_rect;
i32 m_id;
Expand Down
9 changes: 5 additions & 4 deletions Userland/Services/Taskbar/TaskbarWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ TaskbarWindow::TaskbarWindow(NonnullRefPtr<GUI::Menu> start_menu)
set_window_type(GUI::WindowType::Taskbar);
set_title("Taskbar");

on_screen_rect_change(GUI::Desktop::the().rect());
on_screen_rects_change(GUI::Desktop::the().rects(), GUI::Desktop::the().main_screen_index());

auto& main_widget = set_main_widget<TaskbarWidget>();
main_widget.set_layout<GUI::HorizontalBoxLayout>();
Expand Down Expand Up @@ -148,8 +148,9 @@ void TaskbarWindow::create_quick_launch_bar()
quick_launch_bar.set_fixed_size(total_width, 24);
}

void TaskbarWindow::on_screen_rect_change(const Gfx::IntRect& rect)
void TaskbarWindow::on_screen_rects_change(const Vector<Gfx::IntRect, 4>& rects, size_t main_screen_index)
{
const auto& rect = rects[main_screen_index];
Gfx::IntRect new_rect { rect.x(), rect.bottom() - taskbar_height() + 1, rect.width(), taskbar_height() };
set_rect(new_rect);
update_applet_area();
Expand Down Expand Up @@ -332,7 +333,7 @@ void TaskbarWindow::wm_event(GUI::WMEvent& event)
}
}

void TaskbarWindow::screen_rect_change_event(GUI::ScreenRectChangeEvent& event)
void TaskbarWindow::screen_rects_change_event(GUI::ScreenRectsChangeEvent& event)
{
on_screen_rect_change(event.rect());
on_screen_rects_change(event.rects(), event.main_screen_index());
}
4 changes: 2 additions & 2 deletions Userland/Services/Taskbar/TaskbarWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class TaskbarWindow final : public GUI::Window {
private:
explicit TaskbarWindow(NonnullRefPtr<GUI::Menu> start_menu);
void create_quick_launch_bar();
void on_screen_rect_change(const Gfx::IntRect&);
void on_screen_rects_change(const Vector<Gfx::IntRect, 4>&, size_t);
NonnullRefPtr<GUI::Button> create_button(const WindowIdentifier&);
void add_window_button(::Window&, const WindowIdentifier&);
void remove_window_button(::Window&, bool);
void update_window_button(::Window&, bool);
::Window* find_window_owner(::Window&) const;

virtual void wm_event(GUI::WMEvent&) override;
virtual void screen_rect_change_event(GUI::ScreenRectChangeEvent&) override;
virtual void screen_rects_change_event(GUI::ScreenRectsChangeEvent&) override;

void update_applet_area();

Expand Down
4 changes: 2 additions & 2 deletions Userland/Services/WebContent/ClientConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ void ClientConnection::update_system_fonts(String const& default_font_query, Str
Gfx::FontDatabase::set_fixed_width_font_query(fixed_width_font_query);
}

void ClientConnection::update_screen_rect(const Gfx::IntRect& rect)
void ClientConnection::update_screen_rects(const Vector<Gfx::IntRect>& rects, u32 main_screen)
{
m_page_host->set_screen_rect(rect);
m_page_host->set_screen_rects(rects, main_screen);
}

void ClientConnection::load_url(const URL& url)
Expand Down
2 changes: 1 addition & 1 deletion Userland/Services/WebContent/ClientConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ClientConnection final

virtual void update_system_theme(Core::AnonymousBuffer const&) override;
virtual void update_system_fonts(String const&, String const&) override;
virtual void update_screen_rect(Gfx::IntRect const&) override;
virtual void update_screen_rects(Vector<Gfx::IntRect> const&, u32) override;
virtual void load_url(URL const&) override;
virtual void load_html(String const&, URL const&) override;
virtual void paint(Gfx::IntRect const&, i32) override;
Expand Down
2 changes: 1 addition & 1 deletion Userland/Services/WebContent/PageHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PageHost final : public Web::PageClient {

void set_palette_impl(const Gfx::PaletteImpl&);
void set_viewport_rect(const Gfx::IntRect&);
void set_screen_rect(const Gfx::IntRect& rect) { m_screen_rect = rect; };
void set_screen_rects(const Vector<Gfx::IntRect, 4>& rects, size_t main_screen_index) { m_screen_rect = rects[main_screen_index]; };

void set_should_show_line_box_borders(bool b) { m_should_show_line_box_borders = b; }

Expand Down
2 changes: 1 addition & 1 deletion Userland/Services/WebContent/WebContentServer.ipc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ endpoint WebContentServer
{
update_system_theme(Core::AnonymousBuffer theme_buffer) =|
update_system_fonts(String default_font_query, String fixed_width_font_query) =|
update_screen_rect(Gfx::IntRect rect) =|
update_screen_rects(Vector<Gfx::IntRect> rects, u32 main_screen_index) =|

load_url(URL url) =|
load_html(String html, URL url) =|
Expand Down
Loading

0 comments on commit 4392da9

Please sign in to comment.