summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGfx/ShareableBitmap.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-11-28 11:56:31 +0100
committerAndreas Kling <kling@serenityos.org>2021-11-28 23:14:19 +0100
commitcb9cac4e4002d6f2d5a16c7344dfb5393cec2b56 (patch)
treedaa183f9f73c17d0e72e0d0bd7b89ecbf0f6fdbe /Userland/Libraries/LibGfx/ShareableBitmap.cpp
parent8d76eb773f25b1e51ef923734cd355692f014ce5 (diff)
downloadserenity-cb9cac4e4002d6f2d5a16c7344dfb5393cec2b56.zip
LibIPC+IPCCompiler+AK: Make IPC value decoders return ErrorOr<void>
This allows us to use TRY() in decoding helpers, leading to a nice reduction in line count.
Diffstat (limited to 'Userland/Libraries/LibGfx/ShareableBitmap.cpp')
-rw-r--r--Userland/Libraries/LibGfx/ShareableBitmap.cpp36
1 files changed, 13 insertions, 23 deletions
diff --git a/Userland/Libraries/LibGfx/ShareableBitmap.cpp b/Userland/Libraries/LibGfx/ShareableBitmap.cpp
index 44d1de68d5..70f6d2dc9a 100644
--- a/Userland/Libraries/LibGfx/ShareableBitmap.cpp
+++ b/Userland/Libraries/LibGfx/ShareableBitmap.cpp
@@ -39,43 +39,33 @@ bool encode(Encoder& encoder, const Gfx::ShareableBitmap& shareable_bitmap)
return true;
}
-bool decode(Decoder& decoder, Gfx::ShareableBitmap& shareable_bitmap)
+ErrorOr<void> decode(Decoder& decoder, Gfx::ShareableBitmap& shareable_bitmap)
{
bool valid = false;
- if (!decoder.decode(valid))
- return false;
+ TRY(decoder.decode(valid));
if (!valid) {
shareable_bitmap = {};
- return true;
+ return {};
}
IPC::File anon_file;
- if (!decoder.decode(anon_file))
- return false;
+ TRY(decoder.decode(anon_file));
Gfx::IntSize size;
- if (!decoder.decode(size))
- return false;
+ TRY(decoder.decode(size));
u32 scale;
- if (!decoder.decode(scale))
- return false;
+ TRY(decoder.decode(scale));
u32 raw_bitmap_format;
- if (!decoder.decode(raw_bitmap_format))
- return false;
+ TRY(decoder.decode(raw_bitmap_format));
if (!Gfx::is_valid_bitmap_format(raw_bitmap_format))
- return false;
+ return Error::from_string_literal("IPC: Invalid Gfx::ShareableBitmap format"sv);
auto bitmap_format = (Gfx::BitmapFormat)raw_bitmap_format;
Vector<Gfx::RGBA32> palette;
if (Gfx::Bitmap::is_indexed(bitmap_format)) {
- if (!decoder.decode(palette))
- return false;
+ TRY(decoder.decode(palette));
}
- auto buffer_or_error = Core::AnonymousBuffer::create_from_anon_fd(anon_file.take_fd(), Gfx::Bitmap::size_in_bytes(Gfx::Bitmap::minimum_pitch(size.width(), bitmap_format), size.height()));
- if (buffer_or_error.is_error())
- return false;
- auto bitmap_or_error = Gfx::Bitmap::try_create_with_anonymous_buffer(bitmap_format, buffer_or_error.release_value(), size, scale, palette);
- if (bitmap_or_error.is_error())
- return false;
- shareable_bitmap = Gfx::ShareableBitmap { bitmap_or_error.release_value(), Gfx::ShareableBitmap::ConstructWithKnownGoodBitmap };
- return true;
+ auto buffer = TRY(Core::AnonymousBuffer::create_from_anon_fd(anon_file.take_fd(), Gfx::Bitmap::size_in_bytes(Gfx::Bitmap::minimum_pitch(size.width(), bitmap_format), size.height())));
+ auto bitmap = TRY(Gfx::Bitmap::try_create_with_anonymous_buffer(bitmap_format, move(buffer), size, scale, palette));
+ shareable_bitmap = Gfx::ShareableBitmap { move(bitmap), Gfx::ShareableBitmap::ConstructWithKnownGoodBitmap };
+ return {};
}
}