mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:57:43 +00:00
LibWeb: cache in-process decoded images in ImageResource
Otherwise cloned Bitmaps returned by the decoder will be prematurely freed
This commit is contained in:
parent
16ebbde26f
commit
9494b03a02
2 changed files with 5 additions and 5 deletions
|
@ -115,7 +115,7 @@ void LayoutImage::paint(PaintContext& context, PaintPhase phase)
|
||||||
if (alt.is_empty())
|
if (alt.is_empty())
|
||||||
alt = image_element.src();
|
alt = image_element.src();
|
||||||
context.painter().draw_text(enclosing_int_rect(absolute_rect()), alt, Gfx::TextAlignment::Center, specified_style().color_or_fallback(CSS::PropertyID::Color, document(), Color::Black), Gfx::TextElision::Right);
|
context.painter().draw_text(enclosing_int_rect(absolute_rect()), alt, Gfx::TextAlignment::Center, specified_style().color_or_fallback(CSS::PropertyID::Color, document(), Color::Black), Gfx::TextElision::Right);
|
||||||
} else if (auto* bitmap = m_image_loader.bitmap()) {
|
} else if (auto bitmap = m_image_loader.bitmap()) {
|
||||||
context.painter().draw_scaled_bitmap(enclosing_int_rect(absolute_rect()), *bitmap, bitmap->rect());
|
context.painter().draw_scaled_bitmap(enclosing_int_rect(absolute_rect()), *bitmap, bitmap->rect());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,10 +62,10 @@ const Gfx::Bitmap* ImageResource::bitmap(size_t frame_index) const
|
||||||
if (!m_decoder)
|
if (!m_decoder)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (m_decoder->is_animated())
|
if (m_decoder->is_animated())
|
||||||
return m_decoder->frame(frame_index).image;
|
m_decoded_image = m_decoder->frame(frame_index).image;
|
||||||
return m_decoder->bitmap();
|
else
|
||||||
}
|
m_decoded_image = m_decoder->bitmap();
|
||||||
if (!m_decoded_image && !m_has_attempted_decode) {
|
} else if (!m_decoded_image && !m_has_attempted_decode) {
|
||||||
auto image_decoder_client = ImageDecoderClient::Client::construct();
|
auto image_decoder_client = ImageDecoderClient::Client::construct();
|
||||||
m_decoded_image = image_decoder_client->decode_image(encoded_data());
|
m_decoded_image = image_decoder_client->decode_image(encoded_data());
|
||||||
m_has_attempted_decode = true;
|
m_has_attempted_decode = true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue