mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:37:35 +00:00
LibGfx: Use anonymous buffer instead of raw anon_fd for Gfx::Bitmap
Instead of using a low-level, proprietary API inside LibGfx, let's use Core::AnonymousBuffer which already abstracts anon_fd and offers a higher-level API too.
This commit is contained in:
parent
de395a3df2
commit
e4394b1605
5 changed files with 41 additions and 75 deletions
|
@ -14,7 +14,7 @@
|
|||
namespace Gfx {
|
||||
|
||||
ShareableBitmap::ShareableBitmap(const Bitmap& bitmap)
|
||||
: m_bitmap(bitmap.to_bitmap_backed_by_anon_fd())
|
||||
: m_bitmap(bitmap.to_bitmap_backed_by_anonymous_buffer())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ bool encode(Encoder& encoder, const Gfx::ShareableBitmap& shareable_bitmap)
|
|||
if (!shareable_bitmap.is_valid())
|
||||
return true;
|
||||
auto& bitmap = *shareable_bitmap.bitmap();
|
||||
encoder << IPC::File(bitmap.anon_fd());
|
||||
encoder << IPC::File(bitmap.anonymous_buffer().fd());
|
||||
encoder << bitmap.size();
|
||||
encoder << bitmap.scale();
|
||||
encoder << (u32)bitmap.format();
|
||||
|
@ -73,7 +73,10 @@ bool decode(Decoder& decoder, Gfx::ShareableBitmap& shareable_bitmap)
|
|||
if (!decoder.decode(palette))
|
||||
return false;
|
||||
}
|
||||
auto bitmap = Gfx::Bitmap::create_with_anon_fd(bitmap_format, anon_file.take_fd(), size, scale, palette, Gfx::Bitmap::ShouldCloseAnonymousFile::Yes);
|
||||
auto buffer = Core::AnonymousBuffer::create_from_anon_fd(anon_file.take_fd(), Gfx::Bitmap::size_in_bytes(Gfx::Bitmap::minimum_pitch(size.width(), bitmap_format), size.height()));
|
||||
if (!buffer.is_valid())
|
||||
return false;
|
||||
auto bitmap = Gfx::Bitmap::create_with_anonymous_buffer(bitmap_format, buffer, size, scale, palette);
|
||||
if (!bitmap)
|
||||
return false;
|
||||
shareable_bitmap = Gfx::ShareableBitmap { bitmap.release_nonnull(), Gfx::ShareableBitmap::ConstructWithKnownGoodBitmap };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue