1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:48:10 +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:
Jean-Baptiste Boric 2021-05-24 12:24:38 +02:00 committed by Andreas Kling
parent de395a3df2
commit e4394b1605
5 changed files with 41 additions and 75 deletions

View file

@ -23,7 +23,6 @@
#include <LibGUI/WindowServerConnection.h>
#include <LibGfx/Bitmap.h>
#include <fcntl.h>
#include <serenity.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -744,7 +743,7 @@ void Window::set_hovered_widget(Widget* widget)
void Window::set_current_backing_store(WindowBackingStore& backing_store, bool flush_immediately)
{
auto& bitmap = backing_store.bitmap();
WindowServerConnection::the().set_window_backing_store(m_window_id, 32, bitmap.pitch(), bitmap.anon_fd(), backing_store.serial(), bitmap.has_alpha_channel(), bitmap.size(), flush_immediately);
WindowServerConnection::the().set_window_backing_store(m_window_id, 32, bitmap.pitch(), bitmap.anonymous_buffer().fd(), backing_store.serial(), bitmap.has_alpha_channel(), bitmap.size(), flush_immediately);
}
void Window::flip(const Vector<Gfx::IntRect, 32>& dirty_rects)
@ -777,14 +776,14 @@ OwnPtr<WindowBackingStore> Window::create_backing_store(const Gfx::IntSize& size
size_t pitch = Gfx::Bitmap::minimum_pitch(size.width(), format);
size_t size_in_bytes = size.height() * pitch;
auto anon_fd = anon_create(round_up_to_power_of_two(size_in_bytes, PAGE_SIZE), O_CLOEXEC);
if (anon_fd < 0) {
auto buffer = Core::AnonymousBuffer::create_with_size(round_up_to_power_of_two(size_in_bytes, PAGE_SIZE));
if (!buffer.is_valid()) {
perror("anon_create");
return {};
}
// FIXME: Plumb scale factor here eventually.
auto bitmap = Gfx::Bitmap::create_with_anon_fd(format, anon_fd, size, 1, {}, Gfx::Bitmap::ShouldCloseAnonymousFile::No);
auto bitmap = Gfx::Bitmap::create_with_anonymous_buffer(format, buffer, size, 1, {});
if (!bitmap)
return {};
return make<WindowBackingStore>(bitmap.release_nonnull());