SVGDecodedImageData.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/DOM/Document.h>
  8. #include <LibWeb/HTML/DecodedImageData.h>
  9. namespace Web::SVG {
  10. class SVGDecodedImageData final : public HTML::DecodedImageData {
  11. JS_CELL(SVGDecodedImageData, Cell);
  12. JS_DECLARE_ALLOCATOR(SVGDecodedImageData);
  13. public:
  14. static ErrorOr<JS::NonnullGCPtr<SVGDecodedImageData>> create(JS::Realm&, JS::NonnullGCPtr<Page>, URL const&, ByteBuffer encoded_svg);
  15. virtual ~SVGDecodedImageData() override;
  16. virtual RefPtr<Gfx::ImmutableBitmap> bitmap(size_t frame_index, Gfx::IntSize) const override;
  17. virtual Optional<CSSPixels> intrinsic_width() const override;
  18. virtual Optional<CSSPixels> intrinsic_height() const override;
  19. virtual Optional<CSSPixelFraction> intrinsic_aspect_ratio() const override;
  20. // FIXME: Support SVG animations. :^)
  21. virtual int frame_duration(size_t) const override { return 0; }
  22. virtual size_t frame_count() const override { return 1; }
  23. virtual size_t loop_count() const override { return 0; }
  24. virtual bool is_animated() const override { return false; }
  25. DOM::Document const& svg_document() const { return *m_document; }
  26. virtual void visit_edges(Cell::Visitor& visitor) override;
  27. private:
  28. class SVGPageClient;
  29. SVGDecodedImageData(JS::NonnullGCPtr<Page>, JS::NonnullGCPtr<SVGPageClient>, JS::NonnullGCPtr<DOM::Document>, JS::NonnullGCPtr<SVG::SVGSVGElement>);
  30. RefPtr<Gfx::Bitmap> render(Gfx::IntSize) const;
  31. mutable HashMap<Gfx::IntSize, NonnullRefPtr<Gfx::ImmutableBitmap>> m_cached_rendered_bitmaps;
  32. JS::NonnullGCPtr<Page> m_page;
  33. JS::NonnullGCPtr<SVGPageClient> m_page_client;
  34. JS::NonnullGCPtr<DOM::Document> m_document;
  35. JS::NonnullGCPtr<SVG::SVGSVGElement> m_root_element;
  36. };
  37. }