2023-05-20 16:11:36 +02:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2023, Andreas Kling <andreas@ladybird.org>
|
2023-05-20 16:11:36 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2025-11-23 13:07:35 +01:00
|
|
|
#include <LibGfx/Forward.h>
|
2023-05-20 16:11:36 +02:00
|
|
|
#include <LibWeb/HTML/DecodedImageData.h>
|
|
|
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
|
|
|
|
|
class AnimatedBitmapDecodedImageData final : public DecodedImageData {
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_CELL(AnimatedBitmapDecodedImageData, DecodedImageData);
|
|
|
|
|
GC_DECLARE_ALLOCATOR(AnimatedBitmapDecodedImageData);
|
2023-12-12 20:07:19 +01:00
|
|
|
|
2023-05-20 16:11:36 +02:00
|
|
|
public:
|
|
|
|
|
struct Frame {
|
2023-11-24 14:45:45 +01:00
|
|
|
RefPtr<Gfx::ImmutableBitmap> bitmap;
|
2023-05-20 16:11:36 +02:00
|
|
|
int duration { 0 };
|
|
|
|
|
};
|
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
static ErrorOr<GC::Ref<AnimatedBitmapDecodedImageData>> create(JS::Realm&, Vector<Frame>&&, size_t loop_count, bool animated);
|
2023-05-20 16:11:36 +02:00
|
|
|
virtual ~AnimatedBitmapDecodedImageData() override;
|
|
|
|
|
|
2023-11-24 14:45:45 +01:00
|
|
|
virtual RefPtr<Gfx::ImmutableBitmap> bitmap(size_t frame_index, Gfx::IntSize = {}) const override;
|
2023-05-20 16:11:36 +02:00
|
|
|
virtual int frame_duration(size_t frame_index) const override;
|
|
|
|
|
|
|
|
|
|
virtual size_t frame_count() const override { return m_frames.size(); }
|
|
|
|
|
virtual size_t loop_count() const override { return m_loop_count; }
|
|
|
|
|
virtual bool is_animated() const override { return m_animated; }
|
|
|
|
|
|
2023-05-20 16:27:31 +02:00
|
|
|
virtual Optional<CSSPixels> intrinsic_width() const override;
|
|
|
|
|
virtual Optional<CSSPixels> intrinsic_height() const override;
|
2023-09-03 17:33:58 -05:00
|
|
|
virtual Optional<CSSPixelFraction> intrinsic_aspect_ratio() const override;
|
2023-05-20 16:11:36 +02:00
|
|
|
|
2025-11-04 21:20:00 +01:00
|
|
|
virtual Optional<Gfx::IntRect> frame_rect(size_t frame_index) const override;
|
|
|
|
|
virtual void paint(DisplayListRecordingContext&, size_t frame_index, Gfx::IntRect dst_rect, Gfx::IntRect clip_rect, Gfx::ScalingMode scaling_mode) const override;
|
|
|
|
|
|
2023-05-20 16:11:36 +02:00
|
|
|
private:
|
|
|
|
|
AnimatedBitmapDecodedImageData(Vector<Frame>&&, size_t loop_count, bool animated);
|
|
|
|
|
|
|
|
|
|
Vector<Frame> m_frames;
|
|
|
|
|
size_t m_loop_count { 0 };
|
|
|
|
|
bool m_animated { false };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|