ladybird/Libraries/LibWeb/PixelUnits.cpp
Aliaksandr Kalenik cded122a2d 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.
2026-05-21 11:45:06 +01:00

66 lines
1.5 KiB
C++

/*
* Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Math.h>
#include <LibIPC/Decoder.h>
#include <LibIPC/Encoder.h>
#include <LibWeb/PixelUnits.h>
namespace Web {
}
namespace IPC {
template<>
ErrorOr<void> encode(Encoder& encoder, Web::DevicePixelPoint const& value)
{
TRY(encoder.encode(value.x()));
TRY(encoder.encode(value.y()));
return {};
}
template<>
ErrorOr<Web::DevicePixelPoint> decode(Decoder& decoder)
{
auto x = TRY(decoder.decode<Web::DevicePixels>());
auto y = TRY(decoder.decode<Web::DevicePixels>());
return Web::DevicePixelPoint { x, y };
}
template<>
ErrorOr<void> encode(Encoder& encoder, Web::DevicePixelSize const& value)
{
TRY(encoder.encode(value.width()));
TRY(encoder.encode(value.height()));
return {};
}
template<>
ErrorOr<Web::DevicePixelSize> decode(Decoder& decoder)
{
auto width = TRY(decoder.decode<Web::DevicePixels>());
auto height = TRY(decoder.decode<Web::DevicePixels>());
return Web::DevicePixelSize { width, height };
}
template<>
ErrorOr<void> encode(Encoder& encoder, Web::DevicePixelRect const& value)
{
TRY(encoder.encode(value.location()));
TRY(encoder.encode(value.size()));
return {};
}
template<>
ErrorOr<Web::DevicePixelRect> decode(Decoder& decoder)
{
auto location = TRY(decoder.decode<Web::DevicePixelPoint>());
auto size = TRY(decoder.decode<Web::DevicePixelSize>());
return Web::DevicePixelRect { location, size };
}
}