From 333366a99d09ede55a025f7294617e5d89ce630b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 15 Jan 2021 23:13:24 +0100 Subject: [PATCH] WindowServer+Taskbar: Send WM icon updates as Gfx::ShareableBitmap Window icons in Taskbar were previously received in WM events with shbuf ID's. Now that Gfx::ShareableBitmap is backed by anonymous files, we can easily switch to using those. --- Userland/Libraries/LibGUI/Event.h | 12 +++++------- Userland/Libraries/LibGUI/Window.cpp | 3 +-- Userland/Libraries/LibGUI/WindowServerConnection.cpp | 5 +++-- Userland/Libraries/LibGfx/ShareableBitmap.cpp | 2 +- Userland/Services/Taskbar/TaskbarWindow.cpp | 10 +--------- Userland/Services/Taskbar/main.cpp | 4 ++-- Userland/Services/WindowServer/WindowClient.ipc | 2 +- Userland/Services/WindowServer/WindowManager.cpp | 10 +--------- Userland/Services/WindowServer/main.cpp | 4 ++-- 9 files changed, 17 insertions(+), 35 deletions(-) diff --git a/Userland/Libraries/LibGUI/Event.h b/Userland/Libraries/LibGUI/Event.h index ce60f00e12..8ce2cb49bf 100644 --- a/Userland/Libraries/LibGUI/Event.h +++ b/Userland/Libraries/LibGUI/Event.h @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -172,19 +173,16 @@ private: class WMWindowIconBitmapChangedEvent : public WMEvent { public: - WMWindowIconBitmapChangedEvent(int client_id, int window_id, int icon_buffer_id, const Gfx::IntSize& icon_size) + WMWindowIconBitmapChangedEvent(int client_id, int window_id, const Gfx::Bitmap* bitmap) : WMEvent(Event::Type::WM_WindowIconBitmapChanged, client_id, window_id) - , m_icon_buffer_id(icon_buffer_id) - , m_icon_size(icon_size) + , m_bitmap(move(bitmap)) { } - int icon_buffer_id() const { return m_icon_buffer_id; } - const Gfx::IntSize& icon_size() const { return m_icon_size; } + const Gfx::Bitmap* bitmap() const { return m_bitmap; } private: - int m_icon_buffer_id; - Gfx::IntSize m_icon_size; + RefPtr m_bitmap; }; class MultiPaintEvent final : public Event { diff --git a/Userland/Libraries/LibGUI/Window.cpp b/Userland/Libraries/LibGUI/Window.cpp index 3eec87c346..baab010b6a 100644 --- a/Userland/Libraries/LibGUI/Window.cpp +++ b/Userland/Libraries/LibGUI/Window.cpp @@ -777,8 +777,7 @@ void Window::apply_icon() if (!is_visible()) return; - auto icon = m_icon->to_shareable_bitmap(); - WindowServerConnection::the().send_sync(m_window_id, icon); + WindowServerConnection::the().send_sync(m_window_id, m_icon->to_shareable_bitmap()); } void Window::start_wm_resize() diff --git a/Userland/Libraries/LibGUI/WindowServerConnection.cpp b/Userland/Libraries/LibGUI/WindowServerConnection.cpp index 8250f134af..8540a924c8 100644 --- a/Userland/Libraries/LibGUI/WindowServerConnection.cpp +++ b/Userland/Libraries/LibGUI/WindowServerConnection.cpp @@ -289,8 +289,9 @@ void WindowServerConnection::handle(const Messages::WindowClient::WM_WindowRectC void WindowServerConnection::handle(const Messages::WindowClient::WM_WindowIconBitmapChanged& message) { - if (auto* window = Window::from_window_id(message.wm_id())) - Core::EventLoop::current().post_event(*window, make(message.client_id(), message.window_id(), message.icon_buffer_id(), message.icon_size())); + if (auto* window = Window::from_window_id(message.wm_id())) { + Core::EventLoop::current().post_event(*window, make(message.client_id(), message.window_id(), message.bitmap().bitmap())); + } } void WindowServerConnection::handle(const Messages::WindowClient::WM_WindowRemoved& message) diff --git a/Userland/Libraries/LibGfx/ShareableBitmap.cpp b/Userland/Libraries/LibGfx/ShareableBitmap.cpp index 8431a26fad..66a42ef5f0 100644 --- a/Userland/Libraries/LibGfx/ShareableBitmap.cpp +++ b/Userland/Libraries/LibGfx/ShareableBitmap.cpp @@ -60,7 +60,7 @@ bool decode(Decoder& decoder, Gfx::ShareableBitmap& shareable_bitmap) if (!decoder.decode(size)) return false; - auto bitmap = Gfx::Bitmap::create_with_anon_fd(Gfx::BitmapFormat::RGBA32, anon_file.fd(), size, Gfx::Bitmap::ShouldCloseAnonymousFile::No); + auto bitmap = Gfx::Bitmap::create_with_anon_fd(Gfx::BitmapFormat::RGBA32, anon_file.take_fd(), size, Gfx::Bitmap::ShouldCloseAnonymousFile::Yes); shareable_bitmap = bitmap->to_shareable_bitmap(); return true; } diff --git a/Userland/Services/Taskbar/TaskbarWindow.cpp b/Userland/Services/Taskbar/TaskbarWindow.cpp index fbc7946634..a028cea848 100644 --- a/Userland/Services/Taskbar/TaskbarWindow.cpp +++ b/Userland/Services/Taskbar/TaskbarWindow.cpp @@ -256,17 +256,9 @@ void TaskbarWindow::wm_event(GUI::WMEvent& event) case GUI::Event::WM_WindowIconBitmapChanged: { auto& changed_event = static_cast(event); -#ifdef EVENT_DEBUG - dbgln("WM_WindowIconBitmapChanged: client_id={}, window_id={}, icon_buffer_id={}", - changed_event.client_id(), - changed_event.window_id(), - changed_event.icon_buffer_id()); -#endif if (auto* window = WindowList::the().window(identifier)) { - auto buffer = SharedBuffer::create_from_shbuf_id(changed_event.icon_buffer_id()); - ASSERT(buffer); if (window->button()) - window->button()->set_icon(Gfx::Bitmap::create_with_shared_buffer(Gfx::BitmapFormat::RGBA32, *buffer, changed_event.icon_size())); + window->button()->set_icon(changed_event.bitmap()); } break; } diff --git a/Userland/Services/Taskbar/main.cpp b/Userland/Services/Taskbar/main.cpp index eb49b1cc24..d6584ab914 100644 --- a/Userland/Services/Taskbar/main.cpp +++ b/Userland/Services/Taskbar/main.cpp @@ -33,7 +33,7 @@ int main(int argc, char** argv) { - if (pledge("stdio sendfd shared_buffer accept proc exec rpath unix cpath fattr sigaction", nullptr) < 0) { + if (pledge("stdio recvfd sendfd shared_buffer accept proc exec rpath unix cpath fattr sigaction", nullptr) < 0) { perror("pledge"); return 1; } @@ -45,7 +45,7 @@ int main(int argc, char** argv) ; }); - if (pledge("stdio sendfd shared_buffer accept proc exec rpath", nullptr) < 0) { + if (pledge("stdio recvfd sendfd shared_buffer accept proc exec rpath", nullptr) < 0) { perror("pledge"); return 1; } diff --git a/Userland/Services/WindowServer/WindowClient.ipc b/Userland/Services/WindowServer/WindowClient.ipc index c6ac17b022..f3d04d5a9c 100644 --- a/Userland/Services/WindowServer/WindowClient.ipc +++ b/Userland/Services/WindowServer/WindowClient.ipc @@ -24,7 +24,7 @@ endpoint WindowClient = 4 WM_WindowRemoved(i32 wm_id, i32 client_id, i32 window_id) =| WM_WindowStateChanged(i32 wm_id, i32 client_id, i32 window_id, i32 parent_client_id, i32 parent_window_id, bool is_active, bool is_minimized, bool is_modal, bool is_frameless, i32 window_type, [UTF8] String title, Gfx::IntRect rect, i32 progress) =| - WM_WindowIconBitmapChanged(i32 wm_id, i32 client_id, i32 window_id, i32 icon_buffer_id, Gfx::IntSize icon_size) =| + WM_WindowIconBitmapChanged(i32 wm_id, i32 client_id, i32 window_id, Gfx::ShareableBitmap bitmap) =| WM_WindowRectChanged(i32 wm_id, i32 client_id, i32 window_id, Gfx::IntRect rect) =| AsyncSetWallpaperFinished(bool success) =| diff --git a/Userland/Services/WindowServer/WindowManager.cpp b/Userland/Services/WindowServer/WindowManager.cpp index 8ced98b4fe..570bf3d04b 100644 --- a/Userland/Services/WindowServer/WindowManager.cpp +++ b/Userland/Services/WindowServer/WindowManager.cpp @@ -316,15 +316,7 @@ void WindowManager::tell_wm_listener_about_window_icon(Window& listener, Window& return; if (window.is_internal()) return; - if (window.icon().shbuf_id() == -1) - return; -#ifdef WINDOWMANAGER_DEBUG - dbg() << "WindowServer: Sharing icon buffer " << window.icon().shbuf_id() << " with PID " << listener.client()->client_pid(); -#endif - if (shbuf_allow_pid(window.icon().shbuf_id(), listener.client()->client_pid()) < 0) { - ASSERT_NOT_REACHED(); - } - listener.client()->post_message(Messages::WindowClient::WM_WindowIconBitmapChanged(listener.window_id(), window.client_id(), window.window_id(), window.icon().shbuf_id(), window.icon().size())); + listener.client()->post_message(Messages::WindowClient::WM_WindowIconBitmapChanged(listener.window_id(), window.client_id(), window.window_id(), window.icon().to_shareable_bitmap())); } void WindowManager::tell_wm_listeners_window_state_changed(Window& window) diff --git a/Userland/Services/WindowServer/main.cpp b/Userland/Services/WindowServer/main.cpp index c2f4b66825..e2da920064 100644 --- a/Userland/Services/WindowServer/main.cpp +++ b/Userland/Services/WindowServer/main.cpp @@ -39,7 +39,7 @@ int main(int, char**) { - if (pledge("stdio video thread recvfd shared_buffer accept rpath wpath cpath unix proc fattr sigaction", nullptr) < 0) { + if (pledge("stdio video thread sendfd recvfd shared_buffer accept rpath wpath cpath unix proc fattr sigaction", nullptr) < 0) { perror("pledge"); return 1; } @@ -84,7 +84,7 @@ int main(int, char**) WindowServer::EventLoop loop; - if (pledge("stdio video thread recvfd shared_buffer accept rpath wpath cpath proc", nullptr) < 0) { + if (pledge("stdio video thread sendfd recvfd shared_buffer accept rpath wpath cpath proc", nullptr) < 0) { perror("pledge"); return 1; }