ImageDecoder: Handle decoding of images in an asynchronous manner

ImageDecoder now queues up image decoding requests and returns the
images back to the caller later. ImageDecoderClient has a new
promise-based API that allows callers to attach their own resolve/reject
handlers to the responses from ImageDecoder.
This commit is contained in:
Andrew Kaster 2024-04-19 14:23:16 -06:00 committed by Andrew Kaster
commit b871bc082c
Notes: sideshowbarker 2024-07-16 21:45:42 +09:00
6 changed files with 132 additions and 31 deletions

View file

@ -9,6 +9,7 @@
#include <AK/HashMap.h>
#include <ImageDecoder/ImageDecoderClientEndpoint.h>
#include <ImageDecoder/ImageDecoderServerEndpoint.h>
#include <LibCore/Promise.h>
#include <LibIPC/ConnectionToServer.h>
namespace ImageDecoderClient {
@ -33,12 +34,20 @@ class Client final
public:
Client(NonnullOwnPtr<Core::LocalSocket>);
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 = {});
// FIXME: Move all clients to the promise-based API and get rid of this synchronous (i.e. EventLoop-spinning) one.
Optional<DecodedImage> decode_image(ReadonlyBytes, Optional<Gfx::IntSize> ideal_size = {}, Optional<ByteString> mime_type = {});
Function<void()> on_death;
private:
virtual void die() override;
virtual void did_decode_image(i64 image_id, bool is_animated, u32 loop_count, Vector<Gfx::ShareableBitmap> const& bitmaps, Vector<u32> const& durations, Gfx::FloatPoint scale) override;
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;
};
}