summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-01-16 10:59:25 +0100
committerAndreas Kling <kling@serenityos.org>2021-01-16 11:26:53 +0100
commit4277be356ad8737f162265ffbe7f59374318ba7f (patch)
tree90eb1aba281866fefb3bfc55f1aa1fb733f22017
parent7c1df68be314793fd915d63d930f81351d723f0b (diff)
downloadserenity-4277be356ad8737f162265ffbe7f59374318ba7f.zip
WindowServer+LibGUI: Send menu item icons as Gfx::ShareableBitmap
-rw-r--r--Userland/Libraries/LibGUI/Menu.cpp30
-rw-r--r--Userland/Services/WindowServer/ClientConnection.cpp9
-rw-r--r--Userland/Services/WindowServer/WindowServer.ipc2
3 files changed, 6 insertions, 35 deletions
diff --git a/Userland/Libraries/LibGUI/Menu.cpp b/Userland/Libraries/LibGUI/Menu.cpp
index 47e284312a..4f5e60f078 100644
--- a/Userland/Libraries/LibGUI/Menu.cpp
+++ b/Userland/Libraries/LibGUI/Menu.cpp
@@ -25,7 +25,6 @@
*/
#include <AK/HashMap.h>
-#include <AK/SharedBuffer.h>
#include <LibGUI/Action.h>
#include <LibGUI/ActionGroup.h>
#include <LibGUI/Menu.h>
@@ -107,27 +106,6 @@ void Menu::dismiss()
WindowServerConnection::the().post_message(Messages::WindowServer::DismissMenu(m_menu_id));
}
-template<typename IconContainerType>
-static int ensure_realized_icon(IconContainerType& container)
-{
- int icon_buffer_id = -1;
- if (container.icon()) {
- ASSERT(container.icon()->format() == Gfx::BitmapFormat::RGBA32);
- ASSERT(container.icon()->size() == Gfx::IntSize(16, 16));
- if (container.icon()->shbuf_id() == -1) {
- auto shared_buffer = SharedBuffer::create_with_size(container.icon()->size_in_bytes());
- ASSERT(shared_buffer);
- auto shared_icon = Gfx::Bitmap::create_with_shared_buffer(Gfx::BitmapFormat::RGBA32, *shared_buffer, container.icon()->size());
- memcpy(shared_buffer->template data<u8>(), container.icon()->scanline_u8(0), container.icon()->size_in_bytes());
- shared_buffer->seal();
- shared_buffer->share_with(WindowServerConnection::the().server_pid());
- container.set_icon(shared_icon);
- }
- icon_buffer_id = container.icon()->shbuf_id();
- }
- return icon_buffer_id;
-}
-
int Menu::realize_menu(RefPtr<Action> default_action)
{
unrealize_menu();
@@ -148,17 +126,17 @@ int Menu::realize_menu(RefPtr<Action> default_action)
if (item.type() == MenuItem::Type::Submenu) {
auto& submenu = *item.submenu();
submenu.realize_if_needed(default_action);
- int icon_buffer_id = ensure_realized_icon(submenu);
- WindowServerConnection::the().send_sync<Messages::WindowServer::AddMenuItem>(m_menu_id, i, submenu.menu_id(), submenu.name(), true, false, false, false, "", icon_buffer_id, false);
+ auto icon = submenu.icon() ? submenu.icon()->to_shareable_bitmap() : Gfx::ShareableBitmap();
+ WindowServerConnection::the().send_sync<Messages::WindowServer::AddMenuItem>(m_menu_id, i, submenu.menu_id(), submenu.name(), true, false, false, false, "", icon, false);
continue;
}
if (item.type() == MenuItem::Type::Action) {
auto& action = *item.action();
- int icon_buffer_id = ensure_realized_icon(action);
auto shortcut_text = action.shortcut().is_valid() ? action.shortcut().to_string() : String();
bool exclusive = action.group() && action.group()->is_exclusive() && action.is_checkable();
bool is_default = (default_action.ptr() == &action);
- WindowServerConnection::the().send_sync<Messages::WindowServer::AddMenuItem>(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_buffer_id, exclusive);
+ auto icon = action.icon() ? action.icon()->to_shareable_bitmap() : Gfx::ShareableBitmap();
+ WindowServerConnection::the().send_sync<Messages::WindowServer::AddMenuItem>(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/Services/WindowServer/ClientConnection.cpp b/Userland/Services/WindowServer/ClientConnection.cpp
index 77f27a571e..89d2ede079 100644
--- a/Userland/Services/WindowServer/ClientConnection.cpp
+++ b/Userland/Services/WindowServer/ClientConnection.cpp
@@ -203,14 +203,7 @@ OwnPtr<Messages::WindowServer::AddMenuItemResponse> ClientConnection::handle(con
auto menu_item = make<MenuItem>(menu, identifier, message.text(), message.shortcut(), message.enabled(), message.checkable(), message.checked());
if (message.is_default())
menu_item->set_default(true);
- if (message.icon_buffer_id() != -1) {
- auto icon_buffer = SharedBuffer::create_from_shbuf_id(message.icon_buffer_id());
- if (!icon_buffer)
- return {};
- // FIXME: Verify that the icon buffer can accommodate a 16x16 bitmap view.
- auto shared_icon = Gfx::Bitmap::create_with_shared_buffer(Gfx::BitmapFormat::RGBA32, icon_buffer.release_nonnull(), { 16, 16 });
- menu_item->set_icon(shared_icon);
- }
+ menu_item->set_icon(message.icon().bitmap());
menu_item->set_submenu_id(message.submenu_id());
menu_item->set_exclusive(message.exclusive());
menu.add_item(move(menu_item));
diff --git a/Userland/Services/WindowServer/WindowServer.ipc b/Userland/Services/WindowServer/WindowServer.ipc
index 73d14a05f7..80ad93cdf8 100644
--- a/Userland/Services/WindowServer/WindowServer.ipc
+++ b/Userland/Services/WindowServer/WindowServer.ipc
@@ -23,7 +23,7 @@ endpoint WindowServer = 2
bool checked,
bool is_default,
[UTF8] String shortcut,
- i32 icon_buffer_id,
+ Gfx::ShareableBitmap icon,
bool exclusive) => ()
AddMenuSeparator(i32 menu_id) => ()