/* * Copyright (c) 2020, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include namespace ImageDecoderClient { struct Frame { NonnullRefPtr bitmap; u32 duration { 0 }; }; struct DecodedImage { bool is_animated { false }; Gfx::FloatPoint scale { 1, 1 }; u32 loop_count { 0 }; u32 frame_count { 0 }; Vector frames; Vector all_durations; Gfx::ColorSpace color_space; i64 session_id { 0 }; }; class Client final : public IPC::ConnectionToServer , public ImageDecoderClientEndpoint { C_OBJECT_ABSTRACT(Client); public: using InitTransport = Messages::ImageDecoderServer::InitTransport; Client(NonnullOwnPtr); NonnullRefPtr> decode_image(ReadonlyBytes, Function(DecodedImage&)> on_resolved, Function on_rejected, Optional ideal_size = {}, Optional mime_type = {}); void request_animation_frames(i64 session_id, u32 start_frame_index, u32 count); void stop_animation_decode(i64 session_id); Function on_death; Function>)> on_animation_frames_decoded; Function on_animation_decode_failed; private: void verify_event_loop() const; virtual void die() override; virtual void did_decode_image(i64 request_id, bool is_animated, u32 loop_count, Gfx::BitmapSequence bitmap_sequence, Vector durations, Gfx::FloatPoint scale, Gfx::ColorSpace color_space, i64 session_id) override; virtual void did_fail_to_decode_image(i64 request_id, String error_message) override; virtual void did_decode_animation_frames(i64 session_id, Gfx::BitmapSequence bitmaps) override; virtual void did_fail_animation_decode(i64 session_id, String error_message) override; Core::EventLoop* m_creation_event_loop { &Core::EventLoop::current() }; i64 m_next_request_id { 0 }; HashMap>> m_token_promises; }; }