mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-25 17:25:08 +02:00
LibImageDecoderClient: Verify main thread in Client methods
This commit is contained in:
committed by
Gregory Bertilson
parent
edf1ca8f19
commit
1477d86b3e
Notes:
github-actions[bot]
2026-02-28 06:05:21 +00:00
Author: https://github.com/jonbgamble Commit: https://github.com/LadybirdBrowser/ladybird/commit/1477d86b3e2 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8073 Reviewed-by: https://github.com/Zaggy1024 ✅
@@ -16,6 +16,7 @@ Client::Client(NonnullOwnPtr<IPC::Transport> transport)
|
||||
|
||||
void Client::die()
|
||||
{
|
||||
verify_event_loop();
|
||||
for (auto& [_, promise] : m_pending_decoded_images) {
|
||||
promise->reject(Error::from_string_literal("ImageDecoder disconnected"));
|
||||
}
|
||||
@@ -24,6 +25,7 @@ void Client::die()
|
||||
|
||||
NonnullRefPtr<Core::Promise<DecodedImage>> Client::decode_image(ReadonlyBytes encoded_data, Function<ErrorOr<void>(DecodedImage&)> on_resolved, Function<void(Error&)> on_rejected, Optional<Gfx::IntSize> ideal_size, Optional<ByteString> mime_type)
|
||||
{
|
||||
verify_event_loop();
|
||||
auto promise = Core::Promise<DecodedImage>::construct();
|
||||
if (on_resolved)
|
||||
promise->on_resolution = move(on_resolved);
|
||||
@@ -59,6 +61,7 @@ NonnullRefPtr<Core::Promise<DecodedImage>> Client::decode_image(ReadonlyBytes en
|
||||
|
||||
void Client::did_decode_image(i64 image_id, bool is_animated, u32 loop_count, Gfx::BitmapSequence bitmap_sequence, Vector<u32> durations, Gfx::FloatPoint scale, Gfx::ColorSpace color_space, i64 session_id)
|
||||
{
|
||||
verify_event_loop();
|
||||
auto bitmaps = move(bitmap_sequence.bitmaps);
|
||||
VERIFY(!bitmaps.is_empty());
|
||||
|
||||
@@ -100,6 +103,7 @@ void Client::did_decode_image(i64 image_id, bool is_animated, u32 loop_count, Gf
|
||||
|
||||
void Client::did_fail_to_decode_image(i64 image_id, String error_message)
|
||||
{
|
||||
verify_event_loop();
|
||||
auto maybe_promise = m_pending_decoded_images.take(image_id);
|
||||
if (!maybe_promise.has_value()) {
|
||||
dbgln("ImageDecoderClient: No pending image with ID {}", image_id);
|
||||
@@ -114,6 +118,7 @@ void Client::did_fail_to_decode_image(i64 image_id, String error_message)
|
||||
|
||||
void Client::did_decode_animation_frames(i64 session_id, Gfx::BitmapSequence bitmap_sequence)
|
||||
{
|
||||
verify_event_loop();
|
||||
if (!on_animation_frames_decoded)
|
||||
return;
|
||||
|
||||
@@ -129,18 +134,27 @@ void Client::did_decode_animation_frames(i64 session_id, Gfx::BitmapSequence bit
|
||||
|
||||
void Client::did_fail_animation_decode(i64 session_id, String error_message)
|
||||
{
|
||||
verify_event_loop();
|
||||
if (on_animation_decode_failed)
|
||||
on_animation_decode_failed(session_id, move(error_message));
|
||||
}
|
||||
|
||||
void Client::request_animation_frames(i64 session_id, u32 start_frame_index, u32 count)
|
||||
{
|
||||
verify_event_loop();
|
||||
async_request_animation_frames(session_id, start_frame_index, count);
|
||||
}
|
||||
|
||||
void Client::stop_animation_decode(i64 session_id)
|
||||
{
|
||||
verify_event_loop();
|
||||
async_stop_animation_decode(session_id);
|
||||
}
|
||||
|
||||
void Client::verify_event_loop() const
|
||||
{
|
||||
if (Core::EventLoop::is_running())
|
||||
VERIFY(&Core::EventLoop::current() == m_creation_event_loop);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <AK/HashMap.h>
|
||||
#include <ImageDecoder/ImageDecoderClientEndpoint.h>
|
||||
#include <ImageDecoder/ImageDecoderServerEndpoint.h>
|
||||
#include <LibCore/EventLoop.h>
|
||||
#include <LibCore/Promise.h>
|
||||
#include <LibGfx/ColorSpace.h>
|
||||
#include <LibIPC/ConnectionToServer.h>
|
||||
@@ -51,6 +52,7 @@ public:
|
||||
Function<void(i64 session_id, String error_message)> on_animation_decode_failed;
|
||||
|
||||
private:
|
||||
void verify_event_loop() const;
|
||||
virtual void die() override;
|
||||
|
||||
virtual void did_decode_image(i64 image_id, bool is_animated, u32 loop_count, Gfx::BitmapSequence bitmap_sequence, Vector<u32> durations, Gfx::FloatPoint scale, Gfx::ColorSpace color_space, i64 session_id) override;
|
||||
@@ -59,6 +61,7 @@ private:
|
||||
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() };
|
||||
HashMap<i64, NonnullRefPtr<Core::Promise<DecodedImage>>> m_pending_decoded_images;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user