summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGfx
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
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')
-rw-r--r--Userland/Libraries/LibGfx/Color.cpp10
-rw-r--r--Userland/Libraries/LibGfx/Color.h2
-rw-r--r--Userland/Libraries/LibGfx/Point.cpp10
-rw-r--r--Userland/Libraries/LibGfx/Point.h2
-rw-r--r--Userland/Libraries/LibGfx/Rect.cpp10
-rw-r--r--Userland/Libraries/LibGfx/Rect.h2
-rw-r--r--Userland/Libraries/LibGfx/ShareableBitmap.cpp36
-rw-r--r--Userland/Libraries/LibGfx/ShareableBitmap.h2
-rw-r--r--Userland/Libraries/LibGfx/Size.cpp10
-rw-r--r--Userland/Libraries/LibGfx/Size.h2
10 files changed, 34 insertions, 52 deletions
diff --git a/Userland/Libraries/LibGfx/Color.cpp b/Userland/Libraries/LibGfx/Color.cpp
index 30bb560a72..f37984d9c6 100644
--- a/Userland/Libraries/LibGfx/Color.cpp
+++ b/Userland/Libraries/LibGfx/Color.cpp
@@ -13,7 +13,6 @@
#include <LibIPC/Decoder.h>
#include <LibIPC/Encoder.h>
#include <ctype.h>
-#include <stdio.h>
#include <stdlib.h>
namespace Gfx {
@@ -343,13 +342,12 @@ bool IPC::encode(IPC::Encoder& encoder, Color const& color)
return true;
}
-bool IPC::decode(IPC::Decoder& decoder, Color& color)
+ErrorOr<void> IPC::decode(IPC::Decoder& decoder, Color& color)
{
- u32 rgba = 0;
- if (!decoder.decode(rgba))
- return false;
+ u32 rgba;
+ TRY(decoder.decode(rgba));
color = Color::from_rgba(rgba);
- return true;
+ return {};
}
ErrorOr<void> AK::Formatter<Gfx::Color>::format(FormatBuilder& builder, Gfx::Color const& value)
diff --git a/Userland/Libraries/LibGfx/Color.h b/Userland/Libraries/LibGfx/Color.h
index 860c12f033..89ed8a3a4e 100644
--- a/Userland/Libraries/LibGfx/Color.h
+++ b/Userland/Libraries/LibGfx/Color.h
@@ -486,6 +486,6 @@ struct Formatter<Gfx::Color> : public Formatter<StringView> {
namespace IPC {
bool encode(Encoder&, Gfx::Color const&);
-bool decode(Decoder&, Gfx::Color&);
+ErrorOr<void> decode(Decoder&, Gfx::Color&);
}
diff --git a/Userland/Libraries/LibGfx/Point.cpp b/Userland/Libraries/LibGfx/Point.cpp
index c91c980735..901826f98e 100644
--- a/Userland/Libraries/LibGfx/Point.cpp
+++ b/Userland/Libraries/LibGfx/Point.cpp
@@ -57,16 +57,14 @@ bool encode(Encoder& encoder, Gfx::IntPoint const& point)
return true;
}
-bool decode(Decoder& decoder, Gfx::IntPoint& point)
+ErrorOr<void> decode(Decoder& decoder, Gfx::IntPoint& point)
{
int x = 0;
int y = 0;
- if (!decoder.decode(x))
- return false;
- if (!decoder.decode(y))
- return false;
+ TRY(decoder.decode(x));
+ TRY(decoder.decode(y));
point = { x, y };
- return true;
+ return {};
}
}
diff --git a/Userland/Libraries/LibGfx/Point.h b/Userland/Libraries/LibGfx/Point.h
index 809a504a43..59fe677106 100644
--- a/Userland/Libraries/LibGfx/Point.h
+++ b/Userland/Libraries/LibGfx/Point.h
@@ -291,7 +291,7 @@ struct Formatter<Gfx::Point<T>> : Formatter<StringView> {
namespace IPC {
bool encode(Encoder&, Gfx::IntPoint const&);
-bool decode(Decoder&, Gfx::IntPoint&);
+ErrorOr<void> decode(Decoder&, Gfx::IntPoint&);
}
diff --git a/Userland/Libraries/LibGfx/Rect.cpp b/Userland/Libraries/LibGfx/Rect.cpp
index 8fe8c1baeb..34ddd4f709 100644
--- a/Userland/Libraries/LibGfx/Rect.cpp
+++ b/Userland/Libraries/LibGfx/Rect.cpp
@@ -328,16 +328,14 @@ bool encode(Encoder& encoder, Gfx::IntRect const& rect)
return true;
}
-bool decode(Decoder& decoder, Gfx::IntRect& rect)
+ErrorOr<void> decode(Decoder& decoder, Gfx::IntRect& rect)
{
Gfx::IntPoint point;
Gfx::IntSize size;
- if (!decoder.decode(point))
- return false;
- if (!decoder.decode(size))
- return false;
+ TRY(decoder.decode(point));
+ TRY(decoder.decode(size));
rect = { point, size };
- return true;
+ return {};
}
}
diff --git a/Userland/Libraries/LibGfx/Rect.h b/Userland/Libraries/LibGfx/Rect.h
index ef61e965b8..293ebb592d 100644
--- a/Userland/Libraries/LibGfx/Rect.h
+++ b/Userland/Libraries/LibGfx/Rect.h
@@ -736,7 +736,7 @@ struct Formatter<Gfx::Rect<T>> : Formatter<StringView> {
namespace IPC {
-bool decode(Decoder&, Gfx::IntRect&);
bool encode(Encoder&, const Gfx::IntRect&);
+ErrorOr<void> decode(Decoder&, Gfx::IntRect&);
}
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 {};
}
}
diff --git a/Userland/Libraries/LibGfx/ShareableBitmap.h b/Userland/Libraries/LibGfx/ShareableBitmap.h
index e9616102dd..4601c93224 100644
--- a/Userland/Libraries/LibGfx/ShareableBitmap.h
+++ b/Userland/Libraries/LibGfx/ShareableBitmap.h
@@ -35,6 +35,6 @@ private:
namespace IPC {
bool encode(Encoder&, const Gfx::ShareableBitmap&);
-bool decode(Decoder&, Gfx::ShareableBitmap&);
+ErrorOr<void> decode(Decoder&, Gfx::ShareableBitmap&);
}
diff --git a/Userland/Libraries/LibGfx/Size.cpp b/Userland/Libraries/LibGfx/Size.cpp
index 28be84125a..dc122d13bc 100644
--- a/Userland/Libraries/LibGfx/Size.cpp
+++ b/Userland/Libraries/LibGfx/Size.cpp
@@ -33,16 +33,14 @@ bool encode(Encoder& encoder, Gfx::IntSize const& size)
return true;
}
-bool decode(Decoder& decoder, Gfx::IntSize& size)
+ErrorOr<void> decode(Decoder& decoder, Gfx::IntSize& size)
{
int width = 0;
int height = 0;
- if (!decoder.decode(width))
- return false;
- if (!decoder.decode(height))
- return false;
+ TRY(decoder.decode(width));
+ TRY(decoder.decode(height));
size = { width, height };
- return true;
+ return {};
}
}
diff --git a/Userland/Libraries/LibGfx/Size.h b/Userland/Libraries/LibGfx/Size.h
index 52e3ac514e..59d329acbe 100644
--- a/Userland/Libraries/LibGfx/Size.h
+++ b/Userland/Libraries/LibGfx/Size.h
@@ -189,6 +189,6 @@ struct Formatter<Gfx::Size<T>> : Formatter<StringView> {
namespace IPC {
bool encode(Encoder&, Gfx::IntSize const&);
-bool decode(Decoder&, Gfx::IntSize&);
+ErrorOr<void> decode(Decoder&, Gfx::IntSize&);
}