diff options
author | Andreas Kling <kling@serenityos.org> | 2020-06-23 13:48:32 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-06-23 14:28:45 +0200 |
commit | fbd760379ad11b44f67d7e5470c1fa7bb0600f2f (patch) | |
tree | 37912fb21c4486c31325f6c02dfe66a1ba88304e | |
parent | 9ef5d46277dfeacd12683ad8ea0de0be30a16350 (diff) | |
download | serenity-fbd760379ad11b44f67d7e5470c1fa7bb0600f2f.zip |
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.
-rw-r--r-- | Libraries/LibWeb/Loader/ImageLoader.cpp | 37 | ||||
-rw-r--r-- | Libraries/LibWeb/Loader/ImageLoader.h | 3 | ||||
-rw-r--r-- | Libraries/LibWeb/Loader/ImageResource.cpp | 3 | ||||
-rw-r--r-- | Libraries/LibWeb/Loader/ImageResource.h | 1 |
4 files changed, 12 insertions, 32 deletions
diff --git a/Libraries/LibWeb/Loader/ImageLoader.cpp b/Libraries/LibWeb/Loader/ImageLoader.cpp index 040e711017..3732326bf5 100644 --- a/Libraries/LibWeb/Loader/ImageLoader.cpp +++ b/Libraries/LibWeb/Loader/ImageLoader.cpp @@ -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); } } diff --git a/Libraries/LibWeb/Loader/ImageLoader.h b/Libraries/LibWeb/Loader/ImageLoader.h index 2bebcaa6fa..0ac1bd1f41 100644 --- a/Libraries/LibWeb/Loader/ImageLoader.h +++ b/Libraries/LibWeb/Loader/ImageLoader.h @@ -39,7 +39,6 @@ public: void load(const URL&); const Gfx::Bitmap* bitmap() const; - const Gfx::ImageDecoder* image_decoder() const; bool has_image() const; @@ -56,12 +55,10 @@ private: // ^ImageResourceClient virtual void resource_did_load() override; virtual void resource_did_fail() override; - virtual void resource_did_replace_decoder() override; virtual bool is_visible_in_viewport() const override { return m_visible_in_viewport; } void animate(); - RefPtr<Gfx::ImageDecoder> m_decoder; mutable bool m_visible_in_viewport { false }; size_t m_current_frame_index { 0 }; diff --git a/Libraries/LibWeb/Loader/ImageResource.cpp b/Libraries/LibWeb/Loader/ImageResource.cpp index 35a02d0e79..e3e714cfce 100644 --- a/Libraries/LibWeb/Loader/ImageResource.cpp +++ b/Libraries/LibWeb/Loader/ImageResource.cpp @@ -94,9 +94,6 @@ void ImageResource::update_volatility() return; m_decoder = nullptr; - for_each_client([&](auto& client) { - static_cast<ImageResourceClient&>(client).resource_did_replace_decoder(); - }); } ImageResourceClient::~ImageResourceClient() diff --git a/Libraries/LibWeb/Loader/ImageResource.h b/Libraries/LibWeb/Loader/ImageResource.h index 62c1fc8de6..0e66785a70 100644 --- a/Libraries/LibWeb/Loader/ImageResource.h +++ b/Libraries/LibWeb/Loader/ImageResource.h @@ -54,7 +54,6 @@ public: virtual ~ImageResourceClient(); virtual bool is_visible_in_viewport() const { return false; } - virtual void resource_did_replace_decoder() {} protected: ImageResource* resource() { return static_cast<ImageResource*>(ResourceClient::resource()); } |