From cded122a2da36f7c24f2ea1acf131de0968bb625 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Wed, 20 May 2026 13:08:47 +0200 Subject: [PATCH] LibIPC: Support DistinctNumeric serialization IPC currently needs each distinct numeric wrapper to provide its own serialization specialization. That makes compositor resource ids and pixel-unit wrappers grow one-off glue as soon as they cross an endpoint. Teach LibIPC to serialize AK::DistinctNumeric wrappers through their underlying value type and remove the redundant Web-side specializations for UniqueNodeID and DevicePixels. Existing compound pixel-unit serializers now rely on generic wrapper support for their components. This is preparatory work required to add IPC between the main and compositor threads. --- Libraries/LibIPC/Concepts.h | 4 ++++ Libraries/LibIPC/Decoder.h | 6 ++++++ Libraries/LibIPC/Encoder.h | 6 ++++++ Libraries/LibWeb/DOM/Node.cpp | 19 ------------------- Libraries/LibWeb/Forward.h | 10 ---------- Libraries/LibWeb/PixelUnits.cpp | 14 -------------- Libraries/LibWeb/PixelUnits.h | 5 ----- 7 files changed, 16 insertions(+), 48 deletions(-) diff --git a/Libraries/LibIPC/Concepts.h b/Libraries/LibIPC/Concepts.h index 4573aa189a..e51a750989 100644 --- a/Libraries/LibIPC/Concepts.h +++ b/Libraries/LibIPC/Concepts.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include #include @@ -64,4 +65,7 @@ concept Optional = SpecializationOf; template concept Variant = SpecializationOf; +template +concept DistinctNumeric = SpecializationOf; + } diff --git a/Libraries/LibIPC/Decoder.h b/Libraries/LibIPC/Decoder.h index 3cf01ab26d..5a2abd1b2f 100644 --- a/Libraries/LibIPC/Decoder.h +++ b/Libraries/LibIPC/Decoder.h @@ -84,6 +84,12 @@ ErrorOr decode(Decoder& decoder) return static_cast(value); } +template +ErrorOr decode(Decoder& decoder) +{ + return T { TRY(decoder.decode()) }; +} + template<> ErrorOr decode(Decoder&); diff --git a/Libraries/LibIPC/Encoder.h b/Libraries/LibIPC/Encoder.h index 206b6f1ac3..07274ddd34 100644 --- a/Libraries/LibIPC/Encoder.h +++ b/Libraries/LibIPC/Encoder.h @@ -76,6 +76,12 @@ ErrorOr encode(Encoder& encoder, T const& value) return encoder.encode(to_underlying(value)); } +template +ErrorOr encode(Encoder& encoder, T const& value) +{ + return encoder.encode(value.value()); +} + template<> ErrorOr encode(Encoder&, float const&); diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp index a87b3f9b94..601541ff94 100644 --- a/Libraries/LibWeb/DOM/Node.cpp +++ b/Libraries/LibWeb/DOM/Node.cpp @@ -12,8 +12,6 @@ #include #include #include -#include -#include #include #include #include @@ -3428,20 +3426,3 @@ GC::Ptr Node::containing_shadow_root() } } - -namespace IPC { - -template<> -ErrorOr encode(Encoder& encoder, Web::UniqueNodeID const& value) -{ - return encode(encoder, value.value()); -} - -template<> -ErrorOr decode(Decoder& decoder) -{ - auto value = TRY(decoder.decode()); - return Web::UniqueNodeID(value); -} - -} diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.h index dc9d397074..2d380a7f3f 100644 --- a/Libraries/LibWeb/Forward.h +++ b/Libraries/LibWeb/Forward.h @@ -1393,16 +1393,6 @@ struct FormDataEntry; } -namespace IPC { - -template<> -WEB_API ErrorOr encode(Encoder&, Web::UniqueNodeID const&); - -template<> -WEB_API ErrorOr decode(Decoder&); - -} - namespace Web::TrustedTypes { class TrustedHTML; diff --git a/Libraries/LibWeb/PixelUnits.cpp b/Libraries/LibWeb/PixelUnits.cpp index a65752a6f0..77d25c22d5 100644 --- a/Libraries/LibWeb/PixelUnits.cpp +++ b/Libraries/LibWeb/PixelUnits.cpp @@ -15,20 +15,6 @@ namespace Web { namespace IPC { -template<> -ErrorOr encode(Encoder& encoder, Web::DevicePixels const& value) -{ - TRY(encoder.encode(value.value())); - return {}; -} - -template<> -ErrorOr decode(Decoder& decoder) -{ - auto value = TRY(decoder.decode()); - return Web::DevicePixels(value); -} - template<> ErrorOr encode(Encoder& encoder, Web::DevicePixelPoint const& value) { diff --git a/Libraries/LibWeb/PixelUnits.h b/Libraries/LibWeb/PixelUnits.h index ebfb370feb..dee398288e 100644 --- a/Libraries/LibWeb/PixelUnits.h +++ b/Libraries/LibWeb/PixelUnits.h @@ -536,11 +536,6 @@ struct Formatter : Formatter { namespace IPC { -template<> -WEB_API ErrorOr encode(Encoder& encoder, Web::DevicePixels const& value); -template<> -WEB_API ErrorOr decode(Decoder& decoder); - template<> WEB_API ErrorOr encode(Encoder& encoder, Web::DevicePixelPoint const& value); template<>