/* * Copyright (c) 2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include namespace Web::SVG { class SVGDecodedImageData final : public HTML::DecodedImageData { JS_CELL(SVGDecodedImageData, Cell); JS_DECLARE_ALLOCATOR(SVGDecodedImageData); public: static ErrorOr> create(JS::Realm&, JS::NonnullGCPtr, AK::URL const&, ByteBuffer encoded_svg); virtual ~SVGDecodedImageData() override; virtual RefPtr bitmap(size_t frame_index, Gfx::IntSize) const override; virtual Optional intrinsic_width() const override; virtual Optional intrinsic_height() const override; virtual Optional intrinsic_aspect_ratio() const override; // FIXME: Support SVG animations. :^) virtual int frame_duration(size_t) const override { return 0; } virtual size_t frame_count() const override { return 1; } virtual size_t loop_count() const override { return 0; } virtual bool is_animated() const override { return false; } DOM::Document const& svg_document() const { return *m_document; } virtual void visit_edges(Cell::Visitor& visitor) override; private: class SVGPageClient; SVGDecodedImageData(JS::NonnullGCPtr, JS::NonnullGCPtr, JS::NonnullGCPtr, JS::NonnullGCPtr); RefPtr render(Gfx::IntSize) const; mutable HashMap> m_cached_rendered_bitmaps; JS::NonnullGCPtr m_page; JS::NonnullGCPtr m_page_client; JS::NonnullGCPtr m_document; JS::NonnullGCPtr m_root_element; }; }