mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-25 22:08:59 +00:00
This change unfortunately cannot be atomically made without a single commit changing everything. Most of the important changes are in LibIPC/Connection.cpp, LibIPC/ServerConnection.cpp and LibCore/LocalServer.cpp. The notable changes are: - IPCCompiler now generates the decode and decode_message functions such that they take a Core::Stream::LocalSocket instead of the socket fd. - IPC::Decoder now uses the receive_fd method of LocalSocket instead of doing system calls directly on the fd. - IPC::ConnectionBase and related classes now use the Stream API functions. - IPC::ServerConnection no longer constructs the socket itself; instead, a convenience macro, IPC_CLIENT_CONNECTION, is used in place of C_OBJECT and will generate a static try_create factory function for the ServerConnection subclass. The subclass is now responsible for passing the socket constructed in this function to its ServerConnection base; the socket is passed as the first argument to the constructor (as a NonnullOwnPtr<Core::Stream::LocalServer>) before any other arguments. - The functionality regarding taking over sockets from SystemServer has been moved to LibIPC/SystemServerTakeover.cpp. The Core::LocalSocket implementation of this functionality hasn't been deleted due to my intention of removing this class in the near future and to reduce noise on this (already quite noisy) PR.
60 lines
1.6 KiB
C++
60 lines
1.6 KiB
C++
/*
|
|
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibCore/AnonymousBuffer.h>
|
|
#include <LibImageDecoderClient/Client.h>
|
|
|
|
namespace ImageDecoderClient {
|
|
|
|
Client::Client(NonnullOwnPtr<Core::Stream::LocalSocket> socket)
|
|
: IPC::ServerConnection<ImageDecoderClientEndpoint, ImageDecoderServerEndpoint>(*this, move(socket))
|
|
{
|
|
}
|
|
|
|
void Client::die()
|
|
{
|
|
if (on_death)
|
|
on_death();
|
|
}
|
|
|
|
Optional<DecodedImage> Client::decode_image(ReadonlyBytes encoded_data)
|
|
{
|
|
if (encoded_data.is_empty())
|
|
return {};
|
|
|
|
auto encoded_buffer_or_error = Core::AnonymousBuffer::create_with_size(encoded_data.size());
|
|
if (encoded_buffer_or_error.is_error()) {
|
|
dbgln("Could not allocate encoded buffer");
|
|
return {};
|
|
}
|
|
auto encoded_buffer = encoded_buffer_or_error.release_value();
|
|
|
|
memcpy(encoded_buffer.data<void>(), encoded_data.data(), encoded_data.size());
|
|
auto response_or_error = try_decode_image(move(encoded_buffer));
|
|
|
|
if (response_or_error.is_error()) {
|
|
dbgln("ImageDecoder died heroically");
|
|
return {};
|
|
}
|
|
|
|
auto& response = response_or_error.value();
|
|
|
|
if (response.bitmaps().is_empty())
|
|
return {};
|
|
|
|
DecodedImage image;
|
|
image.is_animated = response.is_animated();
|
|
image.loop_count = response.loop_count();
|
|
image.frames.resize(response.bitmaps().size());
|
|
for (size_t i = 0; i < image.frames.size(); ++i) {
|
|
auto& frame = image.frames[i];
|
|
frame.bitmap = response.bitmaps()[i].bitmap();
|
|
frame.duration = response.durations()[i];
|
|
}
|
|
return image;
|
|
}
|
|
|
|
}
|