2020-02-14 20:58:14 -03:00
|
|
|
/*
|
2021-06-16 14:21:42 -03:00
|
|
|
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
2020-02-14 20:58:14 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-02-14 20:58:14 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <AK/String.h>
|
|
|
|
|
#include <LibGfx/Size.h>
|
2020-03-29 14:03:13 -03:00
|
|
|
#include <LibIPC/Decoder.h>
|
2020-05-12 13:05:43 -03:00
|
|
|
#include <LibIPC/Encoder.h>
|
2020-02-14 20:58:14 -03:00
|
|
|
|
|
|
|
|
namespace Gfx {
|
|
|
|
|
|
2020-07-26 01:31:47 -03:00
|
|
|
template<>
|
2020-06-10 05:57:59 -03:00
|
|
|
String IntSize::to_string() const
|
2020-02-14 20:58:14 -03:00
|
|
|
{
|
2021-01-03 11:26:47 -03:00
|
|
|
return String::formatted("[{}x{}]", m_width, m_height);
|
2020-02-14 20:58:14 -03:00
|
|
|
}
|
|
|
|
|
|
2020-07-26 01:31:47 -03:00
|
|
|
template<>
|
|
|
|
|
String FloatSize::to_string() const
|
2020-02-14 20:58:14 -03:00
|
|
|
{
|
2021-01-03 11:26:47 -03:00
|
|
|
return String::formatted("[{}x{}]", m_width, m_height);
|
2020-02-14 20:58:14 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2020-02-15 08:04:35 -03:00
|
|
|
|
|
|
|
|
namespace IPC {
|
|
|
|
|
|
2021-06-16 14:20:35 -03:00
|
|
|
bool encode(Encoder& encoder, Gfx::IntSize const& size)
|
2020-05-12 13:05:43 -03:00
|
|
|
{
|
|
|
|
|
encoder << size.width() << size.height();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-10 05:57:59 -03:00
|
|
|
bool decode(Decoder& decoder, Gfx::IntSize& size)
|
2020-02-15 08:04:35 -03:00
|
|
|
{
|
2020-02-22 21:32:00 -03:00
|
|
|
int width = 0;
|
|
|
|
|
int height = 0;
|
2020-03-29 14:03:13 -03:00
|
|
|
if (!decoder.decode(width))
|
|
|
|
|
return false;
|
|
|
|
|
if (!decoder.decode(height))
|
2020-02-15 08:04:35 -03:00
|
|
|
return false;
|
|
|
|
|
size = { width, height };
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2020-07-26 01:31:47 -03:00
|
|
|
|
|
|
|
|
template class Gfx::Size<int>;
|
|
|
|
|
template class Gfx::Size<float>;
|