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.
This commit is contained in:
parent
20285b23b3
commit
cded122a2d
7 changed files with 16 additions and 48 deletions
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/DistinctNumeric.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/Span.h>
|
||||
|
|
@ -64,4 +65,7 @@ concept Optional = SpecializationOf<T, AK::Optional>;
|
|||
template<typename T>
|
||||
concept Variant = SpecializationOf<T, AK::Variant>;
|
||||
|
||||
template<typename T>
|
||||
concept DistinctNumeric = SpecializationOf<T, AK::DistinctNumeric>;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,6 +84,12 @@ ErrorOr<T> decode(Decoder& decoder)
|
|||
return static_cast<T>(value);
|
||||
}
|
||||
|
||||
template<Concepts::DistinctNumeric T>
|
||||
ErrorOr<T> decode(Decoder& decoder)
|
||||
{
|
||||
return T { TRY(decoder.decode<typename T::Type>()) };
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<String> decode(Decoder&);
|
||||
|
||||
|
|
|
|||
|
|
@ -76,6 +76,12 @@ ErrorOr<void> encode(Encoder& encoder, T const& value)
|
|||
return encoder.encode(to_underlying(value));
|
||||
}
|
||||
|
||||
template<Concepts::DistinctNumeric T>
|
||||
ErrorOr<void> encode(Encoder& encoder, T const& value)
|
||||
{
|
||||
return encoder.encode(value.value());
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<void> encode(Encoder&, float const&);
|
||||
|
||||
|
|
|
|||
|
|
@ -12,8 +12,6 @@
|
|||
#include <AK/JsonObjectSerializer.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibGC/DeferGC.h>
|
||||
#include <LibIPC/Decoder.h>
|
||||
#include <LibIPC/Encoder.h>
|
||||
#include <LibJS/Runtime/ExternalMemory.h>
|
||||
#include <LibJS/Runtime/FunctionObject.h>
|
||||
#include <LibWeb/Animations/Animation.h>
|
||||
|
|
@ -3428,20 +3426,3 @@ GC::Ptr<ShadowRoot> Node::containing_shadow_root()
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
namespace IPC {
|
||||
|
||||
template<>
|
||||
ErrorOr<void> encode(Encoder& encoder, Web::UniqueNodeID const& value)
|
||||
{
|
||||
return encode(encoder, value.value());
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<Web::UniqueNodeID> decode(Decoder& decoder)
|
||||
{
|
||||
auto value = TRY(decoder.decode<i64>());
|
||||
return Web::UniqueNodeID(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1393,16 +1393,6 @@ struct FormDataEntry;
|
|||
|
||||
}
|
||||
|
||||
namespace IPC {
|
||||
|
||||
template<>
|
||||
WEB_API ErrorOr<void> encode(Encoder&, Web::UniqueNodeID const&);
|
||||
|
||||
template<>
|
||||
WEB_API ErrorOr<Web::UniqueNodeID> decode(Decoder&);
|
||||
|
||||
}
|
||||
|
||||
namespace Web::TrustedTypes {
|
||||
|
||||
class TrustedHTML;
|
||||
|
|
|
|||
|
|
@ -15,20 +15,6 @@ namespace Web {
|
|||
|
||||
namespace IPC {
|
||||
|
||||
template<>
|
||||
ErrorOr<void> encode(Encoder& encoder, Web::DevicePixels const& value)
|
||||
{
|
||||
TRY(encoder.encode(value.value()));
|
||||
return {};
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<Web::DevicePixels> decode(Decoder& decoder)
|
||||
{
|
||||
auto value = TRY(decoder.decode<int>());
|
||||
return Web::DevicePixels(value);
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<void> encode(Encoder& encoder, Web::DevicePixelPoint const& value)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -536,11 +536,6 @@ struct Formatter<Web::DevicePixels> : Formatter<Web::DevicePixels::Type> {
|
|||
|
||||
namespace IPC {
|
||||
|
||||
template<>
|
||||
WEB_API ErrorOr<void> encode(Encoder& encoder, Web::DevicePixels const& value);
|
||||
template<>
|
||||
WEB_API ErrorOr<Web::DevicePixels> decode(Decoder& decoder);
|
||||
|
||||
template<>
|
||||
WEB_API ErrorOr<void> encode(Encoder& encoder, Web::DevicePixelPoint const& value);
|
||||
template<>
|
||||
|
|
|
|||
Loading…
Reference in a new issue