ladybird/Libraries/LibGfx/Matrix4x4.cpp
Aliaksandr Kalenik 7127b2c854 LibGfx: Add IPC serialization for FloatMatrix4x4
The compositor IPC path transports transform matrices as LibGfx values,
so the matrix type should own its byte representation. Add the
FloatMatrix4x4 specialization in a new LibGfx source file and serialize
the fixed-size float array directly through the IPC stream.

This is preparatory work required to add IPC between the main and
compositor threads.
2026-05-21 11:45:06 +01:00

30 lines
855 B
C++

/*
* Copyright (c) 2026-present, the Ladybird developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibGfx/Matrix4x4.h>
#include <LibIPC/Decoder.h>
#include <LibIPC/Encoder.h>
namespace IPC {
template<>
ErrorOr<void> encode(Encoder& encoder, Gfx::FloatMatrix4x4 const& matrix)
{
static constexpr size_t element_count = Gfx::FloatMatrix4x4::Size * Gfx::FloatMatrix4x4::Size;
TRY(encoder.append(reinterpret_cast<u8 const*>(matrix.elements()), element_count * sizeof(float)));
return {};
}
template<>
ErrorOr<Gfx::FloatMatrix4x4> decode(Decoder& decoder)
{
static constexpr size_t element_count = Gfx::FloatMatrix4x4::Size * Gfx::FloatMatrix4x4::Size;
Gfx::FloatMatrix4x4 matrix;
TRY(decoder.decode_into(Bytes { reinterpret_cast<u8*>(matrix.elements()), element_count * sizeof(float) }));
return matrix;
}
}