summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-02-20 11:35:00 +0100
committerAndreas Kling <kling@serenityos.org>2021-02-20 11:37:55 +0100
commit3b9f110161bc78d8534a29e3f14030e1f5a15574 (patch)
treecd12c5cb2f964b987086062fed277d7b98cc1dea /Userland/Libraries/LibWeb
parent8fb9d1fd1dbe95f7ef2d8fa96eb0534afc51bee0 (diff)
downloadserenity-3b9f110161bc78d8534a29e3f14030e1f5a15574.zip
LibWeb+LibImageDecoderClient: Reuse ImageDecoder service process
The overhead from spawning a new ImageDecoder for every decoding job is way too large and causing other problems as well (#5421) Let's keep the same decoder open and reuse it as long as it's working.
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/Loader/ImageResource.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/Userland/Libraries/LibWeb/Loader/ImageResource.cpp b/Userland/Libraries/LibWeb/Loader/ImageResource.cpp
index ba94e8d039..001eb30877 100644
--- a/Userland/Libraries/LibWeb/Loader/ImageResource.cpp
+++ b/Userland/Libraries/LibWeb/Loader/ImageResource.cpp
@@ -48,6 +48,18 @@ int ImageResource::frame_duration(size_t frame_index) const
return m_decoded_frames[frame_index].duration;
}
+static ImageDecoderClient::Client& image_decoder_client()
+{
+ static RefPtr<ImageDecoderClient::Client> image_decoder_client;
+ if (!image_decoder_client) {
+ image_decoder_client = ImageDecoderClient::Client::construct();
+ image_decoder_client->on_death = [&] {
+ image_decoder_client = nullptr;
+ };
+ }
+ return *image_decoder_client;
+}
+
void ImageResource::decode_if_needed() const
{
if (!has_encoded_data())
@@ -59,8 +71,9 @@ void ImageResource::decode_if_needed() const
if (!m_decoded_frames.is_empty())
return;
- auto image_decoder_client = ImageDecoderClient::Client::construct();
- auto image = image_decoder_client->decode_image(encoded_data());
+ NonnullRefPtr decoder = image_decoder_client();
+ auto image = decoder->decode_image(encoded_data());
+
if (image.has_value()) {
m_loop_count = image.value().loop_count;
m_animated = image.value().is_animated;