1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:17:35 +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

@ -44,14 +44,12 @@ LayoutImage::~LayoutImage()
int LayoutImage::preferred_width() const
{
auto* decoder = m_image_loader.image_decoder();
return node().attribute(HTML::AttributeNames::width).to_int().value_or(decoder ? decoder->width() : 0);
return node().attribute(HTML::AttributeNames::width).to_int().value_or(m_image_loader.width());
}
int LayoutImage::preferred_height() const
{
auto* decoder = m_image_loader.image_decoder();
return node().attribute(HTML::AttributeNames::height).to_int().value_or(decoder ? decoder->height() : 0);
return node().attribute(HTML::AttributeNames::height).to_int().value_or(m_image_loader.height());
}
void LayoutImage::layout(LayoutMode layout_mode)
@ -97,8 +95,8 @@ void LayoutImage::paint(PaintContext& context, PaintPhase phase)
if (alt.is_empty())
alt = image_element.src();
context.painter().draw_text(enclosing_int_rect(absolute_rect()), alt, Gfx::TextAlignment::Center, style().color_or_fallback(CSS::PropertyID::Color, document(), Color::Black), Gfx::TextElision::Right);
} else if (m_image_loader.bitmap()) {
context.painter().draw_scaled_bitmap(enclosing_int_rect(absolute_rect()), *m_image_loader.bitmap(), m_image_loader.bitmap()->rect());
} else if (auto* bitmap = m_image_loader.bitmap()) {
context.painter().draw_scaled_bitmap(enclosing_int_rect(absolute_rect()), *bitmap, bitmap->rect());
}
}
}
@ -106,7 +104,7 @@ void LayoutImage::paint(PaintContext& context, PaintPhase phase)
bool LayoutImage::renders_as_alt_text() const
{
if (is<HTMLImageElement>(node()))
return !m_image_loader.image_decoder();
return !m_image_loader.has_image();
return false;
}