mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-06 00:25:12 +00:00
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:
committed by
Andrew Kaster
parent
0d8064fafc
commit
b871bc082c
@@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user