WindowServer+LibGUI: Make menu allocation asynchronous
This was only synchronous since WindowServer managed the ID allocation. Doing this on the client side instead allows us to make create_menu() an asynchronous IPC call, removing a bunch of IPC stalls during application startup.
This commit is contained in:
parent
52054eb922
commit
baab0a5bef
Notes:
sideshowbarker
2024-07-18 17:57:44 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/baab0a5bef1
4 changed files with 9 additions and 7 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <AK/Debug.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/IDAllocator.h>
|
||||
#include <LibGUI/Action.h>
|
||||
#include <LibGUI/ActionGroup.h>
|
||||
#include <LibGUI/Menu.h>
|
||||
|
@ -15,6 +16,8 @@
|
|||
|
||||
namespace GUI {
|
||||
|
||||
static IDAllocator s_menu_id_allocator;
|
||||
|
||||
static HashMap<int, Menu*>& all_menus()
|
||||
{
|
||||
static HashMap<int, Menu*>* map;
|
||||
|
@ -85,7 +88,9 @@ void Menu::dismiss()
|
|||
int Menu::realize_menu(RefPtr<Action> default_action)
|
||||
{
|
||||
unrealize_menu();
|
||||
m_menu_id = WindowServerConnection::the().create_menu(m_name);
|
||||
m_menu_id = s_menu_id_allocator.allocate();
|
||||
|
||||
WindowServerConnection::the().async_create_menu(m_menu_id, m_name);
|
||||
|
||||
dbgln_if(MENU_DEBUG, "GUI::Menu::realize_menu(): New menu ID: {}", m_menu_id);
|
||||
VERIFY(m_menu_id > 0);
|
||||
|
|
|
@ -99,12 +99,10 @@ void ClientConnection::destroy_menubar(i32 menubar_id)
|
|||
m_menubars.remove(it);
|
||||
}
|
||||
|
||||
Messages::WindowServer::CreateMenuResponse ClientConnection::create_menu(String const& menu_title)
|
||||
void ClientConnection::create_menu(i32 menu_id, String const& menu_title)
|
||||
{
|
||||
int menu_id = m_next_menu_id++;
|
||||
auto menu = Menu::construct(this, menu_id, menu_title);
|
||||
m_menus.set(menu_id, move(menu));
|
||||
return menu_id;
|
||||
}
|
||||
|
||||
void ClientConnection::destroy_menu(i32 menu_id)
|
||||
|
|
|
@ -91,7 +91,7 @@ private:
|
|||
virtual Messages::WindowServer::GreetResponse greet() override;
|
||||
virtual Messages::WindowServer::CreateMenubarResponse create_menubar() override;
|
||||
virtual void destroy_menubar(i32) override;
|
||||
virtual Messages::WindowServer::CreateMenuResponse create_menu(String const&) override;
|
||||
virtual void create_menu(i32, String const&) override;
|
||||
virtual void destroy_menu(i32) override;
|
||||
virtual void add_menu_to_menubar(i32, i32) override;
|
||||
virtual void set_window_menubar(i32, i32) override;
|
||||
|
@ -161,7 +161,6 @@ private:
|
|||
RefPtr<Core::Timer> m_ping_timer;
|
||||
|
||||
int m_next_menubar_id { 10000 };
|
||||
int m_next_menu_id { 20000 };
|
||||
int m_next_window_id { 1982 };
|
||||
|
||||
bool m_has_display_link { false };
|
||||
|
|
|
@ -5,7 +5,7 @@ endpoint WindowServer
|
|||
create_menubar() => (i32 menubar_id)
|
||||
destroy_menubar(i32 menubar_id) =|
|
||||
|
||||
create_menu([UTF8] String menu_title) => (i32 menu_id)
|
||||
create_menu(i32 menu_id, [UTF8] String menu_title) =|
|
||||
destroy_menu(i32 menu_id) =|
|
||||
|
||||
add_menu_to_menubar(i32 menubar_id, i32 menu_id) =|
|
||||
|
|
Loading…
Add table
Reference in a new issue