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.
This commit is contained in:
Aliaksandr Kalenik 2026-05-20 23:51:56 +02:00 committed by Alexander Kalenik
parent e181686f7e
commit 7127b2c854
3 changed files with 42 additions and 0 deletions

View file

@ -21,6 +21,7 @@ set(SOURCES
Font/WOFF2/Loader.cpp
FontCascadeList.cpp
GradientPainting.cpp
Matrix4x4.cpp
ImageFormats/AVIFLoader.cpp
ImageFormats/BMPLoader.cpp
ImageFormats/BMPWriter.cpp

View file

@ -0,0 +1,30 @@
/*
* 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;
}
}

View file

@ -11,6 +11,7 @@
#include <LibGfx/Matrix.h>
#include <LibGfx/Vector3.h>
#include <LibGfx/Vector4.h>
#include <LibIPC/Forward.h>
namespace Gfx {
@ -96,3 +97,13 @@ typedef Matrix4x4<double> DoubleMatrix4x4;
using Gfx::DoubleMatrix4x4;
using Gfx::FloatMatrix4x4;
using Gfx::Matrix4x4;
namespace IPC {
template<>
ErrorOr<void> encode(Encoder&, Gfx::FloatMatrix4x4 const&);
template<>
ErrorOr<Gfx::FloatMatrix4x4> decode(Decoder&);
}