1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:18:12 +00:00

LibGfx+LibIPC: Add Gfx::ShareableBitmap, a bitmap for easy IPC usage

With this patch, it's now possible to pass a Gfx::ShareableBitmap in an
IPC message. As long as the message itself is synchronous, the bitmap
will be adopted by the receiving end, and disowned by the sender nicely
without any accounting effort like we've had to do in the past.

Use this in NotificationServer to allow sending arbitrary bitmaps as
icons instead of paths-to-icons.
This commit is contained in:
Andreas Kling 2020-03-29 19:04:05 +02:00
parent 24a0354ce8
commit 7cfe712f4d
17 changed files with 115 additions and 17 deletions

View file

@ -29,6 +29,7 @@
#include <AK/String.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/PNGLoader.h>
#include <LibGfx/ShareableBitmap.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
@ -97,7 +98,7 @@ Bitmap::Bitmap(BitmapFormat format, NonnullRefPtr<SharedBuffer>&& shared_buffer,
ASSERT(format != BitmapFormat::Indexed8);
}
NonnullRefPtr<Bitmap> Bitmap::to_shareable_bitmap() const
NonnullRefPtr<Bitmap> Bitmap::to_bitmap_backed_by_shared_buffer() const
{
if (m_shared_buffer)
return *this;
@ -164,4 +165,12 @@ int Bitmap::shbuf_id() const
return m_shared_buffer ? m_shared_buffer->shbuf_id() : -1;
}
ShareableBitmap Bitmap::to_shareable_bitmap(pid_t peer_pid) const
{
auto bitmap = to_bitmap_backed_by_shared_buffer();
if (peer_pid > 0)
bitmap->shared_buffer()->share_with(peer_pid);
return ShareableBitmap(*bitmap);
}
}