summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-01-16 11:23:22 +0100
committerAndreas Kling <kling@serenityos.org>2021-01-16 11:26:53 +0100
commit58b435f49e58be34755b317ac7405e8722855bd2 (patch)
tree19be1859ca265bd4fe7468d07a64431e7c04cdce /Userland/Libraries
parentf18d89b36d6762324af8ff420230b409efd95d81 (diff)
downloadserenity-58b435f49e58be34755b317ac7405e8722855bd2.zip
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.)
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibGfx/ShareableBitmap.cpp9
-rw-r--r--Userland/Libraries/LibGfx/ShareableBitmap.h3
2 files changed, 11 insertions, 1 deletions
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> 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<Gfx::Bitmap>, Tag);
+
bool is_valid() const { return m_bitmap; }
const Bitmap* bitmap() const { return m_bitmap; }