2020-06-22 19:35:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-06-22 19:35:22 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/HashMap.h>
|
|
|
|
#include <ImageDecoder/ImageDecoderClientEndpoint.h>
|
|
|
|
#include <ImageDecoder/ImageDecoderServerEndpoint.h>
|
2024-04-19 20:23:16 +00:00
|
|
|
#include <LibCore/Promise.h>
|
2022-02-25 10:27:37 +00:00
|
|
|
#include <LibIPC/ConnectionToServer.h>
|
2020-06-22 19:35:22 +00:00
|
|
|
|
|
|
|
namespace ImageDecoderClient {
|
|
|
|
|
2021-01-29 21:30:48 +00:00
|
|
|
struct Frame {
|
2023-10-01 18:56:19 +00:00
|
|
|
NonnullRefPtr<Gfx::Bitmap> bitmap;
|
2021-01-29 21:30:48 +00:00
|
|
|
u32 duration { 0 };
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DecodedImage {
|
|
|
|
bool is_animated { false };
|
2024-02-14 06:15:06 +00:00
|
|
|
Gfx::FloatPoint scale { 1, 1 };
|
2021-01-29 21:30:48 +00:00
|
|
|
u32 loop_count { 0 };
|
|
|
|
Vector<Frame> frames;
|
|
|
|
};
|
|
|
|
|
2021-02-20 10:35:00 +00:00
|
|
|
class Client final
|
2022-02-25 10:27:37 +00:00
|
|
|
: public IPC::ConnectionToServer<ImageDecoderClientEndpoint, ImageDecoderServerEndpoint>
|
2020-06-22 19:35:22 +00:00
|
|
|
, public ImageDecoderClientEndpoint {
|
2022-09-06 06:04:06 +00:00
|
|
|
IPC_CLIENT_CONNECTION(Client, "/tmp/session/%sid/portal/image"sv);
|
2020-06-22 19:35:22 +00:00
|
|
|
|
|
|
|
public:
|
2023-09-08 10:30:50 +00:00
|
|
|
Client(NonnullOwnPtr<Core::LocalSocket>);
|
|
|
|
|
2024-04-19 20:23:16 +00:00
|
|
|
NonnullRefPtr<Core::Promise<DecodedImage>> decode_image(ReadonlyBytes, Function<ErrorOr<void>(DecodedImage&)> on_resolved, Function<void(Error&)> on_rejected, Optional<Gfx::IntSize> ideal_size = {}, Optional<ByteString> mime_type = {});
|
|
|
|
|
2021-02-20 10:35:00 +00:00
|
|
|
Function<void()> on_death;
|
|
|
|
|
2020-06-22 19:35:22 +00:00
|
|
|
private:
|
2021-02-20 10:35:00 +00:00
|
|
|
virtual void die() override;
|
2024-04-19 20:23:16 +00:00
|
|
|
|
2024-07-17 17:14:44 +00:00
|
|
|
virtual void did_decode_image(i64 image_id, bool is_animated, u32 loop_count, Vector<Optional<NonnullRefPtr<Gfx::Bitmap>>> const& bitmaps, Vector<u32> const& durations, Gfx::FloatPoint scale) override;
|
2024-04-19 20:23:16 +00:00
|
|
|
virtual void did_fail_to_decode_image(i64 image_id, String const& error_message) override;
|
|
|
|
|
|
|
|
HashMap<i64, NonnullRefPtr<Core::Promise<DecodedImage>>> m_pending_decoded_images;
|
2020-06-22 19:35:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|