diff options
author | Andreas Kling <kling@serenityos.org> | 2021-05-03 21:27:22 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-03 21:56:13 +0200 |
commit | a8a899adbf9a3057ea8e498db7d4504b40f5a40e (patch) | |
tree | 38e540aeb7455fb73193b658f05f78b1268a12a8 | |
parent | 8a6db55e79ee484bc071fcb52ca30da069231f77 (diff) | |
download | serenity-a8a899adbf9a3057ea8e498db7d4504b40f5a40e.zip |
WindowServer+LibGUI: Make much of menu construction asynchronous
Creating a menu/menubar needs to be synchronous because we need the
ID from the response, but adding stuff *to* menus (and adding menus
to menubars, and menubars to windows) can all be asynchronous.
This dramatically reduces the amount of IPC ping-pong played by
each GUI application during startup.
I measured how long it takes TextEditor to enter the main event loop
and it's over 10% faster here. (Down from ~86ms to ~74ms)
-rw-r--r-- | Userland/Libraries/LibGUI/Menu.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/MenuItem.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Menubar.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Window.cpp | 2 | ||||
-rw-r--r-- | Userland/Services/WindowServer/WindowServer.ipc | 10 |
5 files changed, 11 insertions, 11 deletions
diff --git a/Userland/Libraries/LibGUI/Menu.cpp b/Userland/Libraries/LibGUI/Menu.cpp index 46f060ac8f..bd6cb4cc92 100644 --- a/Userland/Libraries/LibGUI/Menu.cpp +++ b/Userland/Libraries/LibGUI/Menu.cpp @@ -94,14 +94,14 @@ int Menu::realize_menu(RefPtr<Action> default_action) item.set_menu_id({}, m_menu_id); item.set_identifier({}, i); if (item.type() == MenuItem::Type::Separator) { - WindowServerConnection::the().add_menu_separator(m_menu_id); + WindowServerConnection::the().async_add_menu_separator(m_menu_id); continue; } if (item.type() == MenuItem::Type::Submenu) { auto& submenu = *item.submenu(); submenu.realize_if_needed(default_action); auto icon = submenu.icon() ? submenu.icon()->to_shareable_bitmap() : Gfx::ShareableBitmap(); - WindowServerConnection::the().add_menu_item(m_menu_id, i, submenu.menu_id(), submenu.name(), true, false, false, false, "", icon, false); + WindowServerConnection::the().async_add_menu_item(m_menu_id, i, submenu.menu_id(), submenu.name(), true, false, false, false, "", icon, false); continue; } if (item.type() == MenuItem::Type::Action) { @@ -110,7 +110,7 @@ int Menu::realize_menu(RefPtr<Action> default_action) bool exclusive = action.group() && action.group()->is_exclusive() && action.is_checkable(); bool is_default = (default_action.ptr() == &action); auto icon = action.icon() ? action.icon()->to_shareable_bitmap() : Gfx::ShareableBitmap(); - WindowServerConnection::the().add_menu_item(m_menu_id, i, -1, action.text(), action.is_enabled(), action.is_checkable(), action.is_checkable() ? action.is_checked() : false, is_default, shortcut_text, icon, exclusive); + WindowServerConnection::the().async_add_menu_item(m_menu_id, i, -1, action.text(), action.is_enabled(), action.is_checkable(), action.is_checkable() ? action.is_checked() : false, is_default, shortcut_text, icon, exclusive); } } all_menus().set(m_menu_id, this); diff --git a/Userland/Libraries/LibGUI/MenuItem.cpp b/Userland/Libraries/LibGUI/MenuItem.cpp index 02ca0bd6b3..6658e7ac1b 100644 --- a/Userland/Libraries/LibGUI/MenuItem.cpp +++ b/Userland/Libraries/LibGUI/MenuItem.cpp @@ -74,7 +74,7 @@ void MenuItem::update_window_server() return; auto& action = *m_action; auto shortcut_text = action.shortcut().is_valid() ? action.shortcut().to_string() : String(); - WindowServerConnection::the().update_menu_item(m_menu_id, m_identifier, -1, action.text(), action.is_enabled(), action.is_checkable(), action.is_checkable() ? action.is_checked() : false, m_default, shortcut_text); + WindowServerConnection::the().async_update_menu_item(m_menu_id, m_identifier, -1, action.text(), action.is_enabled(), action.is_checkable(), action.is_checkable() ? action.is_checked() : false, m_default, shortcut_text); } void MenuItem::set_menu_id(Badge<Menu>, unsigned int menu_id) diff --git a/Userland/Libraries/LibGUI/Menubar.cpp b/Userland/Libraries/LibGUI/Menubar.cpp index 4caa05ae96..8fda7c477f 100644 --- a/Userland/Libraries/LibGUI/Menubar.cpp +++ b/Userland/Libraries/LibGUI/Menubar.cpp @@ -49,7 +49,7 @@ void Menubar::notify_added_to_window(Badge<Window>) for (auto& menu : m_menus) { int menu_id = menu.realize_menu(); VERIFY(menu_id != -1); - WindowServerConnection::the().add_menu_to_menubar(m_menubar_id, menu_id); + WindowServerConnection::the().async_add_menu_to_menubar(m_menubar_id, menu_id); } } diff --git a/Userland/Libraries/LibGUI/Window.cpp b/Userland/Libraries/LibGUI/Window.cpp index 16dfe13a49..cf99a6a9b8 100644 --- a/Userland/Libraries/LibGUI/Window.cpp +++ b/Userland/Libraries/LibGUI/Window.cpp @@ -1075,7 +1075,7 @@ void Window::set_menubar(RefPtr<Menubar> menubar) m_menubar = move(menubar); if (m_window_id && m_menubar) { m_menubar->notify_added_to_window({}); - WindowServerConnection::the().set_window_menubar(m_window_id, m_menubar->menubar_id()); + WindowServerConnection::the().async_set_window_menubar(m_window_id, m_menubar->menubar_id()); } } diff --git a/Userland/Services/WindowServer/WindowServer.ipc b/Userland/Services/WindowServer/WindowServer.ipc index f4a77ba064..4a68ed6c71 100644 --- a/Userland/Services/WindowServer/WindowServer.ipc +++ b/Userland/Services/WindowServer/WindowServer.ipc @@ -8,7 +8,7 @@ endpoint WindowServer create_menu([UTF8] String menu_title) => (i32 menu_id) destroy_menu(i32 menu_id) => () - add_menu_to_menubar(i32 menubar_id, i32 menu_id) => () + add_menu_to_menubar(i32 menubar_id, i32 menu_id) =| add_menu_item( i32 menu_id, @@ -21,11 +21,11 @@ endpoint WindowServer bool is_default, [UTF8] String shortcut, Gfx::ShareableBitmap icon, - bool exclusive) => () + bool exclusive) =| - add_menu_separator(i32 menu_id) => () + add_menu_separator(i32 menu_id) =| - 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) => () + 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( Gfx::IntRect rect, @@ -49,7 +49,7 @@ endpoint WindowServer destroy_window(i32 window_id) => (Vector<i32> destroyed_window_ids) - set_window_menubar(i32 window_id, i32 menubar_id) => () + set_window_menubar(i32 window_id, i32 menubar_id) =| set_window_title(i32 window_id, [UTF8] String title) => () get_window_title(i32 window_id) => ([UTF8] String title) |