From 0a98964600fffc97cfe904432be29ec13b6e91a5 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 12 Jun 2021 11:55:13 +0200 Subject: [PATCH] WindowServer+LibGUI: Make window creation asynchronous :^) Let clients manage their own window ID's. If you try to create a new window with an existing ID, WindowServer will simply disconnect you for misbehaving. This removes the need for window creation to be synchronous, which means that most GUI applications can now batch their entire GUI initialization sequence without having to block waiting for responses. --- Userland/Libraries/LibGUI/Window.cpp | 7 ++++++- Userland/Services/WindowServer/ClientConnection.cpp | 13 ++++++++----- Userland/Services/WindowServer/ClientConnection.h | 4 +--- Userland/Services/WindowServer/WindowServer.ipc | 3 ++- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Userland/Libraries/LibGUI/Window.cpp b/Userland/Libraries/LibGUI/Window.cpp index 02622d6c98..96fbdd0338 100644 --- a/Userland/Libraries/LibGUI/Window.cpp +++ b/Userland/Libraries/LibGUI/Window.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -30,6 +31,7 @@ namespace GUI { static i32 s_next_backing_store_serial; +static IDAllocator s_window_id_allocator; class WindowBackingStore { public: @@ -118,7 +120,10 @@ void Window::show() auto* parent_window = find_parent_window(); - m_window_id = WindowServerConnection::the().create_window( + m_window_id = s_window_id_allocator.allocate(); + + WindowServerConnection::the().async_create_window( + m_window_id, m_rect_when_windowless, !m_moved_by_client, m_has_alpha_channel, diff --git a/Userland/Services/WindowServer/ClientConnection.cpp b/Userland/Services/WindowServer/ClientConnection.cpp index e8ffe7d9ef..3ae815316b 100644 --- a/Userland/Services/WindowServer/ClientConnection.cpp +++ b/Userland/Services/WindowServer/ClientConnection.cpp @@ -460,7 +460,7 @@ Window* ClientConnection::window_from_id(i32 window_id) return it->value.ptr(); } -Messages::WindowServer::CreateWindowResponse ClientConnection::create_window(Gfx::IntRect const& rect, +void ClientConnection::create_window(i32 window_id, Gfx::IntRect const& rect, bool auto_position, bool has_alpha_channel, bool modal, bool minimizable, bool resizable, bool fullscreen, bool frameless, bool accessory, float opacity, float alpha_hit_threshold, Gfx::IntSize const& base_size, Gfx::IntSize const& size_increment, Gfx::IntSize const& minimum_size, @@ -471,16 +471,20 @@ Messages::WindowServer::CreateWindowResponse ClientConnection::create_window(Gfx parent_window = window_from_id(parent_window_id); if (!parent_window) { did_misbehave("CreateWindow with bad parent_window_id"); - return nullptr; + return; } } if (type < 0 || type >= (i32)WindowType::_Count) { did_misbehave("CreateWindow with a bad type"); - return nullptr; + return; + } + + if (m_windows.contains(window_id)) { + did_misbehave("CreateWindow with already-used window ID"); + return; } - int window_id = m_next_window_id++; auto window = Window::construct(*this, (WindowType)type, window_id, modal, minimizable, frameless, resizable, fullscreen, accessory, parent_window); window->set_has_alpha_channel(has_alpha_channel); @@ -513,7 +517,6 @@ Messages::WindowServer::CreateWindowResponse ClientConnection::create_window(Gfx if (window->type() == WindowType::Applet) AppletManager::the().add_applet(*window); m_windows.set(window_id, move(window)); - return window_id; } void ClientConnection::destroy_window(Window& window, Vector& destroyed_window_ids) diff --git a/Userland/Services/WindowServer/ClientConnection.h b/Userland/Services/WindowServer/ClientConnection.h index 045fc25b07..2564370a69 100644 --- a/Userland/Services/WindowServer/ClientConnection.h +++ b/Userland/Services/WindowServer/ClientConnection.h @@ -97,7 +97,7 @@ private: virtual void add_menu_item(i32, i32, i32, String const&, bool, bool, bool, bool, String const&, Gfx::ShareableBitmap const&, bool) override; virtual void add_menu_separator(i32) override; virtual void update_menu_item(i32, i32, i32, String const&, bool, bool, bool, bool, String const&) override; - virtual Messages::WindowServer::CreateWindowResponse create_window(Gfx::IntRect const&, bool, bool, bool, + virtual void create_window(i32, Gfx::IntRect const&, bool, bool, bool, bool, bool, bool, bool, bool, float, float, Gfx::IntSize const&, Gfx::IntSize const&, Gfx::IntSize const&, Optional const&, i32, String const&, i32) override; virtual Messages::WindowServer::DestroyWindowResponse destroy_window(i32) override; @@ -163,8 +163,6 @@ private: RefPtr m_ping_timer; - int m_next_window_id { 1982 }; - bool m_has_display_link { false }; bool m_unresponsive { false }; diff --git a/Userland/Services/WindowServer/WindowServer.ipc b/Userland/Services/WindowServer/WindowServer.ipc index 908c060797..09f8a27852 100644 --- a/Userland/Services/WindowServer/WindowServer.ipc +++ b/Userland/Services/WindowServer/WindowServer.ipc @@ -26,6 +26,7 @@ endpoint WindowServer update_menu_item(i32 menu_id, i32 identifier, i32 submenu_id, [UTF8] String text, bool enabled, bool checkable, bool checked, bool is_default, [UTF8] String shortcut) =| create_window( + i32 window_id, Gfx::IntRect rect, bool auto_position, bool has_alpha_channel, @@ -43,7 +44,7 @@ endpoint WindowServer Optional resize_aspect_ratio, i32 type, [UTF8] String title, - i32 parent_window_id) => (i32 window_id) + i32 parent_window_id) =| destroy_window(i32 window_id) => (Vector destroyed_window_ids)