1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 14:17:34 +00:00

LibCore: Use ErrorOr<T> in Core::AnonymousBuffer

This commit is contained in:
Andreas Kling 2021-11-06 01:20:51 +01:00
parent c4edb9f6c2
commit e2eabb4132
15 changed files with 56 additions and 53 deletions

View file

@ -62,7 +62,9 @@ void ClipboardServerConnection::set_bitmap(Gfx::Bitmap const& bitmap)
metadata.set("format", String::number((int)bitmap.format()));
metadata.set("pitch", String::number(bitmap.pitch()));
ReadonlyBytes data { bitmap.scanline(0), bitmap.size_in_bytes() };
auto buffer = Core::AnonymousBuffer::create_with_size(bitmap.size_in_bytes());
auto buffer_or_error = Core::AnonymousBuffer::create_with_size(bitmap.size_in_bytes());
VERIFY(!buffer_or_error.is_error());
auto buffer = buffer_or_error.release_value();
memcpy(buffer.data<u8>(), data.data(), data.size());
this->async_set_clipboard_data(buffer, "image/x-serenityos", metadata);
}

View file

@ -133,7 +133,9 @@ void SpiceAgent::on_message_received()
m_just_set_clip = true;
if (type == ClipboardType::Text) {
auto anon_buffer = Core::AnonymousBuffer::create_with_size(data_buffer.size());
auto anon_buffer_or_error = Core::AnonymousBuffer::create_with_size(data_buffer.size());
VERIFY(!anon_buffer_or_error.is_error());
auto anon_buffer = anon_buffer_or_error.release_value();
memcpy(anon_buffer.data<void>(), data_buffer.data(), data_buffer.size());
m_clipboard_connection.async_set_clipboard_data(anon_buffer, "text/plain", {});
return;

View file

@ -34,7 +34,9 @@ PageHost::~PageHost()
void PageHost::setup_palette()
{
// FIXME: Get the proper palette from our peer somehow
auto buffer = Core::AnonymousBuffer::create_with_size(sizeof(Gfx::SystemTheme));
auto buffer_or_error = Core::AnonymousBuffer::create_with_size(sizeof(Gfx::SystemTheme));
VERIFY(!buffer_or_error.is_error());
auto buffer = buffer_or_error.release_value();
auto* theme = buffer.data<Gfx::SystemTheme>();
theme->color[(int)Gfx::ColorRole::Window] = Color::Magenta;
theme->color[(int)Gfx::ColorRole::WindowText] = Color::Cyan;

View file

@ -635,14 +635,14 @@ void ClientConnection::set_window_backing_store(i32 window_id, [[maybe_unused]]
window.swap_backing_stores();
} else {
// FIXME: Plumb scale factor here eventually.
Core::AnonymousBuffer buffer = Core::AnonymousBuffer::create_from_anon_fd(anon_file.take_fd(), pitch * size.height());
if (!buffer.is_valid()) {
auto buffer_or_error = Core::AnonymousBuffer::create_from_anon_fd(anon_file.take_fd(), pitch * size.height());
if (buffer_or_error.is_error()) {
did_misbehave("SetWindowBackingStore: Failed to create anonymous buffer for window backing store");
return;
}
auto backing_store = Gfx::Bitmap::try_create_with_anonymous_buffer(
has_alpha_channel ? Gfx::BitmapFormat::BGRA8888 : Gfx::BitmapFormat::BGRx8888,
move(buffer),
buffer_or_error.release_value(),
size,
1,
{});