mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-25 20:42:55 +00:00
Most places used to call `context.error()` to report an error, which would set the context's state to `Error` and then return an `Error::from_string_literal()`. This is somewhat elegant, but it doesn't work: Some functions this code calls returns ErrorOr<>s that aren't created by `context.error()`, and for these we wouldn't enter the error state. Instead, manually check error-ness at the leaf entry functions of the class: 1. Add a set_error() helper for functions returning bool 2. In the two functions returning ErrorOr<>, awkwardly check the error manually. If this becomes a very common pattern, maybe we can add a `TRY_WITH_HANDLER(expr, error_lambda)` which would invoke a lambda on error. We could use that here to set the error code. No real behavior change (except we enter the error state more often when something goes wrong).
41 lines
1.1 KiB
C++
41 lines
1.1 KiB
C++
/*
|
|
* Copyright (c) 2023, Nico Weber <thakis@chromium.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibGfx/ImageFormats/ImageDecoder.h>
|
|
|
|
namespace Gfx {
|
|
|
|
struct WebPLoadingContext;
|
|
|
|
class WebPImageDecoderPlugin final : public ImageDecoderPlugin {
|
|
public:
|
|
static bool sniff(ReadonlyBytes);
|
|
static ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> create(ReadonlyBytes);
|
|
|
|
virtual ~WebPImageDecoderPlugin() override;
|
|
|
|
virtual IntSize size() override;
|
|
virtual void set_volatile() override;
|
|
[[nodiscard]] virtual bool set_nonvolatile(bool& was_purged) override;
|
|
virtual bool initialize() override;
|
|
virtual bool is_animated() override;
|
|
virtual size_t loop_count() override;
|
|
virtual size_t frame_count() override;
|
|
virtual size_t first_animated_frame_index() override;
|
|
virtual ErrorOr<ImageFrameDescriptor> frame(size_t index) override;
|
|
virtual ErrorOr<Optional<ReadonlyBytes>> icc_data() override;
|
|
|
|
private:
|
|
bool set_error(ErrorOr<void>&&);
|
|
|
|
WebPImageDecoderPlugin(ReadonlyBytes, OwnPtr<WebPLoadingContext>);
|
|
|
|
OwnPtr<WebPLoadingContext> m_context;
|
|
};
|
|
|
|
}
|