Skip to content

Truly independent web browser

LibGfx: Generate the IPC codecs of points, sizes and rectangles

Andreas Kling002328d86ed2
diff --git a/Libraries/LibGfx/CMakeLists.txt b/Libraries/LibGfx/CMakeLists.txt
index 28bf16d998e..d29b246a5f7 100644
--- a/Libraries/LibGfx/CMakeLists.txt
+++ b/Libraries/LibGfx/CMakeLists.txt
@@ -76,6 +76,10 @@ if (HAS_FONTCONFIG)
list(APPEND SOURCES Font/GlobalFontConfig.cpp)
endif()
+compile_ipc(Point.ipc PointCodecs.h)
+compile_ipc(Rect.ipc RectCodecs.h)
+compile_ipc(Size.ipc SizeCodecs.h)
+
ladybird_lib(LibGfx gfx)
target_link_libraries(LibGfx PRIVATE LibCompress LibCore LibCrypto LibFileSystem LibTextCodec LibIPC LibUnicode)
diff --git a/Libraries/LibGfx/Point.cpp b/Libraries/LibGfx/Point.cpp
index 81710701b0c..39ad166c140 100644
--- a/Libraries/LibGfx/Point.cpp
+++ b/Libraries/LibGfx/Point.cpp
@@ -7,8 +7,6 @@
#include <AK/ByteString.h>
#include <LibGfx/Point.h>
#include <LibGfx/Rect.h>
-#include <LibIPC/Decoder.h>
-#include <LibIPC/Encoder.h>
namespace Gfx {
@@ -49,41 +47,5 @@ ByteString FloatPoint::to_byte_string() const
}
-namespace IPC {
-
-template<>
-ErrorOr<void> encode(Encoder& encoder, Gfx::IntPoint const& point)
-{
- TRY(encoder.encode(point.x()));
- TRY(encoder.encode(point.y()));
- return {};
-}
-
-template<>
-ErrorOr<void> encode(Encoder& encoder, Gfx::FloatPoint const& point)
-{
- TRY(encoder.encode(point.x()));
- TRY(encoder.encode(point.y()));
- return {};
-}
-
-template<>
-ErrorOr<Gfx::IntPoint> decode(Decoder& decoder)
-{
- auto x = TRY(decoder.decode<int>());
- auto y = TRY(decoder.decode<int>());
- return Gfx::IntPoint { x, y };
-}
-
-template<>
-ErrorOr<Gfx::FloatPoint> decode(Decoder& decoder)
-{
- auto x = TRY(decoder.decode<float>());
- auto y = TRY(decoder.decode<float>());
- return Gfx::FloatPoint { x, y };
-}
-
-}
-
template class Gfx::Point<int>;
template class Gfx::Point<float>;
diff --git a/Libraries/LibGfx/Point.h b/Libraries/LibGfx/Point.h
index ed0223b0dda..2d741d8ecd1 100644
--- a/Libraries/LibGfx/Point.h
+++ b/Libraries/LibGfx/Point.h
@@ -11,7 +11,6 @@
#include <AK/StdLibExtras.h>
#include <LibGfx/Forward.h>
#include <LibGfx/Orientation.h>
-#include <LibIPC/Forward.h>
#include <math.h>
namespace Gfx {
@@ -292,19 +291,7 @@ struct Formatter<Gfx::Point<T>> : Formatter<FormatString> {
}
-namespace IPC {
-
-template<>
-ErrorOr<void> encode(Encoder&, Gfx::IntPoint const&);
-template<>
-ErrorOr<void> encode(Encoder&, Gfx::FloatPoint const&);
-
-template<>
-ErrorOr<Gfx::IntPoint> decode(Decoder&);
-template<>
-ErrorOr<Gfx::FloatPoint> decode(Decoder&);
-
-}
+#include <LibGfx/PointCodecs.h>
template<typename T>
struct AK::Traits<Gfx::Point<T>> : public AK::DefaultTraits<Gfx::Point<T>> {
diff --git a/Libraries/LibGfx/Point.ipc b/Libraries/LibGfx/Point.ipc
new file mode 100644
index 00000000000..903de78232f
--- /dev/null
+++ b/Libraries/LibGfx/Point.ipc
@@ -0,0 +1,15 @@
+// Copyright (c) 2026-present, the Ladybird developers.
+
+#include <LibGfx/Point.h>
+
+[ExistingCpp, Accessors]
+struct Gfx::IntPoint {
+ i32 x;
+ i32 y;
+}
+
+[ExistingCpp, Accessors]
+struct Gfx::FloatPoint {
+ float x;
+ float y;
+}
diff --git a/Libraries/LibGfx/Rect.cpp b/Libraries/LibGfx/Rect.cpp
index 71c67ced831..1a767731c29 100644
--- a/Libraries/LibGfx/Rect.cpp
+++ b/Libraries/LibGfx/Rect.cpp
@@ -6,8 +6,6 @@
#include <AK/ByteString.h>
#include <LibGfx/Rect.h>
-#include <LibIPC/Decoder.h>
-#include <LibIPC/Encoder.h>
namespace Gfx {
@@ -25,45 +23,5 @@ ByteString FloatRect::to_byte_string() const
}
-namespace IPC {
-
-template<>
-ErrorOr<void> encode(Encoder& encoder, Gfx::IntRect const& rect)
-{
- TRY(encoder.encode(rect.location()));
- TRY(encoder.encode(rect.size()));
- return {};
-}
-
-template<>
-ErrorOr<Gfx::IntRect> decode(Decoder& decoder)
-{
- auto point = TRY(decoder.decode<Gfx::IntPoint>());
- auto size = TRY(decoder.decode<Gfx::IntSize>());
- return Gfx::IntRect { point, size };
-}
-
-template<>
-ErrorOr<void> encode(Encoder& encoder, Gfx::FloatRect const& rect)
-{
- TRY(encoder.encode(rect.x()));
- TRY(encoder.encode(rect.y()));
- TRY(encoder.encode(rect.width()));
- TRY(encoder.encode(rect.height()));
- return {};
-}
-
-template<>
-ErrorOr<Gfx::FloatRect> decode(Decoder& decoder)
-{
- auto x = TRY(decoder.decode<float>());
- auto y = TRY(decoder.decode<float>());
- auto width = TRY(decoder.decode<float>());
- auto height = TRY(decoder.decode<float>());
- return Gfx::FloatRect { x, y, width, height };
-}
-
-}
-
template class Gfx::Rect<int>;
template class Gfx::Rect<float>;
diff --git a/Libraries/LibGfx/Rect.h b/Libraries/LibGfx/Rect.h
index 17486a2d131..adea7848324 100644
--- a/Libraries/LibGfx/Rect.h
+++ b/Libraries/LibGfx/Rect.h
@@ -612,18 +612,4 @@ struct Formatter<Gfx::Rect<T>> : Formatter<FormatString> {
}
-namespace IPC {
-
-template<>
-ErrorOr<void> encode(Encoder&, Gfx::IntRect const&);
-
-template<>
-ErrorOr<Gfx::IntRect> decode(Decoder&);
-
-template<>
-ErrorOr<void> encode(Encoder&, Gfx::FloatRect const&);
-
-template<>
-ErrorOr<Gfx::FloatRect> decode(Decoder&);
-
-}
+#include <LibGfx/RectCodecs.h>
diff --git a/Libraries/LibGfx/Rect.ipc b/Libraries/LibGfx/Rect.ipc
new file mode 100644
index 00000000000..fd68abb1f32
--- /dev/null
+++ b/Libraries/LibGfx/Rect.ipc
@@ -0,0 +1,19 @@
+// Copyright (c) 2026-present, the Ladybird developers.
+
+#include <LibGfx/Rect.h>
+
+[ExistingCpp, Accessors]
+struct Gfx::IntRect {
+ i32 x;
+ i32 y;
+ i32 width;
+ i32 height;
+}
+
+[ExistingCpp, Accessors]
+struct Gfx::FloatRect {
+ float x;
+ float y;
+ float width;
+ float height;
+}
diff --git a/Libraries/LibGfx/Size.cpp b/Libraries/LibGfx/Size.cpp
index 8db0c3532ea..d7e7313a897 100644
--- a/Libraries/LibGfx/Size.cpp
+++ b/Libraries/LibGfx/Size.cpp
@@ -6,8 +6,6 @@
#include <AK/ByteString.h>
#include <LibGfx/Size.h>
-#include <LibIPC/Decoder.h>
-#include <LibIPC/Encoder.h>
namespace Gfx {
@@ -25,25 +23,5 @@ ByteString FloatSize::to_byte_string() const
}
-namespace IPC {
-
-template<>
-ErrorOr<void> encode(Encoder& encoder, Gfx::IntSize const& size)
-{
- TRY(encoder.encode(size.width()));
- TRY(encoder.encode(size.height()));
- return {};
-}
-
-template<>
-ErrorOr<Gfx::IntSize> decode(Decoder& decoder)
-{
- auto width = TRY(decoder.decode<int>());
- auto height = TRY(decoder.decode<int>());
- return Gfx::IntSize { width, height };
-}
-
-}
-
template class Gfx::Size<int>;
template class Gfx::Size<float>;
diff --git a/Libraries/LibGfx/Size.h b/Libraries/LibGfx/Size.h
index 324c4e1f242..6cc145e5661 100644
--- a/Libraries/LibGfx/Size.h
+++ b/Libraries/LibGfx/Size.h
@@ -9,7 +9,6 @@
#include <AK/Format.h>
#include <LibGfx/Orientation.h>
#include <LibGfx/Point.h>
-#include <LibIPC/Forward.h>
namespace Gfx {
@@ -202,15 +201,7 @@ struct Formatter<Gfx::Size<T>> : Formatter<FormatString> {
}
-namespace IPC {
-
-template<>
-ErrorOr<void> encode(Encoder&, Gfx::IntSize const&);
-
-template<>
-ErrorOr<Gfx::IntSize> decode(Decoder&);
-
-}
+#include <LibGfx/SizeCodecs.h>
template<typename T>
struct AK::Traits<Gfx::Size<T>> : public AK::DefaultTraits<Gfx::Size<T>> {
diff --git a/Libraries/LibGfx/Size.ipc b/Libraries/LibGfx/Size.ipc
new file mode 100644
index 00000000000..fa28b532bfb
--- /dev/null
+++ b/Libraries/LibGfx/Size.ipc
@@ -0,0 +1,9 @@
+// Copyright (c) 2026-present, the Ladybird developers.
+
+#include <LibGfx/Size.h>
+
+[ExistingCpp, Accessors]
+struct Gfx::IntSize {
+ i32 width;
+ i32 height;
+}