2020-02-14 23:58:14 +00:00
|
|
|
/*
|
2024-10-04 11:19:50 +00:00
|
|
|
* Copyright (c) 2020-2021, Andreas Kling <andreas@ladybird.org>
|
2020-02-14 23:58:14 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-02-14 23:58:14 +00:00
|
|
|
*/
|
|
|
|
|
2023-12-16 14:19:34 +00:00
|
|
|
#include <AK/ByteString.h>
|
2020-02-14 23:58:14 +00:00
|
|
|
#include <LibGfx/Size.h>
|
2020-03-29 17:03:13 +00:00
|
|
|
#include <LibIPC/Decoder.h>
|
2020-05-12 16:05:43 +00:00
|
|
|
#include <LibIPC/Encoder.h>
|
2020-02-14 23:58:14 +00:00
|
|
|
|
|
|
|
namespace Gfx {
|
|
|
|
|
2020-07-26 04:31:47 +00:00
|
|
|
template<>
|
2023-12-16 14:19:34 +00:00
|
|
|
ByteString IntSize::to_byte_string() const
|
2020-02-14 23:58:14 +00:00
|
|
|
{
|
2023-12-16 14:19:34 +00:00
|
|
|
return ByteString::formatted("[{}x{}]", m_width, m_height);
|
2020-02-14 23:58:14 +00:00
|
|
|
}
|
|
|
|
|
2020-07-26 04:31:47 +00:00
|
|
|
template<>
|
2023-12-16 14:19:34 +00:00
|
|
|
ByteString FloatSize::to_byte_string() const
|
2020-02-14 23:58:14 +00:00
|
|
|
{
|
2023-12-16 14:19:34 +00:00
|
|
|
return ByteString::formatted("[{}x{}]", m_width, m_height);
|
2020-02-14 23:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-02-15 11:04:35 +00:00
|
|
|
|
|
|
|
namespace IPC {
|
|
|
|
|
2022-11-15 16:24:59 +00:00
|
|
|
template<>
|
2023-01-02 04:37:35 +00:00
|
|
|
ErrorOr<void> encode(Encoder& encoder, Gfx::IntSize const& size)
|
2020-05-12 16:05:43 +00:00
|
|
|
{
|
2023-01-02 04:37:35 +00:00
|
|
|
TRY(encoder.encode(size.width()));
|
|
|
|
TRY(encoder.encode(size.height()));
|
|
|
|
return {};
|
2020-05-12 16:05:43 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 16:24:59 +00:00
|
|
|
template<>
|
2022-12-23 01:40:33 +00:00
|
|
|
ErrorOr<Gfx::IntSize> decode(Decoder& decoder)
|
2020-02-15 11:04:35 +00:00
|
|
|
{
|
2022-12-23 01:40:33 +00:00
|
|
|
auto width = TRY(decoder.decode<int>());
|
|
|
|
auto height = TRY(decoder.decode<int>());
|
|
|
|
return Gfx::IntSize { width, height };
|
2020-02-15 11:04:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-07-26 04:31:47 +00:00
|
|
|
|
|
|
|
template class Gfx::Size<int>;
|
|
|
|
template class Gfx::Size<float>;
|