mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 11:49:44 +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:
parent
0d8064fafc
commit
b871bc082c
Notes:
sideshowbarker
2024-07-16 21:45:42 +09:00
Author: https://github.com/ADKaster
Commit: b871bc082c
Pull-request: https://github.com/SerenityOS/serenity/pull/24028
Reviewed-by: https://github.com/LucasChollet
Reviewed-by: https://github.com/awesomekling
6 changed files with 132 additions and 31 deletions
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue