فهرست منبع

LibGfx: Make Gfx::Bitmap::create_shareable() use an anonymous file

Note that this is only used by OOPWV in LibWeb at the moment.
Andreas Kling 4 سال پیش
والد
کامیت
04b2aeef33
1فایلهای تغییر یافته به همراه6 افزوده شده و 3 حذف شده
  1. 6 3
      Userland/Libraries/LibGfx/Bitmap.cpp

+ 6 - 3
Userland/Libraries/LibGfx/Bitmap.cpp

@@ -103,6 +103,7 @@ RefPtr<Bitmap> Bitmap::create_purgeable(BitmapFormat format, const IntSize& size
     return adopt(*new Bitmap(format, size, Purgeable::Yes, backing_store.value()));
 }
 
+#ifdef __serenity__
 RefPtr<Bitmap> Bitmap::create_shareable(BitmapFormat format, const IntSize& size)
 {
     if (size_would_overflow(format, size))
@@ -110,11 +111,13 @@ RefPtr<Bitmap> Bitmap::create_shareable(BitmapFormat format, const IntSize& size
 
     const auto pitch = minimum_pitch(size.width(), format);
     const auto data_size = size_in_bytes(pitch, size.height());
-    auto shared_buffer = SharedBuffer::create_with_size(data_size);
-    if (!shared_buffer)
+
+    auto anon_fd = anon_create(round_up_to_power_of_two(data_size, PAGE_SIZE), O_CLOEXEC);
+    if (anon_fd < 0)
         return nullptr;
-    return adopt(*new Bitmap(format, shared_buffer.release_nonnull(), size, Vector<RGBA32>()));
+    return Bitmap::create_with_anon_fd(format, anon_fd, size, ShouldCloseAnonymousFile::No);
 }
+#endif
 
 Bitmap::Bitmap(BitmapFormat format, const IntSize& size, Purgeable purgeable, const BackingStore& backing_store)
     : m_size(size)