From e017fe92e6be10a3793232f43973373baf443914 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 20 Nov 2021 10:46:27 +0100 Subject: LibWeb: Move ImageDecoder client connection singleton to its own file This will allow us to use it in more places around LibWeb. --- Userland/Libraries/LibWeb/CMakeLists.txt | 1 + Userland/Libraries/LibWeb/ImageDecoding.cpp | 23 ++++++++++++++++++++++ Userland/Libraries/LibWeb/ImageDecoding.h | 15 ++++++++++++++ Userland/Libraries/LibWeb/Loader/ImageResource.cpp | 14 +------------ 4 files changed, 40 insertions(+), 13 deletions(-) create mode 100644 Userland/Libraries/LibWeb/ImageDecoding.cpp create mode 100644 Userland/Libraries/LibWeb/ImageDecoding.h (limited to 'Userland/Libraries/LibWeb') diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 3462193dee..81dbfa84aa 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -195,6 +195,7 @@ set(SOURCES HTML/TagNames.cpp HTML/WebSocket.cpp HighResolutionTime/Performance.cpp + ImageDecoding.cpp InProcessWebView.cpp IntersectionObserver/IntersectionObserver.cpp Layout/BlockContainer.cpp diff --git a/Userland/Libraries/LibWeb/ImageDecoding.cpp b/Userland/Libraries/LibWeb/ImageDecoding.cpp new file mode 100644 index 0000000000..706c04c97a --- /dev/null +++ b/Userland/Libraries/LibWeb/ImageDecoding.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +namespace Web { + +ImageDecoderClient::Client& image_decoder_client() +{ + static RefPtr image_decoder_client; + if (!image_decoder_client) { + image_decoder_client = ImageDecoderClient::Client::construct(); + image_decoder_client->on_death = [&] { + image_decoder_client = nullptr; + }; + } + return *image_decoder_client; +} + +} diff --git a/Userland/Libraries/LibWeb/ImageDecoding.h b/Userland/Libraries/LibWeb/ImageDecoding.h new file mode 100644 index 0000000000..081b4e123c --- /dev/null +++ b/Userland/Libraries/LibWeb/ImageDecoding.h @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2020-2021, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web { + +ImageDecoderClient::Client& image_decoder_client(); + +} diff --git a/Userland/Libraries/LibWeb/Loader/ImageResource.cpp b/Userland/Libraries/LibWeb/Loader/ImageResource.cpp index 39f2ee5995..b425c98847 100644 --- a/Userland/Libraries/LibWeb/Loader/ImageResource.cpp +++ b/Userland/Libraries/LibWeb/Loader/ImageResource.cpp @@ -5,7 +5,7 @@ */ #include -#include +#include #include namespace Web { @@ -27,18 +27,6 @@ int ImageResource::frame_duration(size_t frame_index) const return m_decoded_frames[frame_index].duration; } -static ImageDecoderClient::Client& image_decoder_client() -{ - static RefPtr image_decoder_client; - if (!image_decoder_client) { - image_decoder_client = ImageDecoderClient::Client::construct(); - image_decoder_client->on_death = [&] { - image_decoder_client = nullptr; - }; - } - return *image_decoder_client; -} - void ImageResource::decode_if_needed() const { if (!has_encoded_data()) -- cgit v1.2.3