summaryrefslogtreecommitdiff
path: root/Libraries/LibWeb/Loader/ImageLoader.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-06-22 21:41:10 +0200
committerAndreas Kling <kling@serenityos.org>2020-06-22 21:47:01 +0200
commit10255bc5c6664ffcb8b496c34a7c34b56d898138 (patch)
tree2aeed4e45c781c0bb14819839af2fa77e5b38b0a /Libraries/LibWeb/Loader/ImageLoader.cpp
parentb273b31c7de6ad2d41e6498e34792d8a34b19feb (diff)
downloadserenity-10255bc5c6664ffcb8b496c34a7c34b56d898138.zip
LibWeb+Browser: Decode non-animated images out-of-process :^)
We now use the ImageDecoder service in LibWeb for everything except GIF images (we'll have to deal with them later, ofc.) This has a little bit of overhead but we should be able to optimize it until it becomes negligible.
Diffstat (limited to 'Libraries/LibWeb/Loader/ImageLoader.cpp')
-rw-r--r--Libraries/LibWeb/Loader/ImageLoader.cpp54
1 files changed, 43 insertions, 11 deletions
diff --git a/Libraries/LibWeb/Loader/ImageLoader.cpp b/Libraries/LibWeb/Loader/ImageLoader.cpp
index c581242d4c..8e1218ae9b 100644
--- a/Libraries/LibWeb/Loader/ImageLoader.cpp
+++ b/Libraries/LibWeb/Loader/ImageLoader.cpp
@@ -67,18 +67,23 @@ void ImageLoader::resource_did_load()
return;
}
+#ifdef IMAGE_LOADER_DEBUG
if (!resource()->has_encoded_data()) {
dbg() << "ImageLoader: Resource did load, no encoded data. URL: " << resource()->url();
} else {
dbg() << "ImageLoader: Resource did load, has encoded data. URL: " << resource()->url();
}
- m_decoder = resource()->ensure_decoder();
+#endif
- if (m_decoder->is_animated() && m_decoder->frame_count() > 1) {
- const auto& first_frame = m_decoder->frame(0);
- m_timer->set_interval(first_frame.duration);
- m_timer->on_timeout = [this] { animate(); };
- m_timer->start();
+ if (resource()->should_decode_in_process()) {
+ m_decoder = resource()->ensure_decoder();
+
+ if (m_decoder->is_animated() && m_decoder->frame_count() > 1) {
+ const auto& first_frame = m_decoder->frame(0);
+ m_timer->set_interval(first_frame.duration);
+ m_timer->on_timeout = [this] { animate(); };
+ m_timer->start();
+ }
}
if (on_load)
@@ -120,16 +125,43 @@ void ImageLoader::resource_did_fail()
void ImageLoader::resource_did_replace_decoder()
{
- m_decoder = resource()->ensure_decoder();
+ if (resource()->should_decode_in_process()) {
+ m_decoder = resource()->ensure_decoder();
+ }
+}
+
+bool ImageLoader::has_image() const
+{
+ if (!resource())
+ return false;
+ if (resource()->should_decode_in_process())
+ return image_decoder();
+ return true;
+}
+
+unsigned ImageLoader::width() const
+{
+ if (!resource())
+ return 0;
+ if (resource()->should_decode_in_process())
+ return image_decoder() ? image_decoder()->width() : 0;
+ return bitmap() ? bitmap()->width() : 0;
+}
+
+unsigned ImageLoader::height() const
+{
+ if (!resource())
+ return 0;
+ if (resource()->should_decode_in_process())
+ return image_decoder() ? image_decoder()->height() : 0;
+ return bitmap() ? bitmap()->height() : 0;
}
const Gfx::Bitmap* ImageLoader::bitmap() const
{
- if (!m_decoder)
+ if (!resource())
return nullptr;
- if (m_decoder->is_animated())
- return m_decoder->frame(m_current_frame_index).image;
- return m_decoder->bitmap();
+ return resource()->bitmap(0);
}
const Gfx::ImageDecoder* ImageLoader::image_decoder() const