LibWeb: Remove Gfx::ImageDecoder from ImageLoader

We still use a Gfx::ImageDecoder for GIF images, but there's no need
for the ImageLoader object to have its own pointer to it. Just grab
the ImageDecoder from the ImageResource when needed.
This commit is contained in:
Andreas Kling 2020-06-23 13:48:32 +02:00
parent 9ef5d46277
commit fbd760379a
Notes: sideshowbarker 2024-07-19 05:25:58 +09:00
4 changed files with 12 additions and 32 deletions

View file

@ -76,10 +76,10 @@ void ImageLoader::resource_did_load()
#endif
if (resource()->should_decode_in_process()) {
m_decoder = resource()->ensure_decoder();
auto& decoder = resource()->ensure_decoder();
if (m_decoder->is_animated() && m_decoder->frame_count() > 1) {
const auto& first_frame = m_decoder->frame(0);
if (decoder.is_animated() && decoder.frame_count() > 1) {
const auto& first_frame = decoder.frame(0);
m_timer->set_interval(first_frame.duration);
m_timer->on_timeout = [this] { animate(); };
m_timer->start();
@ -95,19 +95,18 @@ void ImageLoader::animate()
if (!m_visible_in_viewport)
return;
auto* decoder = image_decoder();
ASSERT(decoder);
auto& decoder = resource()->ensure_decoder();
m_current_frame_index = (m_current_frame_index + 1) % decoder->frame_count();
const auto& current_frame = decoder->frame(m_current_frame_index);
m_current_frame_index = (m_current_frame_index + 1) % decoder.frame_count();
const auto& current_frame = decoder.frame(m_current_frame_index);
if (current_frame.duration != m_timer->interval()) {
m_timer->restart(current_frame.duration);
}
if (m_current_frame_index == decoder->frame_count() - 1) {
if (m_current_frame_index == decoder.frame_count() - 1) {
++m_loops_completed;
if (m_loops_completed > 0 && m_loops_completed == decoder->loop_count()) {
if (m_loops_completed > 0 && m_loops_completed == decoder.loop_count()) {
m_timer->stop();
}
}
@ -123,19 +122,12 @@ void ImageLoader::resource_did_fail()
on_fail();
}
void ImageLoader::resource_did_replace_decoder()
{
if (resource()->should_decode_in_process()) {
m_decoder = resource()->ensure_decoder();
}
}
bool ImageLoader::has_image() const
{
if (!resource())
return false;
if (resource()->should_decode_in_process())
return image_decoder();
return const_cast<ImageResource*>(resource())->ensure_decoder().bitmap();
return true;
}
@ -144,7 +136,7 @@ unsigned ImageLoader::width() const
if (!resource())
return 0;
if (resource()->should_decode_in_process())
return image_decoder() ? image_decoder()->width() : 0;
return const_cast<ImageResource*>(resource())->ensure_decoder().width();
return bitmap() ? bitmap()->width() : 0;
}
@ -153,7 +145,7 @@ unsigned ImageLoader::height() const
if (!resource())
return 0;
if (resource()->should_decode_in_process())
return image_decoder() ? image_decoder()->height() : 0;
return const_cast<ImageResource*>(resource())->ensure_decoder().height();
return bitmap() ? bitmap()->height() : 0;
}
@ -161,12 +153,7 @@ const Gfx::Bitmap* ImageLoader::bitmap() const
{
if (!resource())
return nullptr;
return resource()->bitmap();
}
const Gfx::ImageDecoder* ImageLoader::image_decoder() const
{
return m_decoder;
return resource()->bitmap(m_current_frame_index);
}
}