From ab0dad5ea2a764d4a13c960d24efa7a2e69b931a Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 16 Jan 2021 10:06:27 +0100 Subject: [PATCH] WindowServer+LibGUI: Pass drag&drop bitmaps via Gfx::ShareableBitmap This makes them backed by anonymous files instead of shbufs and also simplifies the code significantly on both client and server side. --- Userland/Libraries/LibGUI/DragOperation.cpp | 11 +++-------- Userland/Services/WindowServer/ClientConnection.cpp | 13 +------------ Userland/Services/WindowServer/WindowManager.cpp | 2 +- Userland/Services/WindowServer/WindowManager.h | 2 +- Userland/Services/WindowServer/WindowServer.ipc | 2 +- 5 files changed, 7 insertions(+), 23 deletions(-) diff --git a/Userland/Libraries/LibGUI/DragOperation.cpp b/Userland/Libraries/LibGUI/DragOperation.cpp index 060f25fc62..74c9eddd7e 100644 --- a/Userland/Libraries/LibGUI/DragOperation.cpp +++ b/Userland/Libraries/LibGUI/DragOperation.cpp @@ -51,22 +51,17 @@ DragOperation::Outcome DragOperation::exec() ASSERT(!m_event_loop); ASSERT(m_mime_data); - int bitmap_id = -1; - Gfx::IntSize bitmap_size; - RefPtr shared_bitmap; + Gfx::ShareableBitmap drag_bitmap; if (m_mime_data->has_format("image/x-raw-bitmap")) { auto data = m_mime_data->data("image/x-raw-bitmap"); auto bitmap = Gfx::Bitmap::create_from_serialized_byte_buffer(move(data)); - shared_bitmap = bitmap->to_bitmap_backed_by_shared_buffer(); - shared_bitmap->shared_buffer()->share_with(WindowServerConnection::the().server_pid()); - bitmap_id = shared_bitmap->shbuf_id(); - bitmap_size = shared_bitmap->size(); + drag_bitmap = bitmap->to_shareable_bitmap(); } auto response = WindowServerConnection::the().send_sync( m_mime_data->text(), m_mime_data->all_data(), - bitmap_id, bitmap_size); + drag_bitmap); if (!response->started()) { m_outcome = Outcome::Cancelled; diff --git a/Userland/Services/WindowServer/ClientConnection.cpp b/Userland/Services/WindowServer/ClientConnection.cpp index 18fd74c8b3..77f27a571e 100644 --- a/Userland/Services/WindowServer/ClientConnection.cpp +++ b/Userland/Services/WindowServer/ClientConnection.cpp @@ -747,18 +747,7 @@ OwnPtr ClientConnection::handle(const if (wm.dnd_client()) return make(false); - RefPtr bitmap; - if (message.bitmap_id() != -1) { - auto shared_buffer = SharedBuffer::create_from_shbuf_id(message.bitmap_id()); - ssize_t size_in_bytes = message.bitmap_size().area() * sizeof(Gfx::RGBA32); - if (size_in_bytes > shared_buffer->size()) { - did_misbehave("SetAppletBackingStore: Shared buffer is too small for applet size"); - return {}; - } - bitmap = Gfx::Bitmap::create_with_shared_buffer(Gfx::BitmapFormat::RGBA32, *shared_buffer, message.bitmap_size()); - } - - wm.start_dnd_drag(*this, message.text(), bitmap, Core::MimeData::construct(message.mime_data())); + wm.start_dnd_drag(*this, message.text(), message.drag_bitmap().bitmap(), Core::MimeData::construct(message.mime_data())); return make(true); } diff --git a/Userland/Services/WindowServer/WindowManager.cpp b/Userland/Services/WindowServer/WindowManager.cpp index 570bf3d04b..0d44b108f7 100644 --- a/Userland/Services/WindowServer/WindowManager.cpp +++ b/Userland/Services/WindowServer/WindowManager.cpp @@ -1383,7 +1383,7 @@ Gfx::IntRect WindowManager::maximized_window_rect(const Window& window) const return rect; } -void WindowManager::start_dnd_drag(ClientConnection& client, const String& text, Gfx::Bitmap* bitmap, const Core::MimeData& mime_data) +void WindowManager::start_dnd_drag(ClientConnection& client, const String& text, const Gfx::Bitmap* bitmap, const Core::MimeData& mime_data) { ASSERT(!m_dnd_client); m_dnd_client = client; diff --git a/Userland/Services/WindowServer/WindowManager.h b/Userland/Services/WindowServer/WindowManager.h index 7c0735784b..37687119cc 100644 --- a/Userland/Services/WindowServer/WindowManager.h +++ b/Userland/Services/WindowServer/WindowManager.h @@ -104,7 +104,7 @@ public: const Gfx::Bitmap* dnd_bitmap() const { return m_dnd_bitmap; } Gfx::IntRect dnd_rect() const; - void start_dnd_drag(ClientConnection&, const String& text, Gfx::Bitmap*, const Core::MimeData&); + void start_dnd_drag(ClientConnection&, const String& text, const Gfx::Bitmap*, const Core::MimeData&); void end_dnd_drag(); Window* active_window() { return m_active_window.ptr(); } diff --git a/Userland/Services/WindowServer/WindowServer.ipc b/Userland/Services/WindowServer/WindowServer.ipc index 3ab9feed6c..73d14a05f7 100644 --- a/Userland/Services/WindowServer/WindowServer.ipc +++ b/Userland/Services/WindowServer/WindowServer.ipc @@ -94,7 +94,7 @@ endpoint WindowServer = 2 SetWindowCursor(i32 window_id, i32 cursor_type) => () SetWindowCustomCursor(i32 window_id, Gfx::ShareableBitmap cursor) => () - StartDrag([UTF8] String text, HashMap mime_data, i32 bitmap_id, Gfx::IntSize bitmap_size) => (bool started) + StartDrag([UTF8] String text, HashMap mime_data, Gfx::ShareableBitmap drag_bitmap) => (bool started) SetSystemTheme(String theme_path, [UTF8] String theme_name) => (bool success) GetSystemTheme() => ([UTF8] String theme_name)