1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 19:35:09 +00:00

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.
This commit is contained in:
Andreas Kling 2020-06-22 21:41:10 +02:00
parent b273b31c7d
commit 10255bc5c6
10 changed files with 96 additions and 25 deletions

View file

@ -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)