From 58b435f49e58be34755b317ac7405e8722855bd2 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 16 Jan 2021 11:23:22 +0100 Subject: LibGfx: Short-circuit ShareableBitmap construction in IPC decoder When decoding a ShareableBitmap that came over IPC, it's safe to assume that it's backed by an anonymous file (since we just decoded it.) --- Userland/Libraries/LibGfx/ShareableBitmap.cpp | 9 ++++++++- Userland/Libraries/LibGfx/ShareableBitmap.h | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'Userland/Libraries/LibGfx') diff --git a/Userland/Libraries/LibGfx/ShareableBitmap.cpp b/Userland/Libraries/LibGfx/ShareableBitmap.cpp index 2ab5ece797..1edf498096 100644 --- a/Userland/Libraries/LibGfx/ShareableBitmap.cpp +++ b/Userland/Libraries/LibGfx/ShareableBitmap.cpp @@ -38,6 +38,11 @@ ShareableBitmap::ShareableBitmap(const Bitmap& bitmap) { } +ShareableBitmap::ShareableBitmap(NonnullRefPtr bitmap, Tag) + : m_bitmap(move(bitmap)) +{ +} + } namespace IPC { @@ -70,7 +75,9 @@ bool decode(Decoder& decoder, Gfx::ShareableBitmap& shareable_bitmap) return false; 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(); + if (!bitmap) + return false; + shareable_bitmap = Gfx::ShareableBitmap { bitmap.release_nonnull(), Gfx::ShareableBitmap::ConstructWithKnownGoodBitmap }; return true; } diff --git a/Userland/Libraries/LibGfx/ShareableBitmap.h b/Userland/Libraries/LibGfx/ShareableBitmap.h index 06ef331c54..d6eecd3cbb 100644 --- a/Userland/Libraries/LibGfx/ShareableBitmap.h +++ b/Userland/Libraries/LibGfx/ShareableBitmap.h @@ -37,6 +37,9 @@ public: ShareableBitmap() { } explicit ShareableBitmap(const Gfx::Bitmap&); + enum Tag { ConstructWithKnownGoodBitmap }; + ShareableBitmap(NonnullRefPtr, Tag); + bool is_valid() const { return m_bitmap; } const Bitmap* bitmap() const { return m_bitmap; } -- cgit v1.2.3