summaryrefslogtreecommitdiff
path: root/Libraries/LibWeb/Loader/ImageResource.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/ImageResource.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/ImageResource.cpp')
-rw-r--r--Libraries/LibWeb/Loader/ImageResource.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/Libraries/LibWeb/Loader/ImageResource.cpp b/Libraries/LibWeb/Loader/ImageResource.cpp
index efacec3aa1..35a02d0e79 100644
--- a/Libraries/LibWeb/Loader/ImageResource.cpp
+++ b/Libraries/LibWeb/Loader/ImageResource.cpp
@@ -27,6 +27,7 @@
#include <AK/Function.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/ImageDecoder.h>
+#include <LibImageDecoderClient/Client.h>
#include <LibWeb/Loader/ImageResource.h>
namespace Web {
@@ -40,6 +41,11 @@ ImageResource::~ImageResource()
{
}
+bool ImageResource::should_decode_in_process() const
+{
+ return mime_type() == "image/gif";
+}
+
Gfx::ImageDecoder& ImageResource::ensure_decoder()
{
if (!m_decoder)
@@ -47,6 +53,26 @@ Gfx::ImageDecoder& ImageResource::ensure_decoder()
return *m_decoder;
}
+const Gfx::Bitmap* ImageResource::bitmap(size_t frame_index) const
+{
+ if (!has_encoded_data())
+ return nullptr;
+
+ if (should_decode_in_process()) {
+ if (!m_decoder)
+ return nullptr;
+ if (m_decoder->is_animated())
+ return m_decoder->frame(frame_index).image;
+ return m_decoder->bitmap();
+ }
+ if (!m_decoded_image && !m_has_attempted_decode) {
+ auto image_decoder_client = ImageDecoderClient::Client::construct();
+ m_decoded_image = image_decoder_client->decode_image(encoded_data());
+ m_has_attempted_decode = true;
+ }
+ return m_decoded_image;
+}
+
void ImageResource::update_volatility()
{
if (!m_decoder)