mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 19:58:11 +00:00
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.
This commit is contained in:
parent
60e580fa3e
commit
ab0dad5ea2
5 changed files with 7 additions and 23 deletions
|
@ -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<Gfx::Bitmap> 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<Messages::WindowServer::StartDrag>(
|
||||
m_mime_data->text(),
|
||||
m_mime_data->all_data(),
|
||||
bitmap_id, bitmap_size);
|
||||
drag_bitmap);
|
||||
|
||||
if (!response->started()) {
|
||||
m_outcome = Outcome::Cancelled;
|
||||
|
|
|
@ -747,18 +747,7 @@ OwnPtr<Messages::WindowServer::StartDragResponse> ClientConnection::handle(const
|
|||
if (wm.dnd_client())
|
||||
return make<Messages::WindowServer::StartDragResponse>(false);
|
||||
|
||||
RefPtr<Gfx::Bitmap> 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<Messages::WindowServer::StartDragResponse>(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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(); }
|
||||
|
|
|
@ -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<String,ByteBuffer> mime_data, i32 bitmap_id, Gfx::IntSize bitmap_size) => (bool started)
|
||||
StartDrag([UTF8] String text, HashMap<String,ByteBuffer> mime_data, Gfx::ShareableBitmap drag_bitmap) => (bool started)
|
||||
|
||||
SetSystemTheme(String theme_path, [UTF8] String theme_name) => (bool success)
|
||||
GetSystemTheme() => ([UTF8] String theme_name)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue