mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 22:38:12 +00:00
LibWeb: Abstract the image decoding via Web::ImageDecoding::Decoder
After this change, LibWeb now expects Web::ImageDecoding::Decoder to be pre-initialized with a concrete implementation before using the webpage. The previous implementation, based on the ImageDecoder service, has been provided directly through an adapter in LibWebClient, and is now used as the default value by WebContent.
This commit is contained in:
parent
962040b49c
commit
2198091bbc
11 changed files with 132 additions and 20 deletions
|
@ -1,23 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2022, Dex♪ <dexes.ttp@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/ImageDecoding.h>
|
||||
|
||||
namespace Web {
|
||||
namespace Web::ImageDecoding {
|
||||
|
||||
ImageDecoderClient::Client& image_decoder_client()
|
||||
static RefPtr<Decoder> s_decoder;
|
||||
|
||||
Decoder::Decoder() = default;
|
||||
|
||||
Decoder::~Decoder() = default;
|
||||
|
||||
void Decoder::initialize(RefPtr<Decoder>&& decoder)
|
||||
{
|
||||
static RefPtr<ImageDecoderClient::Client> image_decoder_client;
|
||||
if (!image_decoder_client) {
|
||||
image_decoder_client = ImageDecoderClient::Client::try_create().release_value_but_fixme_should_propagate_errors();
|
||||
image_decoder_client->on_death = [&] {
|
||||
image_decoder_client = nullptr;
|
||||
};
|
||||
s_decoder = move(decoder);
|
||||
}
|
||||
|
||||
Decoder& Decoder::the()
|
||||
{
|
||||
if (!s_decoder) [[unlikely]] {
|
||||
dbgln("Web::ImageDecoding::Decoder was not initialized!");
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
return *image_decoder_client;
|
||||
return *s_decoder;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue