ladybird/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.h
Shannon Booth e800605ad3 AK+LibURL: Move AK::URL into a new URL library
This URL library ends up being a relatively fundamental base library of
the system, as LibCore depends on LibURL.

This change has two main benefits:
 * Moving AK back more towards being an agnostic library that can
   be used between the kernel and userspace. URL has never really fit
   that description - and is not used in the kernel.
 * URL _should_ depend on LibUnicode, as it needs punnycode support.
   However, it's not really possible to do this inside of AK as it can't
   depend on any external library. This change brings us a little closer
   to being able to do that, but unfortunately we aren't there quite
   yet, as the code generators depend on LibCore.
2024-03-18 14:06:28 -04:00

53 lines
1.8 KiB
C++

/*
* Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/DecodedImageData.h>
namespace Web::SVG {
class SVGDecodedImageData final : public HTML::DecodedImageData {
JS_CELL(SVGDecodedImageData, Cell);
JS_DECLARE_ALLOCATOR(SVGDecodedImageData);
public:
static ErrorOr<JS::NonnullGCPtr<SVGDecodedImageData>> create(JS::Realm&, JS::NonnullGCPtr<Page>, URL::URL const&, ByteBuffer encoded_svg);
virtual ~SVGDecodedImageData() override;
virtual RefPtr<Gfx::ImmutableBitmap> bitmap(size_t frame_index, Gfx::IntSize) const override;
virtual Optional<CSSPixels> intrinsic_width() const override;
virtual Optional<CSSPixels> intrinsic_height() const override;
virtual Optional<CSSPixelFraction> 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<Page>, JS::NonnullGCPtr<SVGPageClient>, JS::NonnullGCPtr<DOM::Document>, JS::NonnullGCPtr<SVG::SVGSVGElement>);
RefPtr<Gfx::Bitmap> render(Gfx::IntSize) const;
mutable HashMap<Gfx::IntSize, NonnullRefPtr<Gfx::ImmutableBitmap>> m_cached_rendered_bitmaps;
JS::NonnullGCPtr<Page> m_page;
JS::NonnullGCPtr<SVGPageClient> m_page_client;
JS::NonnullGCPtr<DOM::Document> m_document;
JS::NonnullGCPtr<SVG::SVGSVGElement> m_root_element;
};
}