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)
This commit is contained in:
Andreas Kling 2021-05-03 21:27:22 +02:00
parent 8a6db55e79
commit a8a899adbf
5 changed files with 11 additions and 11 deletions

View file

@ -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);

View file

@ -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)

View file

@ -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);
}
}

View file

@ -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());
}
}

View file

@ -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)