LibWeb: cache in-process decoded images in ImageResource

Otherwise cloned Bitmaps returned by the decoder will be prematurely
freed
This commit is contained in:
Peter Nelson 2020-09-12 12:36:36 +01:00 committed by Andreas Kling
parent 16ebbde26f
commit 9494b03a02
Notes: sideshowbarker 2024-07-19 02:43:07 +09:00
2 changed files with 5 additions and 5 deletions

View File

@ -115,7 +115,7 @@ 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, 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());
}
}

View File

@ -62,10 +62,10 @@ const Gfx::Bitmap* ImageResource::bitmap(size_t frame_index) const
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) {
m_decoded_image = m_decoder->frame(frame_index).image;
else
m_decoded_image = m_decoder->bitmap();
} else 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;